/** * Call * * Pulls out a anonymous sent from an http header * * Perform actions specific to this middleware and optionally * call the next downstream middleware. */ public function call() { $sessionId = $this->getApp()->getRequest()->headers('SESSION'); $foundSession = call_user_func($this->sessionModelClass . '::init', $this->getApp()); if ($foundSession->findById($sessionId)) { $this->session = $foundSession; $this->getApp()->getRequest()->session = $this->session; $now = new \DateTime('now'); $this->session->lastAccessed = $now; $user = User::init($this->getApp()); $user->findById($this->session->userId); $user->lastAccessed = $now; $user->save(); $this->session->user = $user; } if (!empty($this->next)) { $this->next->call(); } }
/** * @docs-name Email forgot password token * * json should be passed in in the following form * ~~~ * { * "email": string * } * ~~~ * * @docs-param email string body required json object containing a user's email */ public function postForgotPassword() { if ($this->getEmailProvider() == null) { $this->getApp()->returnError(Errors::$PASSWORD_EMAIL_PROVIDER); } if ($this->forgotEmailTemplate == null) { $this->getApp()->returnError(Errors::$PASSWORD_EMAIL_TEMPLATE); } /** * @var $user User */ $data = json_decode($this->getApp()->getRequest()->getBody()); try { $email = $data->email; } catch (\Exception $e) { $this->getApp()->returnError(Errors::$PASSWORD_EMAIL_REQUIRED); } $user = User::init($this->getApp()); if (!$user->findByField('email', $email)) { $this->getApp()->returnError(Errors::$PASSWORD_NO_USER_EMAIL); } $user->lastAccessed = new \DateTime('now'); $user->save(); $authToken = Identity::passHash($user->passHash, $user->lastAccessed->getTimestamp()); $this->forgotEmailTemplate->mergeData(array('!authToken' => $authToken)); $resp = $this->getEmailProvider()->sendEmail($user->email, $this->forgotEmailTemplate); echo json_encode($resp); }