/** * change password processing * @return ViewModel */ public function updatePwAction() { $id = $this->params()->fromPost('login_id'); $pw = $this->params()->fromPost('login_pw'); $key = $this->params()->fromPost('key_id'); $new_pw = $this->params()->fromPost('new_pw'); $token_id = $this->params()->fromPost('token_id'); $sess_token_id = $this->container()->get('token_id'); $this->container()->clear('token_id'); // when can't get require item if (!$id || !$pw || !$key || !$new_pw || !$token_id || !$sess_token_id || $token_id != $sess_token_id) { return $this->redirect()->toRoute('app', array('controller' => 'index')); } $this->container()->set('login_id', $id); $user = new UserEntity(); $row = $user->db()->getLoginInfo($id, $key); $success = false; $ngCount = false; $message = null; if (!$row->user_no) { $message = "Unknown account"; // $message = "アカウントは不明です。"; } else { if (LOGIN_FAILED_COUNT && LOGIN_FAILED_COUNT <= $row->ng_count) { $message = "Account is locked"; // $message = "アカウントはロックされています。"; } else { if (!$row->login_pw || md5($row->login_pw . $token_id) != $pw) { $message = "Failed"; // $message = "認証に失敗しました。"; $ngCount = true; } else { if ($id == $new_pw) { $message = "Don't use same password as ID"; // $message = "ログインIDと同じパスワードは使用できません。"; } else { $success = true; } } } } // save login error number if (!$success && $ngCount) { $user->db()->insertLoginFailed($row->user_no); } if ($success) { $ret = $user->db()->checkLoginPw($row->user_no, $new_pw); if ($ret) { $message = "Don't use same password as past one."; // $message = "過去利用したパスワードは設定出来ません。"; $success = false; } } $tmp_message = "Confirm password policy\n"; // $tmp_message = "パスワードポリシーに違反しています。\n"; if ($success) { $validate = new StringLength(); $validate->setOptions(array('min' => (int) PW_MIN_LENGTH, 'max' => (int) PW_MAX_LENGTH, 'encoding' => 'UTF-8')); $ret = $validate->isValid($new_pw); if (!$ret) { $message = $tmp_message . current($validate->getMessages()); $success = false; } } if ($success && strlen(PW_REGEX_PATTERN)) { unset($validate); $validate = new Regex(array('pattern' => PW_REGEX_PATTERN)); $ret = $validate->isValid($new_pw); if (!$ret) { $message = $tmp_message . current($validate->getMessages()); $success = false; } } // save error message & redirect to input form if ($message || !$success) { $this->flashMessenger()->addMessage($message); return $this->redirect()->toRoute('app', array('controller' => 'index', 'action' => 'change-pw')); } $ret = $user->changePw($row->user_no, $new_pw, 0); $message .= 'Change password ' . ($ret ? 'success' : 'failed'); // . ($ret ? '成功しました。' : '失敗しました。'); $this->flashMessenger()->addMessage($message); if ($ret) { return $this->redirect()->toRoute('app', array('controller' => 'index')); } else { return $this->redirect()->toRoute('app', array('controller' => 'index', 'action' => 'change-pw')); } $view = new ViewModel(); $view->setTerminal(true); return $view; }
public function getStringLengthValidator() { if ($this->stringLengthValidator === NULL) { $validator = new StringLength(); $validator->setOptions($this->getStringLengthConfig())->setMessages(array(StringLength::TOO_SHORT => $this->getErrorMessage('STRINGLENGTH::TOO_SHORT'), StringLength::TOO_LONG => $this->getErrorMessage('STRINGLENGTH::TOO_LONG'), StringLength::INVALID => $this->getErrorMessage('STRINGLENGTH::INVALID'))); $this->setStringLengthValidator($validator); } return $this->stringLengthValidator; }