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