| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace addons\Store\api\modules\v2\controllers;
- use addons\Store\common\models\StoreAdmin;
- use Yii;
- use api\controllers\OnAuthController;
- use yii\db\Exception;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Store\api\modules\v2\controllers
- */
- class AuthController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index','login'];
- public function actionLogin(){
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['username'], 'required'],
- [['password'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $token = StoreAdmin::loginByH5($params);
- if(empty($token['access_token'])) return $this->error(StoreAdmin::getStaticError());
- $token['access_store_token'] = $token['access_token'];
- unset($token['access_token']);
- return $this->success('登录成功', $token);
- }
- }
|