Exemplo n.º 1
0
 /**
  * Log an user
  *
  * @return Response
  */
 public function postPublicLogin()
 {
     // Check if the form validates with success
     if ($this->checkLogin()) {
         // return var_dump($this->credentials);
         // redirect the user back to the intended page
         // or defaultpage if there isn't one
         if (Auth::attempt($this->credentials, true)) {
             //track user
             parent::track('loggin', 'Auth', Auth::user()->id);
             //return Redirect::intended('/');
             if (Request::ajax()) {
                 return Response::json(array('statut' => 'success', 'message' => I18n::get('auth.login-success'), 'user_id' => User::getIdByAuth(Auth::user()->id)));
             } else {
                 return Redirect::route('public.login')->with('success', I18n::get('auth.login-success'))->withInput(Input::except('password'));
             }
         } else {
             $user = AuthUser::where('email', Input::get('email'))->first();
             if (empty($user) || !isset($user)) {
                 if (Request::ajax()) {
                     return Response::json(array('statut' => 'danger', 'message' => I18n::get('auth.unknow_email')));
                 } else {
                     return Redirect::route('public.login')->with('error', I18n::get('auth.unknow_email'))->withInput(Input::except('password'));
                 }
             }
             if (Request::ajax()) {
                 return Response::json(array('statut' => 'danger', 'message' => I18n::get('auth.incorrect_password')));
             } else {
                 return Redirect::route('public.login')->with('error', I18n::get('auth.incorrect_password'))->withInput(Input::except('password'));
             }
         }
         $this->user = $user;
         return Redirect::to('/');
     }
     if (Request::ajax()) {
         return Response::json(array('statut' => 'danger', 'message' => I18n::get('auth.incorrect_password')));
     } else {
         return Redirect::route('public.login')->withInput()->withErrors($this->validator);
     }
 }