Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login($username = NULL, $password = NULL, $remember = FALSE)
- {
- if(!$username && !$password && $this->exists())
- {
- Session::put($this->_sessionName, $this->data()->id);
- }
- else
- {
- $user = $this->find($username);
- if($user)
- {
- if($this->data()->password === Hash::make($password, $this->data()->salt))
- {
- Session::put($this->_sessionName, $this->data()->id);
- if($remember)
- {
- $hash = Hash::unique();
- $hashCheck = $this->_db->get('users_session',array('user_id','=',$this->data()->id));
- if(!$hashCheck->count())
- {
- $this->_db->insert('users_session', array(
- 'user_id' => $this->data()->id,
- 'hash' => $hash
- ));
- }
- else
- {
- $hash = $hashCheck->first()->hash;
- }
- Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
- }
- return true;
- }
- }
- }
- return false;
- }
- if(Input::exists())
- {
- if(Token::check(Input::get('token')))
- {
- $validation = new Validate();
- $validation = $validation->check($_POST, array(
- 'username' => array('required' => true),
- 'password' => array('required' => true)
- ));
- if($validation->passed())
- {
- $user = new User();
- $remember = (Input::get('remember') === 'on') ? true : false;
- $login = $user->login(Input::get('username'), Input::get('password'), $remember);
- if($login)
- {
- Redirect::to('user.php?user='.Input::get("username").'');
- }
- else
- {
- echo '<p>Sorry! Logging in failed</p>';
- }
- }
- else
- {
- foreach($validation->errors() as $error)
- {
- echo $error, '</br>';
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment