private function runGet() { $request = Yii::$app->getRequest(); $model = DynamicModel::validateData(['id' => $request->get('id'), 'screen_name' => $request->get('screen_name'), 'count' => $request->get('count'), 'newer_than' => $request->get('newer_than'), 'older_than' => $request->get('older_than')], [[['id'], 'exist', 'targetClass' => Battle::className(), 'targetAttribute' => 'id'], [['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['newer_than', 'older_than'], 'integer'], [['count'], 'default', 'value' => 10], [['count'], 'integer', 'min' => 1, 'max' => 100]]); if (!$model->validate()) { return $this->formatError($model->getErrors(), 400); } $query = Battle::find()->innerJoinWith('user')->with(['user', 'user.userStat', 'lobby', 'rule', 'map', 'weapon', 'weapon.subweapon', 'weapon.special', 'rank', 'battleImageResult', 'battleImageJudge'])->orderBy('{{battle}}.[[id]] DESC')->limit((int) $model->count); if ($model->id != '') { $query->andWhere(['{{battle}}.[[id]]' => $model->id]); } if ($model->screen_name != '') { $query->andWhere(['{{user}}.[[screen_name]]' => $model->screen_name]); } if ($model->newer_than > 0) { $query->andWhere(['>', '{{battle}}.[[id]]', $model->newer_than]); } if ($model->older_than > 0) { $query->andWhere(['<', '{{battle}}.[[id]]', $model->older_than]); } $list = $query->all(); if ($model->id != '') { return empty($list) ? null : $this->runGetImpl(array_shift($list)); } $resp = Yii::$app->getResponse(); $resp->format = 'json'; return array_map(function ($model) { return $model->toJsonArray(); }, $list); }
/** * @inheritdoc */ public function rules() { return [[['follower_id', 'following_id'], 'required'], [['follower_id', 'following_id', 'create_date'], 'integer'], [['follower_id'], 'compare', 'compareAttribute' => 'following_id', 'operator' => '!='], [['following_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['following_id' => 'id']], [['follower_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['follower_id' => 'id']], [['follower_id'], function ($attribute, $params) { $count = self::find()->where(self::tableName() . '.following_id = :attr1 OR ' . self::tableName() . '.follower_id = :attr2')->orWhere(self::tableName() . '.following_id = :attr2 OR ' . self::tableName() . '.follower_id = :attr1')->params([':attr1' => $this->{$attribute}, ':attr2' => $this->following_id])->count(); return $count == 0; }]]; }
public function rules() { $rules = [[['screen_name', 'password', 'password_repeat'], 'required'], [['screen_name'], 'string', 'max' => 15], [['screen_name'], 'match', 'pattern' => '/^[a-zA-Z0-9_]{1,15}$/', 'message' => '{attribute} must be at most 15 alphanumeric or underscore characters.'], [['screen_name'], 'unique', 'targetClass' => User::className(), 'message' => Yii::t('app', 'This {attribute} is already in use.')], [['name'], 'string', 'max' => 15], [['password_repeat'], 'compare', 'compareAttribute' => 'password', 'operator' => '===']]; if (Yii::$app->params['googleRecaptcha']['siteKey'] != '') { $rules[] = [['recaptcha_token', 'recaptcha_response'], 'required', 'message' => Yii::t('app', 'Please check the reCAPTCHA.')]; $rules[] = [[], ReCaptchaValidator::className(), 'secret' => Yii::$app->params['googleRecaptcha']['secret']]; } return $rules; }
public function rules() { $rules = [[['screen_name', 'password'], 'required'], [['screen_name'], 'string', 'max' => 15], [['screen_name'], 'match', 'pattern' => '/^[a-zA-Z0-9_]{1,15}$/', 'message' => 'ログイン名は英数とアンダーバーの15文字以内で決めてください'], [['screen_name'], 'unique', 'targetClass' => User::className(), 'message' => 'このログイン名は既に使用されています'], [['name'], 'string', 'max' => 15]]; if (Yii::$app->params['googleRecaptcha']['siteKey'] != '') { $rules[] = [['recaptcha_token', 'recaptcha_response'], 'required', 'message' => 'reCAPTCHAの確認をしてください']; $rules[] = [[], ReCaptchaValidator::className(), 'secret' => Yii::$app->params['googleRecaptcha']['secret']]; } return $rules; }
/** * @param $id * @return void|array * @throws \Exception */ public function actionDelete($id) { //TODO: Check rights if (!User::find()->where(['id' => $id])->limit(1)->one()->delete()) { \Yii::$app->response->setStatusCode(404); return ErrorMessage::ModelNotFound(User::className(), $id); } \Yii::$app->response->setStatusCode(204); }
/** * Delete user action. * @param integer $id user id * @since 0.2 */ public function actionDelete($id) { /** @var $user UserModel */ $user = $this->findModel(UserModel::className(), $id); if ($user->delete()) { $this->addFlash(self::FLASH_SUCCESS, Yii::t('app', 'User <b>{name}</b> deleted.', ['name' => Html::encode($user->name)])); } return $this->redirect(['index']); }
public function actionCreate() { /** @var User $user */ $user = \Yii::createObject(['class' => User::className(), 'scenario' => 'create']); $this->performAjaxValidation($user); if ($user->load(\Yii::$app->request->post()) && $user->create()) { \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been created')); return $this->redirect(['update', 'id' => $user->id]); } return $this->render('create', ['user' => $user]); }
public function rules() { return [[['apikey'], 'required'], [['apikey'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'api_key'], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key'], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key'], [['rank', 'rank_after'], 'exist', 'targetClass' => Rank::className(), 'targetAttribute' => 'key'], [['rank_exp', 'rank_exp_after'], 'integer', 'min' => 0, 'max' => 99], [['level', 'level_after'], 'integer', 'min' => 1, 'max' => 50], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['cash', 'cash_after'], 'integer', 'min' => 0, 'max' => 9999999], [['rank_in_team'], 'integer', 'min' => 1, 'max' => 4], [['kill', 'death'], 'integer', 'min' => 0], [['death_reasons'], 'validateDeathReasons'], [['fest_gender'], 'in', 'range' => ['boy', 'girl']], [['fest_rank'], 'filter', 'filter' => 'strtolower'], [['fest_rank'], 'exist', 'targetClass' => FestTitle::className(), 'targetAttribute' => 'key'], [['my_team_color', 'his_team_color'], 'validateTeamColor'], [['image_judge', 'image_result'], 'safe'], [['image_judge', 'image_result'], 'file', 'maxSize' => 3 * 1024 * 1024, 'when' => function ($model, $attr) { return !is_string($model->{$attr}); }], [['image_judge', 'image_result'], 'validateImageFile', 'when' => function ($model, $attr) { return !is_string($model->{$attr}); }], [['image_judge', 'image_result'], 'validateImageString', 'when' => function ($model, $attr) { return is_string($model->{$attr}); }], [['start_at', 'end_at'], 'integer'], [['agent'], 'string', 'max' => 64], [['agent_version'], 'string', 'max' => 255], [['agent', 'agent_version'], 'required', 'when' => function ($model, $attr) { return (string) $this->agent !== '' || (string) $this->agent_version !== ''; }], [['my_point'], 'integer', 'min' => 0], [['my_team_final_point', 'his_team_final_point'], 'integer', 'min' => 0], [['my_team_final_percent', 'his_team_final_percent'], 'number', 'min' => 0.0, 'max' => 100.0], [['knock_out'], 'boolean', 'trueValue' => 'yes', 'falseValue' => 'no'], [['my_team_count', 'his_team_count'], 'integer', 'min' => 0, 'max' => 100], [['lobby'], 'fixLobby']]; }
public function rules() { return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () { return substr($this->rule, 0, 1) !== '@'; }], [['rule'], 'validateGameMode', 'when' => function () { return substr($this->rule, 0, 1) === '@'; }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () { return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true); }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '@'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '+'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '*'; }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['term'], 'in', 'range' => ['this-period', 'last-period', '24h', 'today', 'yesterday', 'term']], [['term_from', 'term_to'], 'date', 'format' => 'yyyy-M-d H:m:s']]; }
public function rules() { return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () { return substr($this->rule, 0, 1) !== '@'; }], [['rule'], 'validateGameMode', 'when' => function () { return substr($this->rule, 0, 1) === '@'; }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () { return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true); }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '@'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '+'; }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () { return substr($this->weapon, 0, 1) === '*'; }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose']]; }
/** * Action change user password. * @return string|\yii\web\Response * @throws \yii\web\NotFoundHttpException * @author Alex Makhorin */ public function actionChangePassword() { /** @var User $model */ $model = $this->findModel(User::className(), Yii::$app->user->identity->getId()); $passwordForm = new PasswordForm(); if ($passwordForm->load(Yii::$app->request->post())) { $passwordForm->userId = Yii::$app->user->identity->getId(); if ($passwordForm->validate()) { $model->password = $passwordForm->new; if ($model->save(false)) { Yii::$app->getSession()->setFlash('success', ['body' => Yii::t('app', 'Password changed')]); return $this->redirect(['profile']); } else { Yii::$app->getSession()->setFlash('danger', ['body' => Yii::t('app', 'Password not changed')]); return $this->redirect(['profile']); } } } return $this->renderAjax('partials/_changePasswordModal', ['model' => $passwordForm]); }
public function rules() { return [[['apikey'], 'required'], [['apikey'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'api_key'], [['test'], 'in', 'range' => ['validate', 'dry_run']], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key'], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key'], [['rank', 'rank_after'], 'exist', 'targetClass' => Rank::className(), 'targetAttribute' => 'key'], [['rank_exp', 'rank_exp_after'], 'integer', 'min' => 0, 'max' => 99], [['level', 'level_after'], 'integer', 'min' => 1, 'max' => 50], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['cash', 'cash_after'], 'integer', 'min' => 0, 'max' => 9999999], [['rank_in_team'], 'integer', 'min' => 1, 'max' => 4], [['kill', 'death'], 'integer', 'min' => 0], [['death_reasons'], 'validateDeathReasons'], [['gender'], 'in', 'range' => ['boy', 'girl']], [['fest_title', 'fest_title_after'], 'filter', 'filter' => 'strtolower'], [['fest_title', 'fest_title_after'], 'filter', 'filter' => function ($a) { switch ($a) { case 'campion': return 'champion'; case 'friend': return 'fiend'; default: return $a; } }], [['fest_title', 'fest_title_after'], 'exist', 'targetClass' => FestTitle::className(), 'targetAttribute' => 'key'], [['fest_exp', 'fest_exp_after'], 'integer', 'min' => 0, 'max' => 99], [['my_team_color', 'his_team_color'], 'validateTeamColor'], [['image_judge', 'image_result'], 'safe'], [['image_judge', 'image_result'], 'file', 'maxSize' => 3 * 1024 * 1024, 'when' => function ($model, $attr) { return !is_string($model->{$attr}); }], [['image_judge', 'image_result'], 'validateImageFile', 'when' => function ($model, $attr) { return !is_string($model->{$attr}); }], [['image_judge', 'image_result'], 'validateImageString', 'when' => function ($model, $attr) { return is_string($model->{$attr}); }], [['start_at', 'end_at'], 'integer'], [['agent'], 'string', 'max' => 64], [['agent_version'], 'string', 'max' => 255], [['agent', 'agent_version'], 'required', 'when' => function ($model, $attr) { return (string) $this->agent !== '' || (string) $this->agent_version !== ''; }], [['agent_custom'], 'string'], [['agent', 'agent_version', 'agent_custom'], 'validateStrictUTF8'], [['automated'], 'boolean', 'trueValue' => 'yes', 'falseValue' => 'no'], [['automated'], 'estimateAutomatedAgent', 'skipOnEmpty' => false], [['my_point'], 'integer', 'min' => 0], [['my_team_final_point', 'his_team_final_point'], 'integer', 'min' => 0], [['my_team_final_percent', 'his_team_final_percent'], 'number', 'min' => 0.0, 'max' => 100.0], [['knock_out'], 'boolean', 'trueValue' => 'yes', 'falseValue' => 'no'], [['my_team_count', 'his_team_count'], 'integer', 'min' => 0, 'max' => 100], [['players'], 'validatePlayers'], [['gears'], 'validateGears'], [['events'], 'validateEvents']]; }
/** * * * @return mixed */ public function getUsers() { return $this->hasOne(User::className(), ['tocken' => 'tocken']); }
/** * @inheritdoc */ public function rules() { return [['name', 'required'], ['name', 'filter', 'filter' => 'trim'], ['name', 'string', 'min' => 2, 'max' => 255], ['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'unique', 'targetClass' => User::className(), 'message' => __('This email address has already been taken.')], ['password', 'required'], ['password', 'string', 'min' => static::PASS_MIN_LEN]]; }
public function actions() { return array_merge(parent::actions(), ['editable' => ['class' => EditableAction::className(), 'modelClass' => User::className(), 'forceCreate' => false]]); }
public function getLastReply() { return $this->hasOne(User::className(), ['id' => 'reply_id'])->select(['id', 'username']); }
/** * @inheritdoc */ public function rules() { return [['name', 'filter', 'filter' => 'trim'], ['name', 'required'], ['name', 'string', 'min' => 2, 'max' => 255], ['name', 'unique', 'targetClass' => User::className(), 'message' => 'The name has already been taken.'], ['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'string', 'max' => 255], ['email', 'unique', 'targetClass' => User::className(), 'message' => 'This email address has already been taken.'], ['password', 'required'], ['password', 'compare'], ['password', 'string', 'min' => 6, 'max' => 64], ['password_repeat', 'required'], ['status', 'default', 'value' => User::STATUS_ENABLED], ['status', 'integer'], ['status', 'in', 'range' => [User::STATUS_DISABLED, User::STATUS_ENABLED, User::STATUS_PENDING]], ['sendmail', 'boolean', 'on' => ['admin']], ['sendmail', 'default', 'value' => false, 'on' => ['admin']]]; }
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); }
/** * @return \yii\db\ActiveQuery */ public function getUsers0() { return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('vote', ['election_id' => 'id']); }
public function getSource() { return $this->hasOne(User::className(), ['id' => 'source_id'])->select(['id', 'username', 'avatar']); }
/** * @return \yii\db\ActiveQuery */ public function getUdatedBy() { return $this->hasOne(User::className(), ['id' => 'udated_by']); }
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['state_id' => 'id']); }
public function rules() { return [['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'exist', 'targetClass' => User::className(), 'filter' => ['status' => User::STATUS_ACTIVE], 'message' => 'Данный email не зарегистрирован в системе']]; }
/** @inheritdoc */ public function init() { $this->user = \Yii::createObject(['class' => User::className(), 'scenario' => 'register']); $this->module = \Yii::$app->getModule('user'); }
public function rules() { return [[['login', 'email', 'password', 'confirm'], 'required', 'message' => 'Введите {attribute}'], [['login', 'email', 'password', 'confirm'], 'string', 'max' => 100, 'tooLong' => '{attribute} не может быть более 100 символов'], [['email'], 'email', 'message' => 'Некорректный Email'], [['avatar'], 'image', 'mimeTypes' => 'image/jpg, image/png, image/jpeg, image/bmp', 'notImage' => 'Файл должен быть картинкой', 'wrongMimeType' => 'Изображение должно быть в формате: png/jpg/bmp ', 'maxSize' => 524288, 'tooBig' => 'Файл должен быть не более 500кБ'], [['confirm'], 'compare', 'compareAttribute' => 'password'], [['login', 'email'], 'unique', 'targetClass' => User::className(), 'message' => 'Этот {attribute} уже занят']]; }
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('network_has_user', ['network_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getCreatedBy() { return $this->hasOne(User::className(), ['user_id' => 'created_by']); }
/** * @return \yii\db\ActiveQuery */ public function getReceiver0() { return $this->hasOne(User::className(), ['id' => 'receiver']); }
public function rules() { return [['username', 'filter', 'filter' => 'trim'], ['username', 'required'], ['username', 'match', 'pattern' => '#^[\\w_-]+$#i'], ['username', 'unique', 'targetClass' => User::className(), 'message' => 'This username has already been taken.'], ['username', 'string', 'min' => 2, 'max' => 255], ['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'unique', 'targetClass' => User::className(), 'message' => 'This email address has already been taken.'], ['password', 'required'], ['password', 'string', 'min' => 6], ['verifyCode', 'captcha', 'captchaAction' => '/user/default/captcha']]; }
/** * @inheritdoc */ public function run($id = null, $tab = 'account') { if (Yii::$app->user->isGuest) { return $this->controller->redirect(['user/login']); } if ($id === null) { $user = Yii::$app->user->getIdentity(); } elseif (Yii::$app->user->can('updateAnyUser')) { $user = $this->controller->findModel(User::className(), $id); } else { throw new \yii\web\ForbiddenHttpException(); } $model = new $this->modelClass($user); if (Yii::$app->request->isPost) { if (Yii::$app->user->can('updateAnyUser')) { $model->setScenario('admin'); } if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->controller->addFlash(Controller::FLASH_INFO, Yii::t('app', 'Changes has saved.')); $model->reset(); } } if (!Yii::$app->request->isPjax && Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } return $this->render(['model' => $model, 'tab' => $tab]); }