<?php
namespace app\index\Controller;
use app\index\Controller\Base;
use think\Request;
use app\index\model\User as UserModel;
class User extends Base
{
public function login()
{
return $this-> view ->fetch();
}
public function checklogin(Request $request)
{//初始返回参数
//$status = 0;
// $result = '';
// $data = $request -> param();
$status = 0; //验证失败标志
$result = '验证失败'; //失败提示信息
$data = $request -> param();
// 创建验证规则
$rule=[
'name|用户名'=>'require',//用户名必填
'password|密码'=>'require',//密码必填
'verify|验证码'=>'require|captcha',//验证码必填
];
$msg=[
'name'=>['require'=>'用户名不能为空请检查'],
'passwrod'=>['require'=>'密码不能为空请检查'],
'verify'=>[
'require'=>'验证码不能为空请检查',
'captcha'=>'验证码错误',
],
];
//$result = $this->validate($data,$rule,$msg);
$result=$this->validate($data, $rule, $msg);
if ($result===true) {
//查询条件
$map = [
'name' => $data['name'],
'password' => md5($data['password'])
];
//数据表查询,返回模型对象
$user = UserModel::get($map);
if (null === $user) {
$result = '没有该用户,请检查';
} else {
$status = 1;
$result = '验证通过,点击[确定]后进入后台';
}
}
return['status' => $status,'message' => $result,'data' => $data];
//return['status'=>$status,'message'=>$result, 'data'=>$data];
}
public function logout()
{
}
}
请帮指出,可以吗,谢谢
jrhhy 你确定打对了????