本文整理汇总了PHP中UserIdentity::createAuthenticatedIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity::createAuthenticatedIdentity方法的具体用法?PHP UserIdentity::createAuthenticatedIdentity怎么用?PHP UserIdentity::createAuthenticatedIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserIdentity
的用法示例。
在下文中一共展示了UserIdentity::createAuthenticatedIdentity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
public function actionIndex()
{
$user = new User();
if (!empty($_POST['User'])) {
$user->attributes = $_POST['User'];
if ($user->save()) {
Yii::app()->user->login(UserIdentity::createAuthenticatedIdentity($user->username, $user->id), 0);
echo json_encode(array('errors' => ''));
} else {
$errors = $user->getErrors();
echo json_encode(array('errors' => $errors));
}
exit;
}
$this->render('index', array('model' => $user));
}
示例2: actionSuccess
/**
* running when login success
*/
public function actionSuccess()
{
$instagram = Yii::app()->instagram;
// receive OAuth code parameter
$code = $_GET['code'];
// check whether the user has granted access
if (isset($code)) {
// receive OAuth token object
$data = $instagram->getOAuthToken($code);
$username = $data->user->username;
$user_id = $data->user->id;
$avatar = $data->user->profile_picture;
// store user access token
$instagram->setAccessToken($data);
// now you have access to all authenticated user methods
$result = $instagram->getUserMedia();
if ($data) {
// save this information to db
$user = new User('instagram_login');
$user->username = $username;
$user->instagram_id = $data->user->id;
$user->access_token = $instagram->getAccessToken($data);
$user->full_name = $data->user->full_name;
$user->avatar = $avatar;
// check if instagram_id is unique then save to db
$user = $user->zeroUnique();
if (!isset(Yii::app()->user->id)) {
// login automatically
Yii::app()->user->login(UserIdentity::createAuthenticatedIdentity($user->username, $user->id), 0);
$this->redirect('/user/activity');
}
$this->redirect('/user/account');
} else {
throw new CHttpException('There are some issues with login on instagram.');
}
} else {
// check whether an error occurred
if (isset($_GET['error'])) {
echo 'An error occurred: ' . $_GET['error_description'];
}
}
$this->render('success', array('result' => $result, 'username' => $username));
}
示例3: actionActivate
public function actionActivate($a)
{
if ($a != '') {
$model = User::model()->find('activate=:a', array(':a' => $a));
d2l($model->attributes);
if ($model) {
// /$model->activate='';
if ($model->status != User::STATUS_ACTIVE) {
$model->status = User::STATUS_ACTIVE;
if ($model->update(array('status'))) {
Yii::app()->user->login(UserIdentity::createAuthenticatedIdentity($model->username, $model->id), 0);
d2l(Yii::app()->user->model->attributes);
$this->render('activate', array('model' => $model, 'status' => 'success'));
}
} else {
Yii::app()->user->logout();
$this->render('activate', array('model' => $model, 'status' => 'already'));
}
} else {
throw new CHttpException(404, "Invalid Activation Code!");
}
}
}