| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- /**
- * 登录
- * @author wesmiler
- */
- namespace app\api\controller;
- use app\index\service\Storage;
- use app\index\service\Users;
- use app\index\validate\UsersValidate;
- use cmf\controller\HomeBaseController;
- class LoginController extends HomeBaseController
- {
- /**
- * 账号注册
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function register(){
- $params = input();
- $validate = new UsersValidate();
- if (!$validate->scene('reg')->check($params)) {
- showJson(1002, $validate->getError());
- }
- // 头像
- $file = request()->file('avatar');
- if ($file) {
- $fileData = Storage::uploadImg($file, 'avatar');
- $params['avatar'] = isset($fileData['file']) ? $fileData['file'] : '';
- }
- if(!Users::saveData($params)){
- showJson(1002, 1011);
- }
- showJson(1001, 1012);
- }
- /**
- * 账号注册
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function login(){
- $params = input();
- $validate = new UsersValidate();
- if (!$validate->scene('login')->check($params)) {
- showJson(1002, $validate->getError());
- }
- $result = Users::login($params);
- if(!is_array($result)){
- showJson(1002, $result);
- }
- showJson(1001, 1013, $result);
- }
- }
|