/**
  * Post of login page
  * @param type LoginRequest $request
  * @return type Response
  */
 public function postLogin(LoginRequest $request)
 {
     // Set login attempts and login time
     $loginAttempts = 1;
     $usernameinput = $request->input('email');
     $password = $request->input('password');
     $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
     // If session has login attempts, retrieve attempts counter and attempts time
     if (\Session::has('loginAttempts')) {
         $loginAttempts = \Session::get('loginAttempts');
         $loginAttemptTime = \Session::get('loginAttemptTime');
         // $credentials = $request->only('email', 'password');
         $usernameinput = $request->input('email');
         $password = $request->input('password');
         $field = filter_var($usernameinput, FILTER_VALIDATE_EMAIL) ? 'email' : 'user_name';
         // If attempts > 3 and time < 10 minutes
         if ($loginAttempts > 4 && time() - $loginAttemptTime <= 600) {
             return redirect()->back()->with('error', 'Maximum login attempts reached. Try again in a while');
         }
         // If time > 10 minutes, reset attempts counter and time in session
         if (time() - $loginAttemptTime > 600) {
             \Session::put('loginAttempts', 1);
             \Session::put('loginAttemptTime', time());
         }
     } else {
         // If no login attempts stored, init login attempts and time
         \Session::put('loginAttempts', $loginAttempts);
         \Session::put('loginAttemptTime', time());
     }
     // If auth ok, redirect to restricted area
     \Session::put('loginAttempts', $loginAttempts + 1);
     if ($this->auth->attempt([$field => $usernameinput, 'password' => $password], $request->has('remember'))) {
         if (Auth::user()->role == 'user') {
             return \Redirect::route('/');
         } else {
             return redirect()->intended($this->redirectPath());
         }
     }
     return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(['email' => $this->getFailedLoginMessage(), 'password' => $this->getFailedLoginMessage()]);
     // Increment login attempts
 }
Esempio n. 2
0
 /**
  * Post of login page
  * @param type LoginRequest $request
  * @return type Response
  */
 public function postLogin(LoginRequest $request)
 {
     // Set login attempts and login time
     $loginAttempts = 1;
     $credentials = $request->only('email', 'password');
     $email = $request->email;
     // $ip_address = $_SERVER['REMOTE_ADDR'];
     //       $limit_login = Limit_Login::where('email' , '=' , $email)->where('ip_address', '=', $ip_address)->first();
     //       if(isset($limit_login)) {
     //       }
     // If session has login attempts, retrieve attempts counter and attempts time
     if (\Session::has('loginAttempts')) {
         $loginAttempts = \Session::get('loginAttempts');
         $loginAttemptTime = \Session::get('loginAttemptTime');
         $credentials = $request->only('email', 'password');
         // If attempts > 3 and time < 10 minutes
         if ($loginAttempts > 4 && time() - $loginAttemptTime <= 600) {
             return redirect()->back()->with('error', 'Maximum login attempts reached. Try again in a while');
         }
         // If time > 10 minutes, reset attempts counter and time in session
         if (time() - $loginAttemptTime > 600) {
             \Session::put('loginAttempts', 1);
             \Session::put('loginAttemptTime', time());
         }
     } else {
         \Session::put('loginAttempts', $loginAttempts);
         \Session::put('loginAttemptTime', time());
     }
     // If auth ok, redirect to restricted area
     \Session::put('loginAttempts', $loginAttempts + 1);
     if ($this->auth->attempt($credentials, $request->has('remember'))) {
         if (Auth::user()->role == 'user') {
             return \Redirect::route('/');
         } else {
             return redirect()->intended($this->redirectPath());
         }
     }
     return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(['email' => $this->getFailedLoginMessage(), 'password' => $this->getFailedLoginMessage()]);
     // Increment login attempts
 }
 /**
  * Post of login page
  * @param type LoginRequest $request
  * @return type Response
  */
 public function postLogin(LoginRequest $request)
 {
     // $email = $request->input('email');
     // $password = Hash::make($request->input('password'));
     // $remember = $request->input('remember');
     // dd([$email,$password,$remember]);
     $credentials = $request->only('email', 'password');
     if ($this->auth->attempt($credentials, $request->has('remember'))) {
         if (Auth::user()->role == 'user') {
             return \Redirect::route('home');
         } else {
             return redirect()->intended($this->redirectPath());
         }
     }
     return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(['email' => $this->getFailedLoginMessage(), 'password' => $this->getFailedLoginMessage()]);
 }