/** * Authenticates a user. * @return boolean whether authentication succeeds. */ public function authenticate() { $model = UserGroupsUser::model()->findByAttributes(array('username' => $this->username)); //Тупая битриксовская проверка пароля. if ($model && $model->is_bitrix_pass) { if (strlen($model->password) > 32) { $salt = substr($model->password, 0, strlen($model->password) - 32); $db_password = substr($model->password, -32); } else { $salt = ""; $db_password = $model->password; } $user_password = md5($salt . $this->password); //echo $salt.'<br/>'.$user_password.'<br/>'.$db_password; //die(); } elseif ($model && !$model->is_bitrix_pass) { $user_password = md5($this->password . $model->getSalt()); $db_password = $model->password; } if (!count($model)) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_ACTIVATION) { $this->errorCode = self::ERROR_USER_INACTIVE; } else { if (!$this->hash && $user_password !== $db_password || $this->hash && $model->password != $this->hash) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::PASSWORD_CHANGE_REQUEST) { $this->errorCode = self::ERROR_PASSWORD_REQUESTED; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = $model->username; $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home ? $model->home : $model->relUserGroupsGroup->home; $this->recovery = false; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); // run the cronjobs if (UserGroupsConfiguration::findRule('server_executed_crons') === false) { UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); if (Yii::app()->controller->module) { foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } } UGCron::run(); } $model->save(); } } } } } } return !$this->errorCode; }
/** * Authenticates a user based on {@link username}. * This method is required by {@link IUserIdentity}. * @return boolean whether authentication succeeds. */ public function authenticate() { if ($this->service && $this->service->isAuthenticated) { $this->username = $this->service->serviceName . '#' . $this->service->id; $this->setState('name', $this->username); $this->setState('service', $this->service->serviceName); $this->errorCode = self::ERROR_NONE; $model = UserGroupsUser::model()->findByAttributes(array('xml_id' => $this->service->id, 'external_auth_id' => $this->service->getAttribute('external_auth_id') ? $this->service->getAttribute('external_auth_id') : $this->service->serviceName)); if (!$model) { $model = new UserGroupsUser(); $model->username = $this->username; $model->email = $this->service->getAttribute('email'); if (!$model->email && $this->service->serviceName == 'yandex') { $model->email = $this->service->getAttribute('name') . '@yandex.ru'; } $model->name = $this->service->getAttribute('name'); $model->last_name = $this->service->getAttribute('lastname'); $model->group_id = 2; $model->status = 4; $model->params = array_keys($model->ParamsFields); $model->xml_id = $this->service->id; $model->external_auth_id = $this->service->getAttribute('external_auth_id') ? $this->service->getAttribute('external_auth_id') : $this->service->serviceName; $model->save(); } if (!$model) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_ACTIVATION) { $this->errorCode = self::ERROR_USER_INACTIVE; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::PASSWORD_CHANGE_REQUEST) { $this->errorCode = self::ERROR_PASSWORD_REQUESTED; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = $model->username; $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home ? $model->home : $model->relUserGroupsGroup->home; $this->recovery = false; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); // run the cronjobs if (UserGroupsConfiguration::findRule('server_executed_crons') === false) { UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } UGCron::run(); } $model->save(); } } } } } } else { $this->errorCode = self::ERROR_NOT_AUTHENTICATED; } return !$this->errorCode; }
/** * this action executes every single cron */ public function actionCron() { if (UserGroupsConfiguration::findRule('server_executed_crons') !== true) { return; } UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } UGCron::run(); }
/** * Authenticates a user. * @return boolean whether authentication succeeds. */ public function authenticate() { $model = UserGroupsUser::model()->findByAttributes(array('username' => $this->username)); if (!count($model)) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_ACTIVATION) { $this->errorCode = self::ERROR_USER_INACTIVE; } else { if ($model->password !== md5($this->password . $model->getSalt())) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::PASSWORD_CHANGE_REQUEST) { $this->errorCode = self::ERROR_PASSWORD_REQUESTED; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = $model->username; $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home ? $model->home : $model->relUserGroupsGroup->home; $this->recovery = false; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); // run the cronjobs if (UserGroupsConfiguration::findRule('server_executed_crons') === false) { UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } UGCron::run(); } $model->save(); } } } } } } return !$this->errorCode; }