CakePHP 2 - qo'lda kirish seansga qo'shilmaydi

Men CakePHP uchun yangi va men boshimni yumaloq ro'yxatga olish/kirishga harakat qilaman, cakephp 2.0 dan foydalanib

Agar foydalanuvchi registr nazorat qilish funktsiyasidan foydalangan holda tashkil etsa va alohida tizimga kirsa ( $ this-Auth-user() ) kutgan barcha Model qiymatlari mavjud.

If i follow the cakephp 2.0 book example and manually login during the register then I do get logged in but $this->Auth->user() only contains the fields from the register form not the User Model. (ie. its missing my Model fields "created", "full name" etc but includes "password" and "passwordconfirm" both unencrypted)

Bu erda biror narsa yo'qmi?

Kirish Ro'yxatdan o'tish:

public function login(){
if($this->request->is('post')){
    if($this->Auth->login()){
        return $this->redirect($this->Auth->redirect());
    } else {
        $this->Session->setFlash(__('Invalid Username or Password.'), 'default', array(), 'auth');
    }
}
}

Ro'yxatdan o'tish Ro'yxatdan o'tish (avtomatik kirish bilan):

public function register(){
    if($this->request->is('post')){
        $this->User->create();
        if($this->User->save($this->request->data)){

            //Login automatically
            if($this->Auth->login($this->data['User'])){

                $this->Session->setFlash(__('Welcome to Test Site.'), 'default', array(), 'auth');
                return $this->redirect($this->Auth->redirect());

            } else {
                $this->Session->setFlash(__('Failed to login with new account.'), 'default', array(), 'auth');
                $this->redirect(array('action' => 'login'));
            }
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

Register.ctp ko'rinishi

<?php
echo $this->Form->create('User', array('action' => 'register'));
echo $this->Form->input('username');
echo $this->Form->input('password', array('label' => 'Password'));
echo $this->Form->input('passwordconfirm', array('label' => 'Confirm Password', 'type' => 'password'));
echo $this->Form->input('email', array('label' => 'Email (optional)'));
echo $this->Form->end('Join');
?>

Biror yordamga muhtoj bolalar uchun bu ozgina uzr so'raydi!


EDIT:

Found a workaround! Looks like $this->Auth->login($this->data['User']) was failing to AuthComponent::identify() my User so i changed it for the following 3 lines:

$LoggedInID = $this->User->field('id', array('username' => $this->Auth->user('username')));
$user = $this->User->read(null, $LoggedInID);
$this->Auth->login($user);

va bu bir muomala qiladi.

Tahrirlash: Siz shuningdek save() funktsiyasidan foydalanishingiz mumkin:

        if($user = $this->User->save($this->request->data)){

            //Login automatically
            if($this->Auth->login($user)){
3

2 javoblar

O'zgarishni qilib ko'ring

if($this->Auth->login($this->data['User'])){

uchun

if($this->Auth->login()){
1
qo'shib qo'ydi

Buni "session.cookie_domain" qiymatini PHP.ini domen nomimga o'zgartirib, hal qildim.

session.cookie_domain = my.domain.com

Endi u mukammal ishlaydi.

Core.php ning sessiya parametrlari quyidagicha

Configure::write('Session', array(
    'defaults' => 'php'     
));
0
qo'shib qo'ydi
PhP |BotsUz
PhP |BotsUz
93 ishtirokchilar

Phpni o'rganishni Hohlasangiz https://t.me/joinchat/AAAAAE-KRc5dd5tPMmGmWA A'zo bo'lin