本文整理汇总了PHP中UserInfo::noEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInfo::noEmail方法的具体用法?PHP UserInfo::noEmail怎么用?PHP UserInfo::noEmail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserInfo
的用法示例。
在下文中一共展示了UserInfo::noEmail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionRennAuth
/**
* 处理人人网登录事宜
* Enter description here ...
* @throws CHttpException
*/
public function actionRennAuth()
{
$rennService = new RennService();
$rennClient = $rennService->getClient();
// 处理code -- 根据code来获得token
if (isset($_REQUEST['code'])) {
$keys = array();
// 获得code
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = Yii::app()->createAbsoluteUrl('/oauth/rennAuth');
try {
// 根据code来获得token
$token = $rennClient->getTokenFromTokenEndpoint('code', $keys);
} catch (RennException $e) {
error_log($e->getTraceAsString());
throw new CHttpException(403, Yii::t('app', '没有得到授权,不能访问'));
Yii::app()->end();
}
}
// 获得用户接口
$userService = $rennClient->getUserService();
// 获得当前登录的人人用户信息
try {
$rennUser = $userService->getUserLogin();
} catch (Exception $e) {
throw new CHttpException(403, Yii::t('app', '没有得到授权,不能访问'));
Yii::app()->end();
}
if (isset($rennUser)) {
//检查是否为新用户
// $rrOauth = Oauth::model()->find('rrid=:rrid',array('rrid'=>$rennUser['id']));
$userInfo = UserInfo::model()->findByAttributes(array('rennId' => $rennUser['id']));
//如果是新用户,在站内创建一个对应用户
if (!$userInfo) {
$transaction = Yii::app()->db->beginTransaction();
try {
$user = new User();
$user->email = 'RRId' . $rennUser['id'] . '@daxidao.com';
$user->password = DxdUtil::randCode(32);
$user->salt = DxdUtil::randCode(32);
$userSaved = $user->validate() && $user->save();
$userInfo = new UserInfo();
$userInfo->id = $user->getPrimaryKey();
$userInfo->email = $user->email;
$userInfo->name = $rennUser['name'];
$userInfo->addTime = time();
$userInfo->rennId = $rennUser['id'];
$userInfo->status = 'ok';
$userInfoSaved = $userInfo->save();
if (!$userSaved || !$userInfoSaved) {
Yii::app()->user->setFlash('error', Yii::t('app', '抱歉,创建用户失败'));
throw new Exception(Yii::t('app', '创建用户失败!'));
}
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
$this->redirect(Yii::app()->baseUrl);
Yii::app()->end();
}
}
//站内用户登录
/* $identity=new UserIdentity($userInfo->email,'somepassword');
$identity->authenticate(true);
if($identity->errorCode===UserIdentity::ERROR_NONE)
{
//$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($identity, 0);
//print_r(Yii::app()->user);
}*/
$user = User::model()->findByAttributes(array('email' => $userInfo->email));
$user->loginWithoutPassword();
}
//如果还没有填写email
if ($userInfo->noEmail()) {
$this->redirect(array('u/registerOauth'));
Yii::app()->end();
}
Yii::app()->user->setFlash('success', Yii::t('app', '人人网登录成功!'));
$this->redirect($this->homePage);
}