/** * Helper to return a failure. It does this by asking the * \Viper\Core\Response class to throw an exception. * * @param mixed $message * @param string $type */ protected function failure($message, $type) { Response::error($message, $type); }
/** * Allows users to reset their password. They are sent an email with a code * that they can use to reset their password. * * @return string */ public function reset() { /** * Make sure that we actually have a user token otherwise we'll have * no idea who we're creating a reset for. */ if ($this->isValidUser()) { /** * Load the reset on the off chance that there is already one. */ $user = Auth::user(); Response::add('user', $user); $user->load('reset'); /** * Check to see if a user reset exists, and create one if not. */ if ($user->reset && $user->reset->count() == 0) { /** * Create the user reset and generate a unique code. */ $reset = new Models\User_Reset(); $reset->generate(); /** * Assign the reset to the user. */ $user->reset()->save($reset); } $this->fireEvent(['user' => $this->user]); /** * Get the user data for the email. Not all of this is used in the default * email, but it allows for custom emails to contain more. */ Response::add('reset', $reset); $user->load('profile'); $user_data = $user->toArray(); /** * Send the email. */ Mail::send('emails.users.reset', $user_data, function ($message) use($user_data) { $message->to($user_data['email'], $user_data['profile']['name'])->subject('Password Reset'); }); /** * Unfortunately because of the way Laravels mail library works, * we can't tell whether or not an email was actually sent. It's safe * to let the end developer to control this side. */ return Response::toJson(); } /** * If no token is provided, or the user property is null, we want * to throw an exception of token type, as this should not happen, * if it does, the developer is being naughty and calling this * incorrectly. */ Response::error('No token provided', 'token'); }