From 7a3e351178fde9d8b785867868fb40cbae4c8ab2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Aug 2019 14:05:58 +0200 Subject: [ticket/11327] Clean up code style a bit PHPBB3-11327 --- phpBB/phpbb/ucp/controller/reset_password.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'phpBB/phpbb/ucp/controller/reset_password.php') diff --git a/phpBB/phpbb/ucp/controller/reset_password.php b/phpBB/phpbb/ucp/controller/reset_password.php index 50d3ce91eb..82b9083175 100644 --- a/phpBB/phpbb/ucp/controller/reset_password.php +++ b/phpBB/phpbb/ucp/controller/reset_password.php @@ -18,6 +18,7 @@ use phpbb\config\config; use phpbb\controller\helper; use phpbb\db\driver\driver_interface; use phpbb\event\dispatcher; +use phpbb\exception\http_exception; use phpbb\language\language; use phpbb\log\log_interface; use phpbb\passwords\manager; @@ -156,7 +157,7 @@ class reset_password { if (!check_form_key('ucp_reset_password')) { - return $this->helper->message('FORM_INVALID'); + throw new http_exception(Response::HTTP_UNAUTHORIZED, 'FORM_INVALID'); } if (empty($email)) @@ -192,11 +193,10 @@ class reset_password $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, 2); // don't waste resources on more rows than we need $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); if (count($rowset) > 1) { - $this->db->sql_freeresult($result); - $this->template->assign_vars([ 'USERNAME_REQUIRED' => true, 'EMAIL' => $email, @@ -206,14 +206,13 @@ class reset_password { $message = $this->language->lang('PASSWORD_RESET_LINK_SENT') . '

' . $this->language->lang('RETURN_INDEX', 'root_path}index.{$this->php_ext}") . '">', ''); - $user_row = empty($rowset) ? [] : $rowset[0]; - $this->db->sql_freeresult($result); - - if (!$user_row) + if ($rowset === false) { return $this->helper->message($message); } + $user_row = $rowset[0]; + if ($user_row['user_type'] == USER_IGNORE || $user_row['user_type'] == USER_INACTIVE) { return $this->helper->message($message); @@ -356,7 +355,7 @@ class reset_password return $this->helper->message($message); } - $error = []; + $errors = []; if ($submit) { @@ -395,12 +394,12 @@ class reset_password ], 'password_confirm' => ['string', true, $this->config['min_pass_chars'], $this->config['max_pass_chars']], ]; - $error = array_merge($error, validate_data($data, $check_data)); + $errors = array_merge($errors, validate_data($data, $check_data)); if (strcmp($data['new_password'], $data['password_confirm']) !== 0) { - $error[] = ($data['password_confirm']) ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY'; + $errors[] = $data['password_confirm'] ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY'; } - if (empty($error)) + if (empty($errors)) { $sql_ary = [ 'user_password' => $this->passwords_manager->hash($data['new_password']), @@ -423,7 +422,7 @@ class reset_password $this->template->assign_vars([ 'S_IS_PASSWORD_RESET' => true, - 'ERROR' => !empty($error) ? implode('
', array_map([$this->language, 'lang'], $error)) : '', + 'ERROR' => !empty($errors) ? implode('
', array_map([$this->language, 'lang'], $errors)) : '', 'S_PROFILE_ACTION' => $this->helper->route('phpbb_ucp_reset_password_controller'), 'S_HIDDEN_FIELDS' => build_hidden_fields([ 'u' => $user_id, -- cgit v1.2.1