本文整理汇总了PHP中backend\models\User::setUserSession方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setUserSession方法的具体用法?PHP User::setUserSession怎么用?PHP User::setUserSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backend\models\User
的用法示例。
在下文中一共展示了User::setUserSession方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
public function actionIndex()
{
$this->layout = false;
if (\Yii::$app->request->isAjax) {
$user = new User();
$data = \Yii::$app->request->post();
$userInfo = $user->getFindUser(['name' => $data['name']]);
$pass = md5(md5($data['password']));
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
//将响应数据转json格式
if (!$userInfo || $userInfo['password'] != $pass) {
//验证用户登录信息
return ['msg' => '用户名或密码错误', 'status' => 0];
} else {
if ($member = \common\models\User::getInstance()->getUserByPhone($userInfo['phone'])) {
$userInfo['member'] = $member;
}
$auth = \Yii::$app->authManager;
$userRole = $auth->getAssignments($userInfo['id']);
$role = "";
foreach ($userRole as $k => $v) {
if ($k == 'admin') {
$role = "admin";
break;
}
$role .= "," . $k;
}
$userInfo['role'] = $role;
$user->setUserSession($userInfo);
//设置Session
return ['msg' => '登录成功', 'status' => 1];
}
}
return $this->render('index.html');
}