/** * Validate user login * * @access public * @param array $values Form values * @return array $valid, $errors [0] = Success or not, [1] = List of errors */ public function validateLogin(array $values) { $v = new Validator($values, array(new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Required('password', t('The password is required')))); $result = $v->execute(); $errors = $v->getErrors(); if ($result) { list($authenticated, $method) = $this->authenticate($values['username'], $values['password']); if ($authenticated === true) { // Create the user session $user = $this->getByUsername($values['username']); $this->updateSession($user); // Update login history $lastLogin = new LastLogin($this->db, $this->event); $lastLogin->create($method, $user['id'], $this->getIpAddress(), $this->getUserAgent()); // Setup the remember me feature if (!empty($values['remember_me'])) { $rememberMe = new RememberMe($this->db, $this->event); $credentials = $rememberMe->create($user['id'], $this->getIpAddress(), $this->getUserAgent()); $rememberMe->writeCookie($credentials['token'], $credentials['sequence'], $credentials['expiration']); } } else { $result = false; $errors['login'] = t('Bad username or password'); } } return array($result, $errors); }