Example #1
0
 public function login()
 {
     Config::set('database.default', Input::get('server'));
     $db = Input::get('server');
     $credentials = array('memb___id' => Input::get('id'), 'password' => Input::get('pass'), 'bloc_code' => 0);
     $ip = Request::getClientIp();
     $suspect = LoginAttempt::find($ip);
     if (is_null($suspect)) {
         $newlogin = new LoginAttempt();
         $newlogin->ip = $ip;
         $newlogin->attempt = 1;
         $newlogin->save();
         if (Auth::attempt($credentials)) {
             Session::put('db', $db);
             $webuser_id = Auth::user()->webuser_id;
             if ($webuser_id != 0) {
                 Session::put('WebUserId', $webuser_id);
             }
             return Redirect::to(Input::get('url'))->with('message', 'Bạn đã đăng nhập thành công!');
         } else {
             return Redirect::to(Input::get('url'))->with('message', 'Thông tin tài khoản không chính xác!')->withError(10);
         }
     } else {
         $updated_at = $suspect->updated_at;
         $attempt = $suspect->attempt;
         $nowless5 = date('Y-m-d H:i:s', time() - 300);
         if ($updated_at > $nowless5) {
             if ($suspect->attempt > 5) {
                 return Redirect::to(Input::get('url'))->with('message', 'Wait another 5 minutes to login!')->withError(10);
             } else {
                 if (Auth::attempt($credentials)) {
                     Session::put('db', $db);
                     $webuser_id = Auth::user()->webuser_id;
                     if ($webuser_id != 0) {
                         Session::put('WebUserId', $webuser_id);
                     }
                     return Redirect::to(Input::get('url'))->with('message', 'Bạn đã đăng nhập thành công!');
                 } else {
                     $suspect->attempt = $suspect->attempt + 1;
                     $suspect->save();
                     return Redirect::to(Input::get('url'))->with('message', 'Thông tin tài khoản không chính xác!')->withError(10);
                 }
             }
         } else {
             if (Auth::attempt($credentials)) {
                 Session::put('db', $db);
                 $webuser_id = Auth::user()->webuser_id;
                 if ($webuser_id != 0) {
                     Session::put('WebUserId', $webuser_id);
                 }
                 return Redirect::to(Input::get('url'))->with('message', 'Bạn đã đăng nhập thành công!');
             } else {
                 $suspect->attempt = 1;
                 $suspect->save();
                 $suspect->touch();
                 return Redirect::to(Input::get('url'))->with('message', 'Thông tin tài khoản không chính xác!')->withError(10);
             }
         }
     }
 }
Example #2
0
 public function dologin()
 {
     Config::set('database.default', Input::get('server'));
     $db = Input::get('server');
     $id = Input::get('id');
     $credentials = array('memb___id' => $id, 'password' => Input::get('password1'), 'bloc_code' => 0);
     $ip = Request::getClientIp();
     $suspect = LoginAttempt::find($ip);
     $destination = Session::get('fromfilter');
     if (is_null($destination)) {
         $destination = 'DashBoard';
     }
     if (is_null($suspect)) {
         $newlogin = new LoginAttempt();
         $newlogin->ip = $ip;
         $newlogin->attempt = 1;
         $newlogin->save();
         if (Auth::attempt($credentials)) {
             Session::put('db', $db);
             $webuser_id = Auth::user()->webuser_id;
             if ($webuser_id == 0) {
                 return Redirect::to('ManageAcc');
             }
             $webU = WebUser::find($webuser_id);
             $name = $webU->username;
             $group = $webU->role;
             $coin = $this->getCoin($id);
             Session::put('nameCok', $name);
             Session::put('groupCok', $group);
             Session::put('ipCok', $ip);
             Session::put('WebUserId', $webuser_id);
             Session::put('idCok', $id);
             Session::put('coinCok', $coin);
             return Redirect::to($destination);
         } else {
             return Redirect::to('login')->with('message', 'Incorrect account/password!');
         }
     } else {
         $updated_at = $suspect->updated_at;
         $attempt = $suspect->attempt;
         $nowless5 = date('Y-m-d H:i:s', time() - 300);
         if ($updated_at > $nowless5) {
             if ($suspect->attempt > 5) {
                 return Redirect::to('/login')->withInput()->with('message', 'Wait another 5 minutes to login!');
             } else {
                 if (Auth::attempt($credentials)) {
                     Session::put('db', $db);
                     $webuser_id = Auth::user()->webuser_id;
                     if ($webuser_id == 0) {
                         return Redirect::to('ManageAcc');
                     }
                     $webU = WebUser::find($webuser_id);
                     $name = $webU->username;
                     $group = $webU->role;
                     $coin = $this->getCoin($id);
                     Session::put('nameCok', $name);
                     Session::put('groupCok', $group);
                     Session::put('ipCok', $ip);
                     Session::put('WebUserId', $webuser_id);
                     Session::put('idCok', $id);
                     Session::put('coinCok', $coin);
                     return Redirect::to($destination);
                 } else {
                     $suspect->attempt = $suspect->attempt + 1;
                     $suspect->save();
                     return Redirect::to('login')->withInput()->with('message', 'Incorrect account/password!');
                 }
             }
         } else {
             if (Auth::attempt($credentials)) {
                 Session::put('db', $db);
                 $webuser_id = Auth::user()->webuser_id;
                 if ($webuser_id == 0) {
                     return Redirect::to('ManageAcc');
                 }
                 $webU = WebUser::find($webuser_id);
                 $name = $webU->username;
                 $group = $webU->role;
                 $coin = $this->getCoin($id);
                 Session::put('nameCok', $name);
                 Session::put('groupCok', $group);
                 Session::put('ipCok', $ip);
                 Session::put('WebUserId', $webuser_id);
                 Session::put('idCok', $id);
                 Session::put('coinCok', $coin);
                 return Redirect::to($destination);
             } else {
                 $suspect->attempt = 1;
                 $suspect->save();
                 $suspect->touch();
                 return Redirect::to('login')->with('message', 'Incorrect account/password!');
             }
         }
     }
 }