本文整理汇总了PHP中common\models\User::generateAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP User::generateAccessToken方法的具体用法?PHP User::generateAccessToken怎么用?PHP User::generateAccessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\User
的用法示例。
在下文中一共展示了User::generateAccessToken方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Signs user up.
* @return User|null the saved model or null if saving fails
* @internal param string $avatar
*/
public function register()
{
if ($this->validate()) {
$user = new User(['scenario' => 'register']);
$user->username = $this->username;
$user->email = $this->email;
$user->setHashPassword($this->password);
$user->generateAuthKey();
$user->generateAccessToken();
$user->password = md5($this->password);
if ($this->saveAvatar(UploadedFile::getInstance($this, 'avatar'))) {
$user->avatar = $this->avatar;
} else {
Yii::$app->session->setFlash('alert', '注册失败');
Yii::$app->session->setFlash('alert-type', 'alert-danger');
return false;
}
if ($user->save()) {
return $user;
} else {
Yii::$app->session->setFlash('alert', '注册失败');
Yii::$app->session->setFlash('alert-type', 'alert-danger');
return false;
}
}
return null;
}
示例2: signup
/**
* Signs user up.
*
* @return User|false the saved model or false if saving fails
*/
public function signup($runValidation = true)
{
if ($runValidation && !$this->validate()) {
return false;
}
$user = new User();
$user->mobile = $this->_session['mobileSignup'];
$user->setPassword($this->_session['mobileSignupPassword']);
$user->generateAuthKey();
$user->generateAccessToken();
$transaction = Yii::$app->db->beginTransaction();
try {
if (!$user->save(false)) {
throw new \Exception();
}
$userAccount = new UserAccount();
$userAccount->id = $user->id;
$userAccount->password_hash = null;
if (!$userAccount->save(false)) {
throw new \Exception();
}
$transaction->commit();
return $user;
} catch (\Exception $e) {
$transaction->rollBack();
return false;
}
}
示例3: 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->generateAccessToken();
if ($user->save()) {
return $user;
}
}
return null;
}
示例4: save
public function save($runValidation = true, $attributeNames = null)
{
if ($this->validate()) {
$user = new User();
$user->email = $this->email;
$user->setPassword($this->password);
$user->pass_agreement = $this->pass_agreement;
$user->generateAccessToken();
if ($user->save()) {
return $user;
} else {
if ($user->hasErrors()) {
foreach ($user->getErrors() as $error) {
$this->addError('email', $error[0]);
}
} else {
throw new \Exception('create user failed, please contact the supporter');
}
}
}
return false;
}
示例5: createUser
/**
* 建立用户记录
* @return bool|User
*/
public function createUser()
{
$user = new User(['scenario' => 'register']);
$user->username = $this->username;
$user->email = $this->email;
$user->avatar = $this->avatar;
$user->status = 9;
$user->generateAuthKey();
$user->generateAccessToken();
if ($user->save()) {
return $user;
} else {
return false;
}
}