コード例 #1
0
ファイル: UserIdentity.php プロジェクト: syxoasis/wakfu-sae
 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
ファイル: AdminIdentity.php プロジェクト: syxoasis/wakfu-sae
 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;
 }