-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#25 パスワード忘れ時に、パスワード初期化メールを出す メールアドレスを変更する際にも、確認メールを出す
- Loading branch information
1 parent
723318f
commit 1f92cf4
Showing
27 changed files
with
1,060 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
src/main/java/org/support/project/knowledge/control/open/PasswordInitializationControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
Oops, something went wrong.