Exemple #1
0
 /**
  * Accept the password change, send new password to user
  *
  * @return array
  */
 public function retrieve_accepted()
 {
     if (!$this->_params['token']) {
         return array('success' => false, 'message' => 'Invalid token for password change.');
     }
     // Try to connect database = if an error occurs, it will return an array, nothing otherwise
     if ($connect = $this->_connect_oauth()) {
         return $connect;
     }
     $user = User::where('user_password_change_token', '=', $this->_params['token'])->first();
     if (is_object($user)) {
         $new_password = $this->_random_password();
         $user->user_password = $this->_hash_password($new_password);
         $user->user_password_change_token = '';
         $user->save();
         // Create email
         $mail = new \Ieru\Ieruapis\Organic\PHPMailer();
         $mail->WordWrap = 50;
         $mail->IsHTML(true);
         $mail->From = '*****@*****.**';
         $mail->FromName = 'Organic.Edunet';
         $mail->AddAddress($user->user_email);
         // Add a recipient
         $mail->AddReplyTo('*****@*****.**', 'Information');
         $mail->Subject = '[Organic.Edunet] Account password changed';
         $mail->Body = '<p>Your account password has been changed to username "' . $user->user_username . '": ' . $new_password . '</p>';
         $mail->AltBody = "Your account password has been changed to '" . $user->user_username . "': " . $new_password;
         $mail->Send();
     } else {
         return array('success' => false, 'message' => 'Incorrect token for password change.');
     }
     return array('success' => true, 'message' => 'Password changed and mail sent.');
 }