| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace wechat\modules\cp\controllers;
- use wechat\models\AdminIdentity;
- use wechat\models\AdminApi;
- use Yii;
- class AccountController extends BaseController
- {
- /**
- * 登录界面
- * @return string
- */
- public function actionLogin()
- {
- $tip = '';
- if (Yii::$app->getRequest()->getIsPost()) {
- $data['username'] = trim(Yii::$app->request->post('j_username'));
- $data['password'] = trim(Yii::$app->request->post('j_password'));
- $api = new AdminApi();
- $result = $api->login($data);
- if ($result['code'] == 1) {
- $identity = new AdminIdentity();
- $identity->setAttributes($result['data']);
- Yii::$app->user->login($identity);
- return $this->redirect('/' . $this->module->id . '/default');
- } else {
- $tip = $result['message'];
- }
- }
-
- return $this->render('login', ['tip' => $tip]);
- }
- /**
- * 登出
- */
- public function actionLogout()
- {
- $redirectAction = 'login';
- Yii::$app->user->logout(false);
- $this->redirect([$redirectAction]);
- }
-
- }
|