CakePHP User Login Verification instance short Type good example

Source: Internet
Author: User
/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)!

  • Related Article

    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.