示例#1
0
 /**
  * Creates a new user account.
  *
  * @param string $email          User's email address
  * @param string $password       User's desired password
  * @param string $repeatPassword User's desired password, repeated to prevent typos
  *
  * @throws Exception
  */
 public function register($email, $password, $repeatPassword)
 {
     if (!Configuration::REGISTRATION_ENABLED) {
         throw new \Exception('registration_disabled');
     }
     if ($this->isAuthenticated()) {
         // User is already authenticated
         throw new \Exception('already_authenticated');
     }
     // Validate email address
     Model\User::validateEmail($email);
     // Validate password
     Model\User::validatePassword($password);
     // Validate password strength
     Model\User::validatePasswordStrength($password);
     if ($password !== $repeatPassword) {
         // Password and password confirmation do not match
         throw new \Exception('password_no_match');
     }
     $user = $this->database->getUserByEmail($email);
     if ($user) {
         // User with this email address already exists
         throw new \Exception('email_used');
     }
     if (Configuration::ACCOUNT_ACTIVATION_REQUIRED) {
         // Create new user
         $user = Model\User::createUser($email, $password, false);
         // Account activation is required, send activation email
         $this->sendActivationEmail($email);
     } else {
         // Create new user
         $user = Model\User::createUser($email, $password, true);
     }
     // Add user to database
     $this->database->addUser($user);
 }