One login
LoginController.class.php:
Public Function Index () {
$admin =d (' admin ');//materialized Database
if (is_post) {
if ($admin->create ($_post,4)) {// Verify the input: username/password/authentication code
if ($admin->login ()) {
$this->success (' login succeeded. Jump ... ', U (' Index/index ');//You can also jump directly to
}else{
$this->error ("username or password does not exist.") ");
}
} else{
$this->error ($admin->geterror ());
}
return;
}
if (session (' ID ')) {
$this->error (' You are logged in, do not log on again. ', U (' Index/index ');
} else{
$this->display ();
}
AdminModel.class.php:
<?php namespace Admin\model;
Use Think\model; Class Adminmodel extends Model {protected $_validate = Array (' username ', ' require ', ' admin name must not be empty. ', 1, ' Regex ', 3,///By default verify Array (' username ', ', ', ', ', ' admin name already exists. ', 1, ' Unique ', 3, Array (' Password ', ' Require ', ' password must not be null. ', 1, ' regex ', 1,//above is registered when verifying//below is login authentication Array (' username ', ' require ', ' admin name must not be empty. ', 1, ' Regex ', 4, Array (' Password ', ' Require ', ' password must not be null. ', 1, ' Regex ', 4, Array (' Verify ', ' check_verify ', ' captcha error.
', 1, ' Callback ', 4);
Public Function Login () {$password = $this->password;
$info = $this->where (Array (' username ' => $this->username))->find ();
if ($info) {if ($info [' Password ']==md5 ($password)) {session (' ID ', $info [' id ']);
Session (' username ', $info [' username ']);
return true;
}}else{return false; }} Public Function check_verify ($code, $id = ') {$verify =new \think\verify ();
Return $verify->check ($code, $id); }
}
Two sign out
Public Function Logout () {session
(NULL);
$this->success (' Exit succeeded. Jump in ... ', U (' Login/login '));
}