本文整理汇总了PHP中dektrium\user\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]);
}
开发者ID:RomarioLopezC,项目名称:RobotSS,代码行数:37,代码来源:SocialServiceManagerController.php
示例2: loadAttributes
public function loadAttributes(User $user)
{
$user->setAttributes($this->attributes);
$profile = \Yii::createObject(Profile::className());
$profile->setAttributes(['name' => $this->name]);
$user->setProfile($profile);
}
开发者ID:Uthpala,项目名称:doingiteasychannel,代码行数:7,代码来源:RegistrationForm.php
示例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);
}
开发者ID:cinghie,项目名称:yii2-user-extended,代码行数:10,代码来源:RegistrationForm.php
示例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'));
}
}]];
}
开发者ID:ilyar,项目名称:dektrium-yii2-user,代码行数:12,代码来源:RecoveryRequestForm.php
示例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]];
}
开发者ID:manyoubaby123,项目名称:imshop,代码行数:10,代码来源:RecoveryForm.php
示例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]);
}
开发者ID:kd-brinex,项目名称:kd,代码行数:25,代码来源:RegistrationController.php
示例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();
}
开发者ID:hector-del-rio,项目名称:yii2-attache,代码行数:26,代码来源:m150805_191756_yii2user_add_admin_user.php
示例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.");
}
}
开发者ID:7flash,项目名称:app,代码行数:7,代码来源:Helper.php
示例9: findModel
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
开发者ID:kapilbhadke,项目名称:ConnectMe,代码行数:8,代码来源:ConnectMeUserController.php
示例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']);
}
开发者ID:KhemPoudel,项目名称:onlinePaathsaala,代码行数:10,代码来源:FollowController.php
示例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;
}
}
开发者ID:lnch,项目名称:yii2-user-control,代码行数:25,代码来源:LoginForm.php
示例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]);
}
开发者ID:ketuker,项目名称:oil-palm-cultivation-thesis,代码行数:17,代码来源:AdminController.php
示例13: testRegister
public function testRegister()
{
$this->specify('user should be registered', function () {
$user = new User(['scenario' => 'register']);
$user->username = 'tester';
$user->email = '[email protected]';
$user->password = 'tester';
verify($user->register())->true();
verify($user->username)->equals('tester');
verify($user->email)->equals('[email protected]');
verify(Yii::$app->getSecurity()->validatePassword('tester', $user->password_hash))->true();
});
$this->specify('profile should be created after registration', function () {
$user = new User(['scenario' => 'register']);
$user->username = 'john_doe';
$user->email = '[email protected]';
$user->password = 'qwerty';
verify($user->register())->true();
verify($user->profile->gravatar_email)->equals('[email protected]');
});
}
开发者ID:manyoubaby123,项目名称:imshop,代码行数:21,代码来源:UserTest.php
示例14: actionAssign
public function actionAssign($role, $userId)
{
$user = User::findOne($userId);
if (!$user) {
throw new InvalidParamException('There is no such user.');
}
$auth = Yii::$app->authManager;
$role = $auth->getRole($role);
if (!$role) {
throw new InvalidParamException('There is no such role.');
}
$auth->assign($role, $userId);
}
开发者ID:romaten1,项目名称:yourjob,代码行数:13,代码来源:RbacController.php
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Ruta::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$user = User::findOne(['username' => $this->id_usuario]);
$query->andFilterWhere(['id' => $this->id]);
if ($this->id_usuario != null) {
$query->andFilterWhere(['id_usuario' => $user != null ? $user->id : 0]);
}
if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'Yes'))) {
$query->andFilterWhere(['esActivo' => $this->esActivo == 0]);
} else {
if (strtolower($this->esActivo) == strtolower(Yii::t('core', 'No'))) {
$query->andFilterWhere(['esActivo' => $this->esActivo == 1]);
}
}
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Monday'))) {
$query->andFilterWhere(['dia' => 1]);
} else {
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Tuesday'))) {
$query->andFilterWhere(['dia' => 2]);
} else {
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Wednesday'))) {
$query->andFilterWhere(['dia' => 3]);
} else {
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Thursday'))) {
$query->andFilterWhere(['dia' => 4]);
} else {
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Friday'))) {
$query->andFilterWhere(['dia' => 5]);
} else {
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Saturday'))) {
$query->andFilterWhere(['dia' => 6]);
} else {
if (strtolower($this->dia) == strtolower(Yii::t('core', 'Sunday'))) {
$query->andFilterWhere(['dia' => 7]);
}
}
}
}
}
}
}
return $dataProvider;
}
开发者ID:apmauj,项目名称:1f8bf10ab74d6f5ca69f7c07b7ee1c38,代码行数:58,代码来源:RutaSearch.php
示例16: actionIndex
/**
* This command creates new user account. If password is not set, this command will generate new 8-char password.
* After saving user to database, this command uses mailer component to send credentials (username and password) to
* user via email.
*
* @param string $email Email address
* @param string $username Username
* @param null|string $password Password (if null it will be generated automatically)
*/
public function actionIndex($email, $username, $password = null)
{
$user = Yii::createObject(['class' => User::className(), 'scenario' => 'create', 'email' => $email, 'username' => $username, 'password' => $password]);
if ($user->create()) {
$this->stdout(Yii::t('user', 'User has been created') . "!\n", Console::FG_GREEN);
} else {
$this->stdout(Yii::t('user', 'Please fix following errors:') . "\n", Console::FG_RED);
foreach ($user->errors as $errors) {
foreach ($errors as $error) {
$this->stdout(' - ' . $error . "\n", Console::FG_RED);
}
}
}
}
开发者ID:TheManagers,项目名称:yii2-user,代码行数:23,代码来源:CreateController.php
示例17: testLogin
/**
* Tests login method.
*/
public function testLogin()
{
$user = \Yii::createObject(User::className());
test::double(Finder::className(), ['findUserByUsernameOrEmail' => $user]);
$form = Yii::createObject(LoginForm::className());
$form->beforeValidate();
test::double($form, ['validate' => false]);
verify($form->login())->false();
test::double($form, ['validate' => true]);
test::double(\yii\web\User::className(), ['login' => false]);
verify($form->login())->false();
test::double(\yii\web\User::className(), ['login' => true]);
verify($form->login())->true();
}
开发者ID:manyoubaby123,项目名称:imshop,代码行数:17,代码来源:LoginFormTest.php
示例18: actionConnect
/**
* Displays page where user can create new account that will be connected to social account.
* @param integer $account_id
* @return string
* @throws NotFoundHttpException
*/
public function actionConnect($account_id)
{
$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 ($user->load(\Yii::$app->request->post()) && $user->create()) {
$account->link('user', $user);
\Yii::$app->user->login($user, $this->module->rememberFor);
return $this->goBack();
}
return $this->render('connect', ['model' => $user, 'account' => $account]);
}
开发者ID:manyoubaby123,项目名称:imshop,代码行数:21,代码来源:RegistrationController.php
示例19: up
public function up()
{
if (isset($_SERVER['TRAVIS']) || isset($_SERVER['PWD']) && strpos($_SERVER['PWD'], '/tests/')) {
return null;
}
$userName = 'webmaster';
$tableName = \dektrium\user\models\User::tableName();
$query = 'SELECT COUNT(*) FROM ' . $tableName . ' WHERE `username`=:username';
$count = \Yii::$app->db->createCommand($query, [':username' => $userName])->queryScalar();
if ($count > 0) {
return null;
}
$user = \Yii::createObject(['class' => \dektrium\user\models\User::className(), 'scenario' => 'create', 'username' => $userName, 'password' => $userName, 'email' => $userName . '@yii2enterprise.dev']);
return $user->create();
}
开发者ID:sibds,项目名称:yii2-enterprise,代码行数:15,代码来源:m160219_091156_createUser.php
示例20: actionConnect
/**
* 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);
Yii::$app->user->login($user, $this->module->rememberFor);
return $this->goBack();
}
return $this->render('connect', ['model' => $user, 'account' => $account]);
}
开发者ID:ketuker,项目名称:oil-palm-cultivation-thesis,代码行数:23,代码来源:RegistrationController.php
注:本文中的dektrium\user\models\User类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论