Esempio n. 1
0
 public function login($usernameOrEmail = null, $password = null, $remember = false)
 {
     if (!$this->isLoggedIn()) {
         $user = $this->search($usernameOrEmail);
         if ($user) {
             if (Password::verify($password, $this->data()->Password)) {
                 // password is correct start a user session
                 $this->startSession();
                 if ($remember) {
                     $hash = Token::create(46);
                     $hashCheck = $this->db->select(array('User_ID'), $this->sessions, null, array(array('User_ID', '=', $this->data()->ID)), array('LIMIT' => 1));
                     if (!$hashCheck->count()) {
                         $this->db->insert($this->sessions, array('User_ID' => $this->data()->ID, 'Token' => $hash));
                     }
                     Cookie::set($this->cookieName, $hash, $this->cookieExpiry);
                 }
                 return true;
             }
         }
     }
     return false;
 }
 public function create()
 {
     if (Input::exists()) {
         $username = Input::get('username');
         $password = Input::get('password');
         $org = Input::get('org');
         $email = Input::get('email');
         $role = Input::get('user_type');
         $validate = Validator::load(DB::load());
         $validation = $validate->checkPost($_POST, array('username' => array('required' => true, 'min' => 3, 'max' => 32, 'notTaken' => 'Users'), 'full_name' => array('required' => true, 'min' => 3, 'max' => 50), 'password' => array('required' => true, 'min' => 3, 'max' => 32, 'validPass' => $password), 'email' => array('required' => true, 'min' => 3, 'max' => 32, 'validEmail' => $email)));
         if ($validation->passed()) {
             DB::load()->insert('Users', array('Created' => time(), 'Username' => $username, 'Password' => Password::hash($password), 'Email' => $email, 'Name' => Input::get('full_name'), 'Org' => $org, 'Role_ID' => $role, 'Status_ID' => 2, 'Auth_token' => Token::create(46)));
             Session::set('SUCCESS', I18n::get('AUTH_CREATE_SUCCESS'));
             Redirect::to($this->data['project_url'] . 'login#form');
         } else {
             // gather the errorrs and echo them out
             foreach ($validation->errors() as $error) {
                 $_SESSION['ERRORS'][] = $error;
             }
             Redirect::to($this->data['project_url'] . 'login#form');
         }
     }
 }