/** * Sets login for the user. It could be set if it fits the format, user isn't a guest, * and there is no user with the same login. * * @param new user login * @return null * @throws UserException in case of errors */ public function setLogin($new_login) { if (!PasswordAuth::checkLoginFormat($new_login)) { throw new UserException("Incorrect login parameter"); } if ($this->id == self::GUEST) { throw new UserException("Cannot change login for guest user. Use User::add instead"); } if (self::findBy("login", $new_login) !== null) { throw new UserException("User with login '{$new_login}' already exists"); } $this->login = $new_login; }