本文整理汇总了PHP中UserIdentity::authenticateWeibo方法的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity::authenticateWeibo方法的具体用法?PHP UserIdentity::authenticateWeibo怎么用?PHP UserIdentity::authenticateWeibo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserIdentity
的用法示例。
在下文中一共展示了UserIdentity::authenticateWeibo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginBySina
public function loginBySina()
{
$SAEOAuth = Yii::app()->SAEOAuth;
$client = $SAEOAuth->getSinaClient();
$sina_id = $SAEOAuth->getUserID();
$sina_info = $client->show_user($sina_id);
$model = new WeiboForm();
$user = $model->getUserBySinaID($sina_id);
if (empty($user)) {
if (Yii::app()->user->isGuest or 1) {
$username = $sina_id;
$password = '123456';
$model->username = $sina_id;
$model->password = $password;
$model->verifyPassword = $password;
$soucePassword = $model->password;
$model->activkey = UserModule::encrypting(microtime() . $model->password);
$model->password = UserModule::encrypting($model->password);
$model->verifyPassword = UserModule::encrypting($model->verifyPassword);
$model->superuser = 0;
$model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
$model->sina_id = $sina_id;
$model->email = $sina_id . '@hhb.com';
$model->save();
$user = $model;
} else {
$user = User::model()->findByPk(Yii::app()->user->id);
$user->sina_id = $sina_id;
$user->save();
}
}
$profile = $user->profile;
if (empty($profile)) {
$profile = new Profile();
$profile->user_id = $model->id;
}
$profile->name = $sina_info['name'];
$profile->location = $sina_info['location'];
$profile->current_province = $sina_info['province'];
$profile->current_city = $sina_info['city'];
$profile->avatar = $sina_info['profile_image_url'];
$profile->save();
$username = $user->username;
$password = $user->password;
$identity = new UserIdentity($username, $password);
$identity->authenticateWeibo();
//必须设置默认时间,才能多域名共享登录session
$duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
// 30 days
Yii::app()->user->login($identity, $duration);
}