本文整理汇总了PHP中common\models\User::getId方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getId方法的具体用法?PHP User::getId怎么用?PHP User::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::getId方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signup
/**
* Регистрация нового пользователя
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$randLength = mt_rand(6, 9);
$this->password = Yii::$app->security->generateRandomString($randLength);
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
//$profile = new Profile();
//$profile->user_id = $user->id;
//$profile->name = $this->name;
////если в куках есть id аффилиата, сохраняем его
//$affiliateId = (int) Yii::$app->request->cookies['affiliate'];
//if ($affiliateId > 0 && User::findIdentity($affiliateId)) {
//$profile->user_affiliate_id = $affiliateId;
//}
//$profile->save();
// Присвоить роль пользователю можно при создании нового пользователя.
// присвоить Роль "user" новому пользователю
// `auth_assignment`
$userRole = Yii::$app->authManager->getRole('user');
Yii::$app->authManager->assign($userRole, $user->getId());
return $this->sendRegistrationEmail();
}
}
return null;
}
示例2: reg
public function reg()
{
$user = new User();
$user->phone = $this->phone;
$user->email = $this->email;
$user->status = $this->status;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($this->scenario === 'emailActivation') {
$user->generateSecretKey();
}
$transaction = Yii::$app->db->beginTransaction();
try {
if ($user->save()) {
$modelProfile = new Profile();
$modelProfile->user_id = $user->id;
if ($modelProfile->save()) {
$transaction->commit();
return RbacHelper::assignRole($user->getId()) ? $user : null;
}
} else {
return false;
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
示例3: setModel
/**
* @param User $model
* @return User
*/
public function setModel($model)
{
$this->username = $model->username;
$this->email = $model->email;
$this->status = $model->status;
$this->model = $model;
$this->roles = ArrayHelper::getColumn(\Yii::$app->authManager->getRolesByUser($model->getId()), 'name');
return $this->model;
}
示例4: assignRole
/**
* Assigns the appropriate role to the registered user.
* If this is the first registered user in our system, he will get the
* root role (this should be you), if not, he will get the user role.
*
* @param User $user User object.
* @return string Role name.
*/
public static function assignRole(User $user)
{
$id = $user->getId();
// make sure there are no leftovers
Role::deleteAll(['user_id' => $id]);
$auth = Yii::$app->authManager;
$role = $auth->getRole($user->user_role);
$auth->assign($role, $id);
// return assigned role name in case you want to use this method in tests
return $role->name;
}
示例5: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->save();
$user->afterSignup();
$auth = Yii::$app->authManager;
$auth->revokeAll($user->getId());
if ($this->roles && is_array($this->roles)) {
foreach ($this->roles as $role) {
$auth->assign($auth->getRole($role), $user->getId());
}
}
return $user;
}
return null;
}
示例6: signup
/**
* Signs up the user.
* If scenario is set to "rna" (registration needs activation), this means
* that user need to activate his account using email confirmation method.
*
* @return User|null The saved model or null if saving fails.
*/
public function signup()
{
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->status = $this->status;
// if scenario is "rna" ( Registration Needs Activation ) we will generate account activation token
if ($this->scenario === 'rna') {
$user->generateAccountActivationToken();
}
// if user is saved and role is assigned return user object
return $user->save() && RbacHelper::assignRole($user->getId()) ? $user : null;
}
示例7: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$user = new User(['scenario' => 'create']);
$role = new Role();
if ($user->load(Yii::$app->request->post()) && $role->load(Yii::$app->request->post()) && Model::validateMultiple([$user, $role])) {
$user->setPassword($user->password);
$user->generateAuthKey();
if ($user->save()) {
$role->user_id = $user->getId();
$role->save();
}
return $this->redirect('index');
} else {
return $this->render('create', ['user' => $user, 'role' => $role]);
}
}
示例8: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
$userRole = Yii::$app->authManager->getRole('user');
Yii::$app->authManager->assign($userRole, $user->getId());
return $user;
}
}
return null;
}
示例9: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->save(false);
// the following three lines were added:
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('author');
$auth->assign($authorRole, $user->getId());
return $user;
}
return null;
}
示例10: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->parent_id = $this->parent_id;
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->save(false);
// нужно добавить следующие три строки:
$auth = Yii::$app->authManager;
$userRole = $auth->getRole('user');
$auth->assign($userRole, $user->getId());
return $user;
}
return null;
}
示例11: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->acceso_externo = false;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
// Aca es donde se asigna el rol "sinRol" a los nuevos usuarios
$auth = Yii::$app->authManager;
$sinRol = $auth->getRole('sinRol');
$auth->assign($sinRol, $user->getId());
return $user;
}
}
return null;
}
示例12: actionCreate
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$user = new User(['scenario' => 'create']);
if (!$user->load(Yii::$app->request->post())) {
return $this->render('create', ['user' => $user]);
}
$user->setPassword($user->password);
$user->generateAuthKey();
if (!$user->save()) {
return $this->render('create', ['user' => $user]);
}
$auth = Yii::$app->authManager;
$role = $auth->getRole($user->item_name);
$info = $auth->assign($role, $user->getId());
if (!$info) {
Yii::$app->session->setFlash('error', Yii::t('app', 'There was some error while saving user role.'));
}
return $this->redirect('index');
}
示例13: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate()) {
$user = new User();
$user->first_name = $this->first_name;
$user->last_name = $this->last_name;
$user->username = $this->username;
$user->email = $this->email;
$user->avatar = $this->avatar;
$user->setPassword($this->password);
$user->generateAuthKey();
if ($user->save()) {
/* Give user access to client area */
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('client');
$auth->assign($authorRole, $user->getId());
return $user;
}
}
return null;
}
示例14: fillUserData
/**
* Заполнение данных пользователя.
*
* @param User $user
*/
public function fillUserData(User $user)
{
$this->setUserId($user->getId());
$this->setCompanyId($user->getCompanyId());
$this->setEmail($user->getEmail());
$this->setFullName($user->getFullName());
$this->setRole($user->getRole());
$this->setStatus($user->getStatus());
$this->setPhoto($user->getPhoto());
}