本文整理匯總了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;
}
}