示例#1
0
 public function authenticate()
 {
     $user = User::model()->with('service')->find('username=:u', ['u' => $this->username]);
     $verifyPassword = false;
     if (empty($user)) {
         $state = 1;
     } else {
         $verifyPassword = CPasswordHelper::verifyPassword($this->password, $user->password);
         $state = $verifyPassword ? 0 : 1;
     }
     $result = Fraudmetrix::login($this->username, $state);
     if ($result['success'] == true && $result['final_decision'] == 'Reject') {
         $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
         $this->errorMessage = '未知错误';
     } else {
         if (empty($user)) {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
             $this->errorMessage = '用户邮箱不存在';
         } else {
             if ($user->state == 1) {
                 $this->errorCode = self::ERROR_NOT_LOGIN;
                 $this->errorMessage = '登录账号已被锁定';
             } elseif (!$verifyPassword) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
                 $this->errorMessage = '用户密码错误';
             } else {
                 $server = Setting::model()->get('wakfu', 'server');
                 $this->errorCode = self::ERROR_NONE;
                 $this->setPersistentStates(array_merge($user->getAttributes(), ['last_login_time' => $user->last_login_time, 'last_login_ip' => $user->last_login_ip, 'sign_up_time' => $user->sign_up_time, 'sign_up_ip' => $user->sign_up_ip, 'server' => $server[$user->service->server], 'port' => $user->service->port]));
                 $this->afterLogin($user);
             }
         }
     }
     return !$this->errorCode;
 }
示例#2
0
 public function authenticate()
 {
     $admin = User::model()->with('userRoles', 'userGroups')->find('`t`.`username`=:u', ['u' => $this->username]);
     $verifyPassword = false;
     if (empty($admin) || $admin->state != 2) {
         $state = 1;
     } else {
         $verifyPassword = CPasswordHelper::verifyPassword($this->password, $admin->password);
         $state = $verifyPassword ? 0 : 1;
     }
     $result = Fraudmetrix::login($this->username, $state);
     if ($result['success'] == true && $result['final_decision'] == 'Reject') {
         $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
         $this->errorMessage = '未知错误';
     } else {
         if (empty($admin) || $admin->state != 2) {
             // 普通用户不允许登录管理系统
             $this->errorCode = self::ERROR_USERNAME_INVALID;
             $this->errorMessage = '用户名不存在';
         } else {
             if (!$verifyPassword) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
                 $this->errorMessage = '用户密码错误';
             } else {
                 $this->errorCode = self::ERROR_NONE;
                 $role = [];
                 foreach ($admin->getRelated('userRoles') as $item) {
                     $r = $item->getRelated('role');
                     if ($r) {
                         $role[] = $r->name;
                     }
                 }
                 $group = [];
                 foreach ($admin->getRelated('userGroups') as $item) {
                     $g = $item->getRelated('group');
                     if ($g) {
                         $group[] = $g->name;
                     }
                 }
                 $this->setPersistentStates(array_merge($admin->getAttributes(), array('last_login_time' => $admin->last_login_time, 'last_login_ip' => $admin->last_login_ip, 'sign_up_time' => $admin->sign_up_time, 'sign_up_ip' => $admin->sign_up_ip, 'role' => $role, 'group' => $group)));
                 $this->afterLogin($admin);
             }
         }
     }
     return !$this->errorCode;
 }
示例#3
0
 public function save()
 {
     $app = Yii::app();
     $transaction = $app->db->beginTransaction();
     try {
         if ($this->validate() == false) {
             throw new CDbException('参数出错', 0, []);
         }
         preg_match('/^(.*)@/', $this->username, $match);
         $password = CPasswordHelper::hashPassword($this->password);
         $result = Fraudmetrix::register($this->username, $this->username, $password);
         if ($result['success'] == true && $result['final_decision'] == 'Reject') {
             throw new CDbException('注册用户失败', 100, []);
         }
         $user = new User();
         $user->attributes = ['username' => $this->username, 'realname' => isset($match[1]) ? $match[1] : '无', 'nickname' => isset($match[1]) ? $match[1] : '无', 'email' => $this->username, 'password' => $password, 'sign_up_time' => time(), 'sign_up_ip' => Yii::app()->request->getUserHostAddress(), 'approved' => 5, 'state' => 0];
         if ($user->save() === false) {
             throw new CDbException('注册用户失败', 10, $user->getErrors());
         }
         $user->uuid = $app->getSecurityManager()->generateUUID($user->id . $user->password);
         if ($user->save() === false) {
             throw new CDbException('注册用户失败', 10, $user->getErrors());
         }
         //写入service
         $service = new Service();
         $service->attributes = ['uid' => $user->id, 'email' => $user->username, 'status' => 1, 'traffic' => 100 * 100];
         if ($service->save()) {
             Queue::apiCreate($user->id);
         }
         $transaction->commit();
     } catch (CDbException $e) {
         $transaction->rollback();
         $this->addErrors($e->errorInfo);
         return false;
     }
     $email = $app->getComponent('email');
     if (!empty($email)) {
         $email->quickSend($this->username, '欢迎您注册夸父', "请妥善保管好您的登录密码:" . $this->password);
     }
     return true;
 }