Beispiel #1
0
 public function createUser(array $credential, $confirmed = null)
 {
     /* @var User $user */
     $user = new $this->userModel();
     if ($email = filter_var($login = $credential['login'], FILTER_VALIDATE_EMAIL)) {
         $user->setData('email', $email);
         $confirmed === null and $confirmed = !$this->options['register']['confirm_email'];
         $confirmed or $user->setData('confirmation_code', Text::token())->setData('confirm_method', 'sendConfirmationEmail');
     } elseif (I18n::checkMobile($login)) {
         $user->setData('mobile', $login);
         $confirmed === null and $confirmed = !$this->options['register']['confirm_mobile'];
         $confirmed or $user->setData('confirmation_code', mt_rand(100000, 999999))->setData('confirm_method', 'sendConfirmationSms');
     } else {
         throw new Exception(__($this->options['hints']['invalid_user_credential']));
     }
     $user->setData('password', $this->hasher->hash($credential['password']))->setData('confirmed', $confirmed)->generateDistributedId();
     if ($confirmed) {
         if (!$user->save()) {
             throw new Exception(__($this->options['hints']['unable_to_save_user']), 0, $user->getStringMessages());
         }
     } else {
         $this->pushPendingConfirmation($user, $credential);
     }
     return $user;
 }
Beispiel #2
0
 public function testCheckMobile()
 {
     $mobile = '13579246801';
     $this->assertTrue(I18n::checkMobile($mobile, 'CN'), 'Bad check mobile result');
 }