コード例 #1
0
 public function cambioPw($codigo)
 {
     try {
         $user = Sentry::findUserByResetPasswordCode($codigo);
         // Check if the reset password code is valid
         if ($user->checkResetPasswordCode($codigo)) {
             $input = Input::all();
             $reglas = array('password' => 'required|case_diff|letters|min:6|confirmed', 'password_confirmation' => 'required|min:6');
             $validation = Validator::make($input, $reglas);
             if ($validation->fails()) {
                 return Response::json(['success' => false, 'errors' => $validation->errors()->toArray()]);
             }
             // Attempt to reset the user password
             if ($user->attemptResetPassword($codigo, Input::get('password'))) {
                 // Password reset passed
                 return Response::json(['success' => true]);
             } else {
                 $error = array('error' => 'No  es posible cambiar la contraseña');
                 return Response::json(['success' => false, 'error' => $error]);
             }
         } else {
             $error = array('error' => 'El coóigo no es valido 1');
             return Response::json(['success' => false, 'error' => $error]);
         }
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         $error = 'El código no es valido';
         return Response::json(['success' => false, 'error' => $error]);
     }
     // Find the user using the user id
 }
コード例 #2
0
ファイル: AuthController.php プロジェクト: ioangogo/gruik
 public function resetPassword()
 {
     $token = Input::get('token', false);
     $password = Input::get('password', false);
     $password_confirmation = Input::get('password_confirmation', false);
     if ($token && $password && $password_confirmation) {
         if ($password === $password_confirmation) {
             try {
                 $user = Sentry::findUserByResetPasswordCode($token);
                 if ($user->checkResetPasswordCode($token)) {
                     if ($user->attemptResetPassword($token, $password)) {
                         Sentry::login($user);
                         return Response::json([], 200);
                     } else {
                         return Response::json(['flash' => 'Password reset fail'], 400);
                     }
                 }
             } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
                 return Response::json(['flash' => 'No user has been found'], 400);
             }
         } else {
             return Response::json(['flash' => 'Password and password confirmation must be the same'], 400);
         }
     }
     return Response::json(['flash' => 'Field missing'], 400);
 }
コード例 #3
0
 public function doUserRecover($code)
 {
     $password = Input::get('new_password');
     $confirmPassword = Input::get('new_password_confirm');
     $validator = Validator::make(array('new_password' => $password, 'new_password_confirm' => $confirmPassword), array('new_password' => 'required|min:6|max:16', 'new_password_confirm' => 'required|min:6|max:16|same:new_password'));
     if ($validator->fails()) {
         $data = array('status' => false, 'errors' => $validator->messages()->all());
         return Response::json($data);
     }
     $user = null;
     try {
         $user = Sentry::findUserByResetPasswordCode($code);
         if ($user->attemptResetPassword($code, $password)) {
             $data = array('status' => true, 'link' => URL::to('user/cabinet'));
         } else {
             $data = array('status' => false, 'errors' => array('Произошла ошибка во время установки нового пароля.'));
         }
         return Response::json($data);
     } catch (UserNotFoundException $e) {
         App::abort('404');
     }
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: samirios1/niter
 /**
  * Resets user password.
  * 
  * @param  string $code
  * @return Redirect
  */
 public function resetPassword($code)
 {
     $new = str_random(20);
     try {
         $user = Sentry::findUserByResetPasswordCode(e($code));
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         return Redirect::to('/')->withFailure(trans('users.invalid reset code'));
     }
     if ($this->user->resetPassword($user, e($code), $new)) {
         $data = array('username' => $user->username, 'email' => $user->email, 'password' => $new);
         $this->user->sendNewPassword($data);
         Event::fire('User.PasswordReset', array($user->username, Carbon::now()));
         return Redirect::to('/')->withSuccess(trans('users.pass reset success'));
     }
     return Redirect::to('/')->withFailure(trans('users.pass reset failure'));
 }
コード例 #5
0
 /**
  * Checks activation code for authenticity, then shows reset password form.
  *
  * @return Response
  */
 public function reset_form($code = FALSE)
 {
     if ($code === FALSE) {
         // Verification code is not present
         Session::flash('alert_danger', 'Unable to reset password. Please use the link from the password reset email. If you are experiencing difficulty, please contact ACME.');
         return Redirect::to('/login');
     }
     try {
         $user = Sentry::findUserByResetPasswordCode($code);
         // Check reset code was created < 1 hour ago
         $code_hours_max = 1;
         // Set max age in hours
         $last_update = strtotime($user->updated_at);
         $time_since_update = time() - $last_update;
         // in seconds
         $code_max_age = $code_hours_max * 60 * 60;
         // in seconds
         if ($time_since_update > $code_max_age) {
             // Verification code is over 1 hour old
             Session::flash('alert_danger', 'Expired verification code. Unable to reset password. Please try password recovery again.');
             return Redirect::to('/login/recover');
         } else {
             // Show Password Reset Form
             return View::make('public.reset_password', array('code' => $code, 'user_id' => $user->id));
         }
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         // Verification code is not valid for any user
         Session::flash('alert_danger', 'Invalid verification code. Unable to reset password. Please try password recovery again.');
         return Redirect::to('/login/recover');
     }
 }
コード例 #6
0
 /**
  *  @SWG\Operation(
  *      partial="usuarios.show",
  *      summary="Muestra el usuario especificado",
  *      @SWG\Parameter(
  *       name="id",
  *       description="Identificador del usuario",
  *       required=true,
  *       type="integer",
  *       paramType="path",
  *       allowMultiple=false
  *     ),
  *  )
  * @return Response
  */
 public function regresaUsuario()
 {
     try {
         $user = Sentry::findUserByResetPasswordCode(Input::get('codigo'));
     } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
         echo 'User was not found.';
     }
     return $user;
 }