Com.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Created by PhpStorm.
* User: asus
* Date: 2019/6/12
* Time: 11:08
*/
namespace app\api\controller;
use think\captcha\Captcha;
use think\Validate;
use app\api\model\Manager as ManagerModel;
class Com extends Base
{
/**
* @name:获取验证码
* @method:get
*/
public function code(){
$this->response('验证码',200,'111');
$config = [
'codeSet' => '1234567890',
// 验证码字体大小
'fontSize' => 30,
// 验证码位数
'length' => 6,
// 关闭验证码杂点
'useNoise' => false,
];
$captcha = new Captcha($config);
$this->response('验证码',200,$captcha->entry());
}
/**
* 管理员登录
* @method:post
* @param $account $password
*/
public function login(){
$rule = [
['account','require|max:15','账号不能为空|最多不能超过25个字符'],
['password','require|max:30','密码不能为空|必须在1~50字符之间'],
];
$validate = new Validate($rule);
if ($validate->check($this->param) === false) {
$this->response($validate->getError(), 202);
}
$manager = new ManagerModel();
$info = $manager->login($this->param['account'],$this->param['password']);
if(empty($info)){
$this->response('账号或者密码错误',202,[]);
}
$this->response('登录成功',200,$info);
}
}