Exemplo n.º 1
0
 protected function afterLogin($fromCookie)
 {
     $loginHistory = new LoginHistory();
     $loginHistory->user_id = $this->id;
     $loginHistory->ip = Yii::app()->request->getUserHostAddress();
     $loginHistory->date = time();
     $loginHistory->from_cookie = intval($fromCookie);
     $loginHistory->save(false);
 }
Exemplo n.º 2
0
 /**
  * Prihlasi pouzivatela do systemu na zaklade mena a hesla
  * 
  * vracia true/false na zaklade toho, ci sa podarilo pouzivatela 
  * prihlasit do systemu
  *
  * @param string $username
  * @param string $password
  * @return boolean true/false
  */
 public function login($username, $password)
 {
     $User = new User();
     // zisti ci existuje
     $someone = $User->findByUsername($username);
     if (empty($someone['User']['username'])) {
         sleep(1);
         return false;
     }
     // ak ma ldapaname, skus ho prihlasit cez ldap najskor
     if (!$this->ldap_login($someone['User']['ldapname'], $password)) {
         if ($someone['User']['password'] != md5($password)) {
             sleep(1);
             return false;
         }
     }
     // ziskaj prava
     $permissions = array('permissions' => $this->clearances($someone['User']['username']));
     // ziskaj IP adresu
     $ip = $this->ip();
     $someone['User']['ip'] = $ip;
     // zapis do session
     $_SESSION['User'] = array_merge($someone['User'], $permissions);
     // zapis do login_history
     $LoginHistory = new LoginHistory();
     $LoginHistoryData = array('user_id' => $someone['User']['id'], 'ip' => $ip, 'login_time' => 'NOW()');
     $LoginHistory->save($LoginHistoryData);
     // replace do users_online
     $UsersOnline = new UsersOnline();
     $this->Session->write('foo', 'bar');
     $UsersOnlineData = array('user_id' => $someone['User']['id'], 'session_id' => $this->Session->id(), 'session_start' => 'NOW()', 'session_last_refresh' => 'NOW()');
     $UsersOnline->delete(session_id());
     $UsersOnline->save($UsersOnlineData);
     return true;
 }
Exemplo n.º 3
0
 /**
  * Attempt to do login
  *
  */
 public function do_login()
 {
     $input = array('email' => Input::get('email'), 'username' => Input::get('email'), 'password' => Input::get('password'), 'remember' => Input::get('remember'));
     // If you wish to only allow login from confirmed users, call logAttempt
     // with the second parameter as true.
     // logAttempt will check if the 'email' perhaps is the username.
     // Get the value from the config file instead of changing the controller
     if (Confide::logAttempt($input, Config::get('confide::signup_confirm'))) {
         // Redirect the user to the URL they were trying to access before
         // caught by the authentication filter IE Redirect::guest('user/login').
         // Otherwise fallback to '/'
         // Fix pull #145
         $user = Confide::user();
         $ip = $this->get_client_ip();
         $this->sendMailIPUser($user, $ip);
         User::where('id', $user->id)->update(array('lastest_login' => date("Y-m-d H:i:s"), 'ip_lastlogin' => $ip));
         $login_history = new LoginHistory();
         $login_history->user_id = $user->id;
         $login_history->ip_address = $ip;
         $login_history->date = date("Y-m-d H:i:s");
         $login_history->save();
         if (Input::get('isAjax')) {
             echo 1;
             exit;
         } else {
             if (User::find($user->id)->hasRole('Admin')) {
                 return Redirect::to('admin');
             } else {
                 return Redirect::to('user/profile')->with('notice', "Welcome to EcoinsTrader. You can now start Trading.");
             }
             // change it to '/admin', '/dashboard' or something
         }
     } else {
         $user = new User();
         // Check if there was too many login attempts
         if (Confide::isThrottled($input)) {
             $err_msg = Lang::get('confide::confide.alerts.too_many_attempts');
         } elseif ($user->checkUserExists($input) and !$user->isConfirmed($input)) {
             $err_msg = Lang::get('confide::confide.alerts.not_confirmed');
         } else {
             $err_msg = Lang::get('confide::confide.alerts.wrong_credentials');
         }
         if (Input::get('isAjax')) {
             echo $err_msg;
             exit;
         } else {
             return Redirect::action('UserController@login')->withInput(Input::except('password'))->with('error', $err_msg);
         }
     }
 }