/** * Registers a new user account. If registration was successful it will set flash message. * * @return bool */ public function register() { if (!$this->validate()) { return false; } /** @var User $user */ $user = Yii::createObject(User::className()); $user->setScenario('register'); $this->loadAttributes($user); if (!$user->register()) { return false; } Yii::$app->session->setFlash('info', Yii::t('user', 'Your account has been created and a message with further instructions has been sent to your email')); return true; }
/** * Displays page where user can create new account that will be connected to social account. * * @param string $code * * @return string * @throws NotFoundHttpException */ public function actionConnect($code) { $account = $this->finder->findAccount()->byCode($code)->one(); if ($account === null || $account->getIsConnected()) { throw new NotFoundHttpException(); } /** @var User $user */ $user = Yii::createObject(['class' => User::className(), 'scenario' => 'connect', 'username' => $account->username, 'email' => $account->email]); if ($user->load(Yii::$app->request->post()) && $user->create()) { $account->connect($user); return $this->render('/message', ['title' => Yii::t('user', 'Your account has been created'), 'module' => $this->module]); // Yii::$app->user->login($user, $this->module->rememberFor); // return $this->goBack(); } return $this->render('connect', ['model' => $user, 'account' => $account]); }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $user = Yii::createObject(['class' => User::className(), 'scenario' => 'create']); if ($user->load(Yii::$app->request->post())) { /* $coordenadas = sysconfigs::getCoordinates($user->direccion); $user->latitud = $coordenadas['latitud']; $user->longitud = $coordenadas['longitud'];*/ //generamos password $user->password = $user->password == null ? Password::generate(8) : $user->password; if ($user->save()) { $user->mailer->sendWelcomeMessage($user, null); return $this->redirect(['update', 'id' => $user->id]); } else { return $this->render('create', ['user' => $user]); } } else { return $this->render('create', ['user' => $user]); } }
public function rules() { return [[['username', 'email', 'password'], 'filter', 'filter' => 'trim'], [['username', 'email', 'password'], 'required'], ['username', 'string', 'min' => 2, 'max' => 255], ['password', 'string', 'min' => 6, 'max' => 255], ['username', 'unique', 'targetClass' => User::className(), 'message' => 'Это имя уже занято.'], ['email', 'email'], ['email', 'unique', 'targetClass' => User::className(), 'message' => 'Эта почта уже занята.'], ['status', 'default', 'value' => User::STATUS_ACTIVE, 'on' => 'default'], ['status', 'in', 'range' => [User::STATUS_NOT_ACTIVE, User::STATUS_ACTIVE]]]; }
/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); }
public function getUser() { return $this->hasMany(User::className(), ['level_id' => 'level_id']); }
<?php use backend\models\User; $params = array_merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php'); return ['id' => 'app-backend', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\\controllers', 'aliases' => ['@file_view_dir' => '@backend/files'], 'bootstrap' => ['log'], 'modules' => [], 'components' => ['user' => ['identityClass' => User::className(), 'enableAutoLogin' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'errorHandler' => ['errorAction' => 'site/error']], 'params' => $params];
/** * @return \yii\db\ActiveQuery */ public function getAuthor() { return $this->hasOne(User::className(), ['id' => 'author_id']); }
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['role_id' => 'role_value']); }
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['attendee_id' => 'id']); }
public function getAddress() { return $this->hasOne(User::className(), ['id' => 'addressId']); }
/** * @return \yii\db\ActiveQuery */ public function getIdUsuario() { return $this->hasOne(User::className(), ['id' => 'id_usuario']); }
/** * @return \yii\db\ActiveQuery */ public function getCreatedBy() { return $this->hasOne(User::className(), ['id' => 'created_by']); }
/** * @return \yii\db\ActiveQuery */ public function getUsername0() { return $this->hasOne(User::className(), ['username' => 'username']); }
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('auth_assignment', ['item_name' => 'name']); }