Skip to content

Commit

Permalink
#2
Browse files Browse the repository at this point in the history
#25
パスワード忘れ時に、パスワード初期化メールを出す
メールアドレスを変更する際にも、確認メールを出す
  • Loading branch information
koda-masaru committed Apr 11, 2015
1 parent 723318f commit 1f92cf4
Show file tree
Hide file tree
Showing 27 changed files with 1,060 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ protected String getResource(String key) {
Resources resources = Resources.getInstance(HttpUtil.getLocale(getRequest()));
return resources.getResource(key);
}
protected String getResource(String key, String... params) {
Resources resources = Resources.getInstance(HttpUtil.getLocale(getRequest()));
return resources.getResource(key, params);
}

protected void addMsgInfo(String key, String... params) {
Resources resources = Resources.getInstance(HttpUtil.getLocale(getRequest()));
Expand All @@ -85,9 +89,9 @@ protected void addMsgError(String key, String... params) {
errors.add(HtmlUtils.escapeHTML(msg));
}

protected void setResult(String successMsg, List<ValidateError> errors) {
protected void setResult(String successMsg, List<ValidateError> errors, String... params) {
if (errors == null || errors.isEmpty()) {
addMsgSuccess(successMsg);
addMsgSuccess(successMsg, params);
} else {
for (ValidateError validateError : errors) {
if (validateError.getLevel().intValue() == LogLevel.ERROR.getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,7 @@ public Boundary list() throws Exception {
String keyword = getParam("keyword");
String tag = getParam("tag");
String user = getParam("user");

if (StringUtils.isNotEmpty(keyword)) {
NotifyAction notify = Container.getComp(NotifyAction.class);
MessageResult message = new MessageResult();
message.setMessage("検索されたよ: " + keyword);
notify.notifyObservers(message);
}

List<KnowledgesEntity> knowledges = new ArrayList<>();

if (StringUtils.isInteger(tag)) {
//タグを選択している
LOG.trace("show on Tag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,63 @@

import java.util.Locale;

import org.apache.taglibs.standard.tag.common.fmt.SetLocaleSupport;
import org.support.project.common.util.StringUtils;
import org.support.project.knowledge.control.Control;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.exception.InvalidParamException;

public class LangControl extends Control {

public Boundary en() {
Locale locale = Locale.ENGLISH;
HttpUtil.setLocale(super.getRequest(), locale);
this.setLocale(getLoginedUser(), HttpUtil.getLocale(getRequest()));
return redirect(getRequest().getContextPath() + "/index");
}


public Boundary ja() {
Locale locale = Locale.JAPANESE;
HttpUtil.setLocale(super.getRequest(), locale);
this.setLocale(getLoginedUser(), HttpUtil.getLocale(getRequest()));
return redirect(getRequest().getContextPath() + "/index");
}

private void setLocale(LoginedUser loginedUser, Locale locale) {
if (loginedUser == null) {
return;
}
loginedUser.setLocale(locale);
}


public Boundary select() throws InvalidParamException {
String LocaleID = getPathString();
if (StringUtils.isEmpty(LocaleID)) {
return en();
} else if (LocaleID.equals("en")) {
return en();
} else if (LocaleID.equals("ja")) {
return ja();
}
Locale locale = Locale.ENGLISH;
if (LocaleID.indexOf("_") == -1) {
locale = new Locale(LocaleID);
} else {
String[] sp = LocaleID.split("_");
if (sp.length == 2) {
locale = new Locale(sp[0], sp[1]);
} else if (sp.length >= 3) {
locale = new Locale(sp[0], sp[1], sp[2]);
}
}
HttpUtil.setLocale(super.getRequest(), locale);
this.setLocale(getLoginedUser(), HttpUtil.getLocale(getRequest()));
return redirect(getRequest().getContextPath() + "/index");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package org.support.project.knowledge.control.open;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.support.project.common.bean.ValidateError;
import org.support.project.common.util.StringUtils;
import org.support.project.common.validate.Validator;
import org.support.project.common.validate.ValidatorFactory;
import org.support.project.knowledge.control.Control;
import org.support.project.knowledge.logic.PasswordInitializationLogic;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.dao.PasswordResetsDao;
import org.support.project.web.entity.PasswordResetsEntity;
import org.support.project.web.exception.InvalidParamException;

public class PasswordInitializationControl extends Control {

/**
* パスワード忘れの画面を表示
* @return
*/
public Boundary view() {
return forward("forgot_pass_request.jsp");
}

/**
* パスワード初期化のリクエストの受付
* @return
*/
public Boundary request() {
String email = getParam("username");

//入力チェック
List<ValidateError> errors = new ArrayList<ValidateError>();
Validator validator = ValidatorFactory.getInstance(Validator.REQUIRED);
ValidateError validateError = validator.validate(email, "Email address");
if (validateError != null) {
errors.add(validateError);
}

validator = ValidatorFactory.getInstance(Validator.MAIL);
validateError = validator.validate(email, "Email address");
if (validateError != null) {
errors.add(validateError);
}
if (!errors.isEmpty()) {
setResult("message.success.insert", errors);
return forward("forgot_pass_request.jsp");
}

// 初期化パスワードデータを発行
validateError = PasswordInitializationLogic.get().insertPasswordReset(email, HttpUtil.getLocale(getRequest()));
if (validateError != null) {
errors.add(validateError);
}

// 画面表示
setResult("message.success.insert", errors);
if (!errors.isEmpty()) {
return forward("forgot_pass_request.jsp");
}

return forward("forgot_pass_result.jsp");
}


/**
* パスワード初期化画面を表示
* @return
* @throws InvalidParamException
*/
public Boundary init() throws InvalidParamException {
String key = getPathString();
PasswordResetsDao resetsDao = PasswordResetsDao.get();
PasswordResetsEntity resetsEntity = resetsDao.selectOnKey(key);
if (resetsEntity == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}

long now = new Date().getTime();
if (now - resetsEntity.getInsertDatetime().getTime() > 1000 * 60 * 60) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}
setAttribute("key", key);
setAttribute("reset", resetsEntity);
return forward("password_reset.jsp");
}


/**
* パスワードの初期化
* @return
*/
public Boundary change() {
String key = getParam("key");
PasswordResetsDao resetsDao = PasswordResetsDao.get();
PasswordResetsEntity resetsEntity = resetsDao.selectOnKey(key);
if (resetsEntity == null) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}
long now = new Date().getTime();
if (now - resetsEntity.getInsertDatetime().getTime() > 1000 * 60 * 60) {
return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}
setAttribute("key", key);
setAttribute("reset", resetsEntity);

List<ValidateError> errors = new ArrayList<>();
if (!StringUtils.isEmpty(getParam("password"))) {
if (!getParam("password").equals(getParam("confirm_password", String.class))) {
ValidateError error = new ValidateError("knowledge.user.invalid.same.password");
errors.add(error);
}
} else {
ValidateError error = new ValidateError("errors.required", "Password");
errors.add(error);
}
if (!errors.isEmpty()) {
return forward("password_reset.jsp");
}

// パスワードデータを初期化
ValidateError validateError = PasswordInitializationLogic.get().changePassword(resetsEntity, getParam("password"));
if (validateError != null) {
errors.add(validateError);
}

// 画面表示
setResult(getResource("message.success.update.target", "Password"), errors);
if (!errors.isEmpty()) {
return forward("password_reset.jsp");
}
return forward("reset_result.jsp");
}

}
Loading

0 comments on commit 1f92cf4

Please sign in to comment.