public function changePassAction() { $params = $this->dispatcher->getParams(); if (!isset($params['params'][0], $params['params'][1])) { echo "You did not specify the name or password.\n"; return; } $name = $params['params'][0]; $pass = $params['params'][1]; try { $administrator = PhadAdministrators::findFirstByName($name); $administrator->password = $this->security->hash($pass); $administrator->save(); } catch (Exception $e) { $massage = $e->getMessage(); echo "{$massage}\n"; return; } echo "The password was changed successfully.\n"; }
/** * Get the entity related to user in the active identity * * @throws Exception * @return PhadAdministrators */ public function getUser() { $identity = $this->session->get('phad-auth-identity'); if (!isset($identity['id'])) { return false; } $user = PhadAdministrators::findFirstById($identity['id']); if ($user == false) { throw new Exception('The user does not exist'); } return $user; }