public function actionCreate() { $this->inputData['password'] = Security\Passwords::hash($this->inputData['password']); $this->inputData['role'] = self::$roles[0]; if (isset($this->inputData['phone'])) { self::normalizePhone($this->inputData['phone']); } parent::actionCreate(); }
/** * Performs an authentication. * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->db->table(static::TABLE_NAME)->where(static::COLUMN_EMAIL, $username)->fetch(); if (!$row) { throw new Security\AuthenticationException('User not found.', self::IDENTITY_NOT_FOUND); } if (!Passwords::verify($password, $row[static::COLUMN_PASSWORD_HASH])) { throw new Security\AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL); } if (Passwords::needsRehash($row[static::COLUMN_PASSWORD_HASH])) { $row->update(array(static::COLUMN_PASSWORD_HASH => Passwords::hash($password))); } $arr = $row->toArray(); unset($arr[static::COLUMN_ID], $arr[static::COLUMN_PASSWORD_HASH], $arr[static::COLUMN_ROLE]); return new Security\Identity($row[static::COLUMN_ID], $this->getEffectiveRoles($row[static::COLUMN_ROLE]), $arr); }