mercredi 25 novembre 2015

Can not use Auth to login in Cakephp

I can not use Auth to login in Cakephp. (i use cakephp 2.4) The query it returns is:

SELECT User.id, User.group_id, User.username, User.password, User.email, User.firstname, User.lastname, User.address, User.phone_number, User.created, User.modified, Group.id, Group.name, Group.description, Group.created FROM chickenrainshop.users AS User LEFT JOIN chickenrainshop.groups AS Group ON (User.group_id = Group.id) WHERE User.username = 'admin' LIMIT 1

??WHERE IS TH PASSWORD IN MY QUERY

My AppController code:

class AppController extends Controller {
public $components = [
                        'DebugKit.Toolbar', 
                        'Session', 
                        'Tool', 
                        'Auth' =>
                                [
                                    'loginAction' => '/login',
                                    'authError'=>'you mus be login to continue',
                                    'flash'=>
                                            [
                                                'element'=>'default',
                                                'key'=>'auth',
                                                'params'=>['class'=>'alert alert-danger']
                                            ],
                                    'loginRedirect'=>'/'
                                ]
                    ];

}

My login function in users controller:

public function login(){
        if ($this->request->is('post')){
            if ($this->Auth->login()){
                $this->redirect($this->Auth->redirect());
            }  else {
                $this->Session->setFlash('username or password is incorrect', 'default',
                                            ['class'=>'alert alert-danger'] , 'auth');
            }
        }
        $this->set('title_for_layout', 'Login');
    }

and login.ctp:

<div class="panel panel-info">
<h4 class="panel-heading"><i class="glyphicon glyphicon-user"></i> Đăng nhập</h4>
<?php echo $this->Session->flash('auth');?>
<?php echo $this->Form->create('User', [
                                        'class'=>"form-horizontal", 
                                        'inputDefaults'=>['label'=>FALSE]
                                        ]);?>
    <div class="control-group">
        <label class="control-label" for="inputUsername">Username</label>
        <div class="controls">
            <?php echo $this->Form->input('username', [
                                                        'placeholder'=>'Tên đăng nhập'
                                                        ]);?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputPassword">Password</label>
        <div class="controls">
            <?php echo $this->Form->input('password', [
                                                        'placeholder'=>'Mật khẩu'
                                                        ]);?>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <hr>
            <?php echo $this->Form->button('Đăng nhập', [
                                                        'type'=>"submit",
                                                        'class'=>"col-lg-2 btn btn-primary"
                                                        ]);?>
        </div>
    </div>
<?php echo $this->Form->end();?>




Aucun commentaire:

Enregistrer un commentaire