/app/controllers/user_controller.php
<?
Class Usercontroller extends AppController {
var $uses =array (' user ');
function index () {
}
function Login () {
if (!empty ($this->data[' user ')) {
$this->user->name= $this->data[' user ' [' name '];
$user = $this->user->find ("User.name="). $this->data[' user ' [' name '].
Print_r ($user);
$user = $user [' user '];
Print_r ($user);
if ($user [' Password ']==md5 ($this->data[' user '] [' password ']) {
$this->session->write (' login ', 1);
$this->flash (' Login suss!! ', '/user ');
}else{
if (! $user [' id ']) {
$this->flash (' No this user!! ', '/user ');
}else{
$this->flash (' name or pass is wrong!! ', '/user ');
}
}
}else{
$this->flash (' Need name and password!! ', '/user ');
}
Exit ();
}
function logout () {
if ($this->session->check (' login ')) {
$this->session->del (' login ');
}
$this->flash (' Logout ok ', '/user ');
Exit ();
}
function Reset () {
$name = ' AAA ';
$pass = ' AAA ';
$user = $this->user->findbyname ($name);
if ($user [' User '] [' ID ']) {
$this->user->set ($user);
}else{
$this->user->set (' name ', $name);
$this->user->set (' Password ', MD5 ($pass));
}
$ret = $this->user->save ();
if ($ret) {
$this->flash (' Update ok!! ', '/user ');
}else{
$this->flash (' Update ok!! ', '/user ');
}
}
}
?>
/app/models/user.php
<?
Class User extends Appmodel {
var $name = "User";
var $useTable = ' users ';
}
?>
/app/views/user/index.view
<?if ($this->controller->session->read (' login ')!=1):?>
<?echo $html->formtag ('/user/login ');? >
<?echo $html->input (' user/name ');? ><br>
<?echo $html->password (' User/password ');? ><br>
<?echo $html->submit (' submit ');? >
</form>
<?else:?>
<?endif?>
Simple user authentication trial $model->findbyfields (); You can use any of the fields in the Model table to query
$model->set ($data);
$model->set ($key, $value);
You can set the query result directly after save if there is a primary key value will update, if not insert into the table.
The above is cakephp user login Verification instance short type good example content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!