A good example of a short instance for cakephp user login verification

Source: Internet
Author: User
You can set the query result directly and save it. if there is a primary key value, it will be updated. if not, it will be inserted into the table.

/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

Controller-> Session-> read ('login ')! = 1):?>
FormTag ('/user/login');?>
Input ('user/name');?>

Password ('user/password');?>

Submit ('submit ');?>


Simple user verification Trial $ model-> findByFields (); you can use any field in the model table to query
$ Model-> set ($ data );
$ Model-> set ($ key, $ value );
You can set the query result directly and save it. if there is a primary key value, it will be updated. if not, it will be inserted into the table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.