Finish account settings option.
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.Controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
public class ActivationController
|
||||
implements Controller, InitializingBean
|
||||
{
|
||||
|
||||
//~ Instance fields ......................................................................................
|
||||
private UserService userService;
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception
|
||||
{
|
||||
ModelAndView modelAndView;
|
||||
try
|
||||
{
|
||||
final String code = request.getParameter("code");
|
||||
userService.activateAccount(Long.parseLong(code));
|
||||
modelAndView = new ModelAndView("activationAccountConfirmation");
|
||||
}
|
||||
catch (Throwable exc)
|
||||
{
|
||||
// TODO Fix it !
|
||||
exc.printStackTrace();
|
||||
// Any type of error
|
||||
modelAndView = new ModelAndView("activationAccountConfirmationFail");
|
||||
}
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet()
|
||||
throws Exception {
|
||||
if (userService == null) {
|
||||
throw new RuntimeException("userService was not set!");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.SimpleFormController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
public class BaseSimpleFormController extends SimpleFormController
|
||||
{
|
||||
|
||||
private MindmapService mindmapService;
|
||||
private UserService userService;
|
||||
private String errorView;
|
||||
|
||||
public UserService getUserService() {
|
||||
return userService;
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public MindmapService getMindmapService() {
|
||||
return mindmapService;
|
||||
}
|
||||
|
||||
public String getErrorView() {
|
||||
return errorView;
|
||||
}
|
||||
|
||||
|
||||
@Override protected org.springframework.web.servlet.ModelAndView showForm(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, org.springframework.validation.BindException bindException) throws java.lang.Exception
|
||||
{
|
||||
final ModelAndView view = super.showForm(httpServletRequest, httpServletResponse,bindException);
|
||||
final String viewName = getErrorView();
|
||||
if(viewName !=null && bindException.getAllErrors().size()>0)
|
||||
{
|
||||
view.setViewName(viewName);
|
||||
view.addObject("errorView",true);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.view.ChangePasswordBean;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ChangePasswordController
|
||||
extends BaseSimpleFormController {
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
|
||||
BindException errors)
|
||||
throws ServletException {
|
||||
final ChangePasswordBean bean = (ChangePasswordBean) command;
|
||||
// Reload user only in case of being necessary...
|
||||
final User model = Utils.getUser();
|
||||
|
||||
final UserService userService = this.getUserService();
|
||||
final User user = userService.reloadUser(model);
|
||||
|
||||
user.setPassword(bean.getPassword());
|
||||
userService.changePassword(user);
|
||||
|
||||
return new ModelAndView(getSuccessView());
|
||||
}
|
||||
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.view.UserBean;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class EditProfileController extends BaseSimpleFormController {
|
||||
|
||||
|
||||
protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {
|
||||
final User model = Utils.getUser();
|
||||
return new UserBean(model);
|
||||
}
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
|
||||
BindException errors)
|
||||
throws ServletException {
|
||||
final UserBean bean = (UserBean) command;
|
||||
final UserService userService = this.getUserService();
|
||||
|
||||
// Reload user only in case of beeing necessary...
|
||||
final User model = Utils.getUser();
|
||||
final User user = userService.reloadUser(model);
|
||||
|
||||
user.setFirstname(bean.getFirstname());
|
||||
user.setLastname(bean.getLastname());
|
||||
// trim() the email email in order to remove spaces
|
||||
user.setEmail(bean.getEmail().trim());
|
||||
user.setAllowSendEmail(bean.isAllowSendEmail());
|
||||
|
||||
// Sync Acegi user and DB user
|
||||
model.setAllowSendEmail(bean.isAllowSendEmail());
|
||||
userService.updateUser(user);
|
||||
|
||||
return new ModelAndView(getSuccessView());
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class SettingsController {
|
||||
|
||||
public ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException noSuchRequestHandlingMethodException, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
|
||||
throws Exception {
|
||||
return new ModelAndView("setting");
|
||||
}
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.importer.ImporterException;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.view.TagBean;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class TagsController
|
||||
extends BaseSimpleFormController {
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {
|
||||
|
||||
final MindMap mindmap = null;
|
||||
final User user = Utils.getUser();
|
||||
final User dbUser = getUserService().getUserBy(user.getId());
|
||||
|
||||
final TagBean tagBean = new TagBean();
|
||||
tagBean.setUserTags(dbUser.getTags());
|
||||
tagBean.setMindmapId(mindmap.getId());
|
||||
tagBean.setMindmapTags(mindmap.getTags());
|
||||
tagBean.setMindmapTitle(mindmap.getTitle());
|
||||
return tagBean;
|
||||
}
|
||||
|
||||
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
|
||||
throws ServletException, WiseMappingException, ImporterException
|
||||
{
|
||||
final TagBean bean = (TagBean) command;
|
||||
final MindMap mindmap = getMindmapService().findMindmapById(bean.getMindmapId());
|
||||
getMindmapService().addTags(mindmap, bean.getMindmapTags());
|
||||
return new ModelAndView(getSuccessView());
|
||||
}
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.view.UserBean;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import net.tanesha.recaptcha.ReCaptcha;
|
||||
import net.tanesha.recaptcha.ReCaptchaResponse;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class UserRegistrationController
|
||||
extends BaseSimpleFormController {
|
||||
|
||||
//~ Instance fields ......................................................................................
|
||||
|
||||
private boolean emailConfirmEnabled;
|
||||
private UserService userService;
|
||||
private ReCaptcha captchaService;
|
||||
private boolean captchaEnabled;
|
||||
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
|
||||
public boolean isEmailConfirmEnabled() {
|
||||
return emailConfirmEnabled;
|
||||
}
|
||||
|
||||
public void setEmailConfirmEnabled(boolean emailConfirmEnabled) {
|
||||
this.emailConfirmEnabled = emailConfirmEnabled;
|
||||
}
|
||||
|
||||
public ModelAndView onSubmit(@Nullable Object command) throws WiseMappingException {
|
||||
final UserBean userBean = ((UserBean) command);
|
||||
|
||||
if (userBean != null) {
|
||||
final User user = new User();
|
||||
// trim() the email email in order to remove spaces
|
||||
user.setEmail(userBean.getEmail().trim());
|
||||
user.setUsername(userBean.getUsername());
|
||||
user.setFirstname(userBean.getFirstname());
|
||||
user.setLastname(userBean.getLastname());
|
||||
user.setPassword(userBean.getPassword());
|
||||
userService.createUser(user, emailConfirmEnabled);
|
||||
}
|
||||
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("confirmByEmail", emailConfirmEnabled);
|
||||
return new ModelAndView(getSuccessView(), model);
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public void setCaptchaService(@NotNull final ReCaptcha captchaService) {
|
||||
this.captchaService = captchaService;
|
||||
}
|
||||
|
||||
public ReCaptcha getCaptchaService() {
|
||||
return captchaService;
|
||||
}
|
||||
|
||||
public boolean isCaptchaEnabled() {
|
||||
return captchaEnabled;
|
||||
}
|
||||
|
||||
public void setCaptchaEnabled(boolean captchaEnabled) {
|
||||
this.captchaEnabled = captchaEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception {
|
||||
|
||||
super.onBindAndValidate(request, command, errors);
|
||||
// If captcha is enabled, generate it ...
|
||||
if (isCaptchaEnabled()) {
|
||||
|
||||
final String challenge = request.getParameter("recaptcha_challenge_field");
|
||||
final String uresponse = request.getParameter("recaptcha_response_field");
|
||||
|
||||
final String remoteAddr = request.getRemoteAddr();
|
||||
final ReCaptchaResponse reCaptchaResponse = captchaService.checkAnswer(remoteAddr, challenge, uresponse);
|
||||
if (!reCaptchaResponse.isValid()) {
|
||||
errors.rejectValue("captcha", Messages.CAPTCHA_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException bindException) throws Exception {
|
||||
final ModelAndView modelAndView = super.showForm(request, response, bindException);
|
||||
|
||||
// If captcha is enabled, generate it ...
|
||||
if (isCaptchaEnabled()) {
|
||||
final Properties prop = new Properties();
|
||||
prop.put("theme", "white");
|
||||
final String captchaHtml = captchaService.createRecaptchaHtml(null, prop);
|
||||
request.setAttribute("captchaHtml", captchaHtml);
|
||||
request.setAttribute("captchaEnabled", true);
|
||||
}
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
}
|
@@ -34,8 +34,6 @@ public interface UserManager {
|
||||
|
||||
User getUserByUsername(String username);
|
||||
|
||||
boolean authenticate(String email, String password);
|
||||
|
||||
void createUser(User user);
|
||||
|
||||
void auditLogin(UserLogin userLogin);
|
||||
|
@@ -86,14 +86,6 @@ public class UserManagerImpl
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authenticate(final String email, final String password) {
|
||||
final boolean result;
|
||||
final User user = getUserBy(email);
|
||||
result = user != null && user.getPassword().equals(password);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUser(User user) {
|
||||
assert user != null : "Trying to store a null user";
|
||||
@@ -134,7 +126,7 @@ public class UserManagerImpl
|
||||
getHibernateTemplate().save(userLogin);
|
||||
}
|
||||
|
||||
public void updateUser(User user) {
|
||||
public void updateUser(@NotNull User user) {
|
||||
assert user != null : "user is null";
|
||||
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
|
||||
getHibernateTemplate().update(user);
|
||||
|
@@ -49,7 +49,7 @@ final public class NotificationService {
|
||||
final String collabEmail = collaboration.getCollaborator().getEmail();
|
||||
|
||||
// Build the subject ...
|
||||
final String subject = user.getFullName() + " has shared a mindmap with you";
|
||||
final String subject = "[WiseMapping] " + user.getFullName() + " has shared a mindmap with you";
|
||||
|
||||
// Fill template properties ...
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
@@ -70,15 +70,44 @@ final public class NotificationService {
|
||||
}
|
||||
|
||||
public void resetPassword(@NotNull User user, @NotNull String temporalPassword) {
|
||||
final String mailSubject = "[WiseMapping] Your new password";
|
||||
final String messageTitle = "Your new password has been generated";
|
||||
final String messageBody =
|
||||
"<p>Someone, most likely you, requested a new password for your WiseMapping account. </p>\n" +
|
||||
"<p><strong>Here is your new password: : " + temporalPassword + "</strong></p>\n" +
|
||||
"<p>You can login clicking <a href=\"" + this.baseUrl + "/c/login\">here</a>. We strongly encourage you to change the password as soon as possible.</p>";
|
||||
|
||||
sendTemplateMail(user, mailSubject, messageTitle, messageBody);
|
||||
}
|
||||
|
||||
public void passwordChanged(@NotNull User user) {
|
||||
final String mailSubject = "[WiseMapping] Your password has been changed";
|
||||
final String messageTitle = "Your password has been changed successfully";
|
||||
final String messageBody =
|
||||
"<p>This is only an notification that your password has been changed. No further action is required.</p>";
|
||||
|
||||
sendTemplateMail(user, mailSubject, messageTitle, messageBody);
|
||||
}
|
||||
|
||||
public void newAccountCreated(@NotNull User user) {
|
||||
final String mailSubject = "Welcome to WiseMapping !";
|
||||
final String messageTitle = "Your account has been created successfully";
|
||||
final String messageBody =
|
||||
"<p> Thank you for your interest in WiseMapping. If have any feedback or idea, send us an email to <a href=\"mailto:feedback@wisemapping.com\">feedback@wisemapping.com</a> .We'd love to hear from you.</p>";
|
||||
sendTemplateMail(user, mailSubject, messageTitle, messageBody);
|
||||
}
|
||||
|
||||
private void sendTemplateMail(@NotNull User user, @NotNull String mailSubject, @NotNull String messageTitle, @NotNull String messageBody) {
|
||||
|
||||
try {
|
||||
final Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("user", user);
|
||||
model.put("temporalPassword", temporalPassword);
|
||||
model.put("supportEmail", mailer.getSupportEmail());
|
||||
model.put("password", temporalPassword);
|
||||
model.put("firstName", user.getFirstname());
|
||||
model.put("messageTitle", messageTitle);
|
||||
model.put("messageBody", messageBody);
|
||||
model.put("baseUrl", this.baseUrl);
|
||||
model.put("supportEmail", mailer.getSupportEmail());
|
||||
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "Reset Your WiseMapping Password", model, "passwordRecovery.vm");
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), mailSubject, model, "baseLayout.vm");
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
}
|
||||
@@ -100,7 +129,7 @@ final public class NotificationService {
|
||||
public void activateAccount(@NotNull User user) {
|
||||
final Map<String, User> model = new HashMap<String, User>();
|
||||
model.put("user", user);
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "WiseMapping : Active account", model, "activationAccountMail.vm");
|
||||
mailer.sendEmail(mailer.getServerSenderEmail(), user.getEmail(), "[WiseMapping] Active account", model, "activationAccountMail.vm");
|
||||
}
|
||||
|
||||
public void sendRegistrationEmail(@NotNull User user) {
|
||||
|
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.mail;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
|
||||
public class SmtpAuthenticator
|
||||
extends Authenticator
|
||||
{
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public SmtpAuthenticator(String username, String password)
|
||||
{
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
}
|
@@ -58,6 +58,7 @@ public class MindmapController {
|
||||
public String showDetails(@PathVariable int id, @NotNull Model model) {
|
||||
final MindMapBean mindmap = findMindmapBean(id);
|
||||
model.addAttribute("mindmap", mindmap);
|
||||
model.addAttribute("baseUrl", siteBaseUrl);
|
||||
return "mindmapDetail";
|
||||
}
|
||||
|
||||
|
@@ -19,9 +19,10 @@
|
||||
package com.wisemapping.ncontroller;
|
||||
|
||||
|
||||
import com.wisemapping.controller.Messages;
|
||||
import com.wisemapping.validator.Messages;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.InvalidUserEmailException;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.validator.UserValidator;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -119,6 +121,12 @@ public class UsersController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "account/settings", method = RequestMethod.GET)
|
||||
public String showUserSettingsPage(@NotNull Model model) {
|
||||
model.addAttribute("user", Utils.getUser());
|
||||
return "accountSettings";
|
||||
}
|
||||
|
||||
private BindingResult validateRegistrationForm(@NotNull UserBean userBean, @NotNull HttpServletRequest request, @NotNull BindingResult bindingResult) {
|
||||
final UserValidator userValidator = new UserValidator();
|
||||
userValidator.setUserService(userService);
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.rest;
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Controller
|
||||
public class AccountController extends BaseController {
|
||||
@Qualifier("userService")
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "account/password", consumes = {"text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void changePassword(@RequestBody String password) {
|
||||
if (password == null) {
|
||||
throw new IllegalArgumentException("Password can not be null");
|
||||
}
|
||||
|
||||
final User user = Utils.getUser();
|
||||
user.setPassword(password);
|
||||
userService.changePassword(user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "account/firstname", consumes = {"text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void changeFirstname(@RequestBody String firstname) {
|
||||
if (firstname == null) {
|
||||
throw new IllegalArgumentException("Firstname can not be null");
|
||||
}
|
||||
|
||||
final User user = Utils.getUser();
|
||||
user.setFirstname(firstname);
|
||||
userService.updateUser(user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "account/lastname", consumes = {"text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void changeLastName(@RequestBody String lastname) {
|
||||
if (lastname == null) {
|
||||
throw new IllegalArgumentException("lastname can not be null");
|
||||
|
||||
}
|
||||
final User user = Utils.getUser();
|
||||
user.setLastname(lastname);
|
||||
userService.updateUser(user);
|
||||
}
|
||||
}
|
@@ -23,6 +23,7 @@ import com.wisemapping.model.User;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -33,6 +34,7 @@ import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
public class AdminController extends BaseController {
|
||||
@Qualifier("userService")
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
@@ -62,7 +62,7 @@ public class UserServiceImpl
|
||||
// Generate a random password ...
|
||||
final String password = randomstring(8, 10);
|
||||
user.setPassword(password);
|
||||
changePassword(user);
|
||||
updateUser(user);
|
||||
|
||||
// Send an email with the new temporal password ...
|
||||
notificationService.resetPassword(user, password);
|
||||
@@ -119,11 +119,16 @@ public class UserServiceImpl
|
||||
// Send registration email.
|
||||
if (emailConfirmEnabled) {
|
||||
notificationService.sendRegistrationEmail(user);
|
||||
} else {
|
||||
// Send a welcome email ..
|
||||
notificationService.newAccountCreated(user);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public void changePassword(@NotNull User user) {
|
||||
notificationService.passwordChanged(user);
|
||||
userManager.updateUser(user);
|
||||
}
|
||||
|
||||
|
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.validator;
|
||||
|
||||
import org.springframework.validation.Validator;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import com.wisemapping.view.ChangePasswordBean;
|
||||
import com.wisemapping.model.Constants;
|
||||
|
||||
public class ChangePasswordValidator
|
||||
implements Validator {
|
||||
|
||||
public boolean supports(final Class clazz) {
|
||||
return clazz.equals(ChangePasswordBean.class);
|
||||
}
|
||||
|
||||
public void validate(Object obj, Errors errors) {
|
||||
ChangePasswordBean bean = (ChangePasswordBean) obj;
|
||||
|
||||
if (bean == null) {
|
||||
errors.rejectValue("changePassword", "error.not-specified", null, "Value required.");
|
||||
} else {
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required", "Field is required.");
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "retryPassword", "required", "Field is required.");
|
||||
ValidatorUtils.rejectIfExceeded(errors,
|
||||
"password",
|
||||
"The password must have less than "+ Constants.MAX_USER_PASSWORD_LENGTH + " characters.",
|
||||
bean.getPassword(),
|
||||
Constants.MAX_USER_PASSWORD_LENGTH);
|
||||
ValidatorUtils.rejectIfExceeded(errors,
|
||||
"retryPassword",
|
||||
"The retryPassword must have less than "+ Constants.MAX_USER_PASSWORD_LENGTH + " characters.",
|
||||
bean.getRetryPassword(),
|
||||
Constants.MAX_USER_PASSWORD_LENGTH);
|
||||
final String password = bean.getPassword();
|
||||
if (password != null && !password.equals(bean.getRetryPassword())) {
|
||||
errors.rejectValue("password", "Password mismatch", "Your password entries did not match");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.validator;
|
||||
|
||||
import com.wisemapping.view.UserBean;
|
||||
import com.wisemapping.controller.Messages;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.Constants;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.ValidationUtils;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
public class EditProfileValidator implements Validator {
|
||||
|
||||
private UserService userService;
|
||||
|
||||
public boolean supports(final Class clazz) {
|
||||
return clazz.equals(UserBean.class);
|
||||
}
|
||||
|
||||
public void validate(Object obj, Errors errors) {
|
||||
UserBean user = (UserBean) obj;
|
||||
if (user == null) {
|
||||
errors.rejectValue("user", "error.not-specified", null, "Value required.");
|
||||
} else {
|
||||
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", "required", "Field is required.");
|
||||
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", "required", "Field is required.");
|
||||
ValidatorUtils.rejectIfExceeded(errors,
|
||||
"firstname",
|
||||
"The firstname must have less than "+ Constants.MAX_USER_FIRSTNAME_LENGTH + " characters.",
|
||||
user.getFirstname(),
|
||||
Constants.MAX_USER_FIRSTNAME_LENGTH);
|
||||
ValidatorUtils.rejectIfExceeded(errors,
|
||||
"lastname",
|
||||
"The lastname must have less than "+ Constants.MAX_USER_LASTNAME_LENGTH + " characters.",
|
||||
user.getLastname(),
|
||||
Constants.MAX_USER_LASTNAME_LENGTH);
|
||||
final String email = user.getEmail();
|
||||
boolean isValid = Utils.isValidateEmailAddress(email);
|
||||
if (isValid) {
|
||||
final User oldUser = userService.getUserBy(email);
|
||||
if (oldUser != null && user.getId() != oldUser.getId()) {
|
||||
errors.rejectValue("email", Messages.EMAIL_ALREADY_EXIST);
|
||||
}
|
||||
} else {
|
||||
Utils.validateEmailAddress(email, errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUserService(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
}
|
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.wisemapping.validator;
|
||||
|
||||
import com.wisemapping.controller.Messages;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.Constants;
|
||||
|
@@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
package com.wisemapping.validator;
|
||||
|
||||
public interface Messages {
|
||||
String EMAIL_ALREADY_EXIST = "EMAIL_ALREADY_EXIST";
|
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.validator;
|
||||
|
||||
import com.wisemapping.model.Constants;
|
||||
import com.wisemapping.view.TagBean;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
public class TagValidator implements Validator {
|
||||
|
||||
public boolean supports(final Class clazz) {
|
||||
return clazz.equals(TagBean.class);
|
||||
}
|
||||
|
||||
public void validate(Object obj, Errors errors) {
|
||||
TagBean tag = (TagBean) obj;
|
||||
if (tag == null) {
|
||||
errors.rejectValue("user", "error.not-specified");
|
||||
} else {
|
||||
|
||||
// Validate email address ...
|
||||
final String tags = tag.getMindmapTags();
|
||||
ValidatorUtils.rejectIfExceeded(errors,
|
||||
"mindmapTags",
|
||||
"The tags must have less than "+ Constants.MAX_TAGS_LENGTH + " characters.",
|
||||
tags,
|
||||
Constants.MAX_TAGS_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.wisemapping.validator;
|
||||
|
||||
import com.wisemapping.controller.Messages;
|
||||
import com.wisemapping.service.UserService;
|
||||
import com.wisemapping.view.UserBean;
|
||||
import com.wisemapping.model.Constants;
|
||||
|
@@ -24,8 +24,6 @@ import org.springframework.validation.ValidationUtils;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.wisemapping.controller.Messages;
|
||||
|
||||
final public class Utils {
|
||||
//Set the email emailPattern string
|
||||
|
||||
|
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.view;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class TagBean
|
||||
{
|
||||
private Set<String> userTags;
|
||||
private String mindmapTitle;
|
||||
private int mindmapId;
|
||||
private String mindmapTags;
|
||||
|
||||
public TagBean(){}
|
||||
|
||||
public Set<String> getUserTags() {
|
||||
return userTags;
|
||||
}
|
||||
|
||||
public void setUserTags(Set<String> tags) {
|
||||
this.userTags = tags;
|
||||
}
|
||||
|
||||
public String getMindmapTags() {
|
||||
return mindmapTags;
|
||||
}
|
||||
|
||||
public void setMindmapTags(String tags) {
|
||||
this.mindmapTags = tags;
|
||||
}
|
||||
|
||||
public String getMindmapTitle()
|
||||
{
|
||||
return mindmapTitle;
|
||||
}
|
||||
|
||||
public void setMindmapTitle(String title)
|
||||
{
|
||||
this.mindmapTitle = title;
|
||||
}
|
||||
|
||||
public int getMindmapId()
|
||||
{
|
||||
return mindmapId;
|
||||
}
|
||||
|
||||
public void setMindmapId(int id)
|
||||
{
|
||||
this.mindmapId = id;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user