/**
  * Checks the user credentials
  *
  * @param array $credentials
  * @return boolan
  */
 public function check($credentials)
 {
     // Check if the user exist
     $user = Feusers::findFirstByUsername($credentials['username']);
     if ($user == false) {
         $this->registerUserThrottling(0);
         throw new Exception('Wrong email/password combination');
     }
     // Check the password
     //$this->security->checkHash($credentials['password'], $user->password)
     if ($this->checkPassword($user->password, $credentials['password'])) {
         $this->_registerSession($user);
         $this->flashSession->success(controllerBase::translate('welcome') . ' ' . $user->username);
         //Forward to the 'invoices' controller if the user is valid
         // Check if the user was flagged
         $this->checkUserFlags($user);
         // Register the successful login
         $this->saveSuccessLogin($user);
         // Check if the remember me was selected
         if (isset($credentials['remember'])) {
             $this->createRememberEnviroment($user);
         }
         $this->response->redirect("");
         $this->view->disable();
     } else {
         $this->registerUserThrottling($user->uid);
         $this->flash->error('Wrong email/password');
         //throw new Exception('Wrong email/password combination');
     }
 }
 public function initialize($entity = null, $options = null)
 {
     // In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $uid = new Hidden('uid');
     } else {
         $uid = new Text('uid');
     }
     $this->add($uid);
     $username = new Text('username', array());
     $username->addValidators(array(new PresenceOf(array('message' => 'The name is required'))));
     $this->add($username);
     $password = new Password('password', array());
     $password->addValidators(array(new PresenceOf(array('message' => 'Password is required'))));
     $this->add($password);
     $last_name = new Text('last_name', array());
     $last_name->addValidators(array(new PresenceOf(array('message' => 'The lastname is required'))));
     $this->add($last_name);
     $first_name = new Text('first_name', array());
     $first_name->addValidators(array(new PresenceOf(array('message' => 'The firstname is required'))));
     $this->add($first_name);
     $title = new Text('title', array());
     $title->addValidators(array(new PresenceOf(array('message' => 'The title is required'))));
     $this->add($title);
     $email = new Text('email', array());
     $email->addValidators(array(new PresenceOf(array('message' => 'The email is required')), new Email(array('message' => 'The email is not valid'))));
     $this->add($email);
     $phone = new Text('phone', array());
     $this->add($phone);
     $address = new Text('address', array());
     $this->add($address);
     $city = new Text('city', array());
     $this->add($city);
     $zip = new Text('zip', array());
     $this->add($zip);
     $company = new Text('company', array());
     $this->add($company);
     $this->add(new Select("profileuid", Profiles::find(array('conditions' => 'deleted=0 AND hidden=0')), array('using' => array('uid', 'title'))));
     $this->add(new Select("usergroup", Usergroups::find(array('conditions' => 'deleted=0 AND hidden=0')), array('using' => array('uid', 'title'))));
     $this->add(new Select("userlanguage", Languages::find(array('conditions' => 'deleted=0 AND hidden=0')), array('using' => array('uid', 'title'))));
     $this->add(new Select('superuser', array('0' => ControllerBase::translate('no'), '1' => ControllerBase::translate('yes'))));
 }
 public function initialize()
 {
     $this->_loginForm = new LoginForm();
     Tag::setTitle('Sign Up/Sign In');
     parent::initialize();
 }