| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\admin\controller;
- use think\Controller;
- use think\Exception;
- use think\Session;
- use think\Log;
- use think\cache\driver\Redis;
- class Login extends Controller
- {
- /**
- * 管理员登录
- *
- * @access public
- * @return string
- */
- public function login()
- {
- $msg = '';
-
- if (input('post.')) {
- $msg = lang('EC01002');
- try {
- // 获取管理员信息.
- $userInfo = model('Admin')->login();
- print_r($userInfo);
- // 成功则跳转.
- if ($userInfo['code'] === 1) {
- return $this->redirect('Admin/Index/index');
- // 失败则返回错误信息.
- } else {
- $msg = $userInfo['msg'];
- }
- } catch (Exception $e) {
- Log::write($e->getMessage(), 'error');
- }
- }
- $this->assign([
- 'errorMsg' => $msg,
- ]);
- return $this->fetch();
- }//end login()
- /**
- * 退出登陆
- *
- * @access public
- * @return string
- */
- public function logout()
- {
- try {
- // 退出登陆.
- $userInfo = model('Admin')->logout();
- // 成功.
- if ($userInfo['code'] === 1) {
- return $this->redirect('Admin/Login/login');
- }
- } catch (Exception $e) {
- Log::write($e->getMessage(), 'error');
- }
- }//end logout()
- }
|