Exemplo n.º 1
0
 /**
  * Creates a token to reset the password for the user
  *
  * @return Response
  */
 public function forgot(Request $request)
 {
     $email = $request->json()->get('email');
     $id = $request->json()->get('id');
     // get site
     $site = Site::getById($id);
     if ($site != NULL) {
         // get user
         $user = User::getByEmail($email, $site->id);
         if ($user != NULL) {
             $user->token = uniqid();
             // save user
             $user->save($site->id);
             // send email
             $to = $user->email;
             $from = env('EMAILS_FROM');
             $fromName = env('EMAILS_FROM_NAME');
             $subject = env('BRAND') . ': Reset Password';
             $file = app()->basePath() . '/resources/emails/reset-password.html';
             // create strings to replace
             $resetUrl = env('APP_URL') . '/reset/' . $site->id . '/' . $user->token;
             $replace = array('{{brand}}' => env('BRAND'), '{{reply-to}}' => env('EMAILS_FROM'), '{{reset-url}}' => $resetUrl);
             // send email from file
             Utilities::sendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
             return response('OK', 200);
         }
     }
     return response('Unauthorized', 401);
 }