namespace app\index\controller;
use app\index\controller\Base;
use think\Request;
use app\index\model\User as UserModel;
class User extends Base
{
//Login page
public function login()
{
return $this -> view ->fetch();
}
//Login verification
public function checklogin(Request $request)
{
//Initial return parameters
$status = 0;
$result = '';
$data = $request -> param();
//Create validation rules
$rule = [
'name|Username' => 'require',//Username is required
'password|Password' => 'require',
'verify|captcha' => 'require|captcha',
];
$msg = [
'name ' => ['require'=>'Username cannot be empty! '],
'password' => ['require'=>'Password cannot be empty! '],
'verify' => [
'require'=>'Verification code cannot be empty! ',
'captcha'=>'Verification code error',
],
];
$result = $this->validate($data, $rule, $msg);
if($result ===true){
//Construct query conditions
$map = [
'name' => $data['name'],
'password' => md5 ($data['password']),
];
//Query user information
$user = UserModel::get($ map);
if($user == null){
$result = 'The user was not found';
}else{
$status = '1';
$result = "Verification passed";
}
}
return ['status '=>$status, 'message'=>$result, 'data'=>$data];
}
//Log out
public function logout()
{
}
}
##
Mine is the same, has the poster solved it? Can you share it
When there is a syntax error in any method in a PHP class, other methods cannot be used normally.
It is recommended to pay attention to Chinese and English symbols when writing code.
The login page cannot be accessed