本文整理汇总了PHP中dektrium\user\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new SocialServiceManager model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new SocialServiceManager();
if ($model->load(Yii::$app->request->post())) {
$person = new Person();
$person->name = $model->name;
$person->lastname = $model->last_name;
$person->phone = $model->phone;
$person->save(false);
$user = new User();
$user->username = $model->username;
$user->password = $model->password;
$user->email = $model->email;
$user->person_id = $person->id;
$user->scenario = 'register';
if ($user->validate(['username', 'password'])) {
$user->register();
$model->user_id = $user->id;
$model->save(false);
//assign the role to the user
$authManager = Yii::$app->getAuthManager();
$socialServiceMRole = $authManager->getRole('socialServiceManager');
$authManager->assign($socialServiceMRole, $user->id);
//set the success message
Yii::$app->getSession()->setFlash('success', 'Usuario creado con éxito');
return $this->redirect(['view', 'id' => $model->id]);
} else {
$model->addErrors($user->errors);
}
}
return $this->render('create', ['model' => $model]);
}
示例2: loadAttributes
public function loadAttributes(User $user)
{
$user->setAttributes($this->attributes);
$profile = \Yii::createObject(Profile::className());
$profile->setAttributes(['name' => $this->name]);
$user->setProfile($profile);
}
示例3: loadAttributes
/**
* @inheritdoc
*/
protected function loadAttributes(\dektrium\user\models\User $user)
{
$user->setAttributes(['email' => $this->email, 'username' => $this->username, 'password' => $this->password]);
$profile = \Yii::createObject(Profile::className());
$profile->setAttributes(['name' => ucwords(strtolower($this->firstname)) . " " . ucwords(strtolower($this->lastname)), 'firstname' => ucwords(strtolower($this->firstname)), 'lastname' => ucwords(strtolower($this->lastname)), 'birthday' => $this->birthday, 'terms' => $this->terms]);
$user->setProfile($profile);
}
示例4: rules
/**
* @inheritdoc
*/
public function rules()
{
return [['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'exist', 'targetClass' => $this->module->manager->userClass, 'message' => \Yii::t('user', 'There is no user with such email.')], ['email', function ($attribute) {
$this->_user = $this->module->manager->findUserByEmail($this->email);
if ($this->_user !== null && $this->getModule()->enableConfirmation && !$this->_user->getIsConfirmed()) {
$this->addError($attribute, \Yii::t('user', 'You need to confirm your email address'));
}
}]];
}
示例5: rules
/** @inheritdoc */
public function rules()
{
return ['emailTrim' => ['email', 'filter', 'filter' => 'trim'], 'emailRequired' => ['email', 'required'], 'emailPattern' => ['email', 'email'], 'emailExist' => ['email', 'exist', 'targetClass' => $this->module->modelMap['User'], 'message' => \Yii::t('user', 'There is no user with this email address')], 'emailUnconfirmed' => ['email', function ($attribute) {
$this->user = $this->finder->findUserByEmail($this->email);
if ($this->user !== null && $this->module->enableConfirmation && !$this->user->getIsConfirmed()) {
$this->addError($attribute, \Yii::t('user', 'You need to confirm your email address'));
}
}], 'passwordRequired' => ['password', 'required'], 'passwordLength' => ['password', 'string', 'min' => 6]];
}
示例6: actionConnect
public function actionConnect($account_id)
{
//var_dump("connect");die;
$account = $this->finder->findAccountById($account_id);
if ($account === null || $account->getIsConnected()) {
throw new NotFoundHttpException();
}
/** @var User $user */
$user = \Yii::createObject(['class' => User::className(), 'scenario' => 'connect']);
if (\Yii::$app->request->get("provider") == 'kd') {
$data = array();
$data['User'] = array();
$data['User']['username'] = \Yii::$app->request->get("username");
$data['User']['email'] = \Yii::$app->request->get("email");
} else {
$data = \Yii::$app->request->post();
}
if ($user->load($data) && $user->create()) {
$account->user_id = $user->id;
$account->save(false);
\Yii::$app->user->login($user, $this->module->rememberFor);
return $this->goBack();
}
return $this->render('connect', ['model' => $user, 'account' => $account]);
}
示例7: safeDown
public function safeDown()
{
$controller = Yii::$app->controller;
$model = \Yii::createObject(LoginForm::className());
do {
if ($model->hasErrors()) {
$this->showErrors($model);
}
// get username
$username = $controller->prompt($controller->ansiFormat("\tUsername: ", \yii\helpers\Console::FG_BLUE));
// get password
echo $controller->ansiFormat("\tPassword: ", \yii\helpers\Console::FG_BLUE);
system('stty -echo');
$password = trim(fgets(STDIN));
system('stty echo');
echo "\n";
$model->login = $username;
$model->password = $password;
} while (!$model->validate());
$user = User::findOne(['username' => $username]);
if (empty($user)) {
throw new \yii\console\Exception("Unable to find user {$username}");
}
$this->delete('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $user->primaryKey]);
$user->delete();
}
示例8: checkUserSetup
private static function checkUserSetup()
{
if (UserModel::find()->where('id != 1')->count() == 0) {
$link = Html::a('user module', ['/user/admin/create']);
\Yii::$app->session->addFlash('warning', "There is no additional user registered, visit {$link} to create an editor.");
}
}
示例9: findModel
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例10: actionFollowings
public function actionFollowings($id)
{
$followings = FollowerUsertoUser::find()->where(['follower_user_id' => $id])->all();
$following_users_ids = ArrayHelper::getColumn($followings, 'followed_user_id');
$query = User::find()->where(['id' => $following_users_ids]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('index', ['models' => $models, 'caller' => $id, 'callerType' => 'Followings']);
}
示例11: login
/**
* Validates form and logs the user in.
*
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
if (Yii::$app->getUser()->login($this->user, $this->rememberMe ? $this->module->rememberFor : 0)) {
UserLog::log("login-success");
$this->user->last_login = gmdate("Y-m-d H:i:s");
$this->user->save();
return true;
} else {
return false;
}
} else {
$message = '';
foreach ($this->errors['login'] as $error) {
$message .= $error . "\n";
}
UserLog::log("login-failure", $message);
return false;
}
}
示例12: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'index' page.
*
* @return mixed
*/
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]);
}
示例13: register
/**
* Registers a new user account.
* @return bool
*/
public function register()
{
if (!$this->validate()) {
return false;
}
$this->user->setAttributes(['email' => $this->email, 'username' => $this->username, 'password' => $this->password]);
return $this->user->register();
}
示例14: rules
public function rules()
{
$rules = parent::rules();
// add some rules
$rules['vmlistLength'] = ['vmlist', 'string', 'max' => 255];
return $rules;
}
示例15: afterSave
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if ($insert) {
UcenterUtil::register($this->username, $this->password, $this->email);
}
}