thank you very much for your pointer divyanshu das, i've followed your 
guidance but still face the same problem.
1. i can't login through with the data i've insert manual via database 
using md5, it return :
e.g.
INSERT INTO `users` VALUES (1,'admin',MD5('adminpassword'),'T',NOW(),NOW());
2. the login i want to achieve is only in admin url prefix, not in the 
normal url (without admin prefix), i'm try to combine what i've read in the 
book and your suggestion it'll end up with the normal url (without admin 
prefix) still require the authentication.

here's the code :
*Model/User.php*
<?php
App::uses('AppModel', 'Model', 'AuthComponent', 'Controller/Component');

class User extends AppModel {

public $validate = array(
'username' => array(
'notempty' => array(
'rule' => array('notempty'),
'allowEmpty' => false,
'required' => true,
//'message' => 'Your custom message here',
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'password' => array(
'notempty' => array(
'rule' => array('notempty'),
'allowEmpty' => false,
'required' => true,
//'message' => 'Your custom message here',
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);

    public function beforeSave($options = array()) {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = 
AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }
}

*Controller/AppController.php*
<?php
App::uses('Controller', 'Controller');

class AppController extends Controller {

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action' => 
'admin_index'),
            'logoutRedirect' => array('controller' => 'homes', 'action' => 
'index')
        )
    );
}

*Controller/UsersController.php*
<?php
App::uses('AppController', 'Controller');

class UsersController extends AppController {

    public function beforeFilter() {
        parent::beforeFilter();
    }

    public function admin_login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->redirect($this->Auth->redirect());
            } else {
                $this->Session->setFlash(__('Invalid username or password, 
try again'));
            }
        }
    }

    public function admin_logout() {
        $this->redirect($this->Auth->logout());
    }

// index, admin_index, admin_add, admin_edit, admin_view generated by cake 
bake controller all --admin
}

*View/Users/admin_login.php*
<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User', array( 'controller' => 'users', 
'action' => 'login', 'admin' => true)); ?>
    <fieldset>
        <legend><?php echo __('Please enter your username and password'); 
?></legend>
        <?php echo $this->Form->input('username');
        echo $this->Form->input('password');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>

any idea, suggestion or solution to achieve it?

many thanks in advance

best regards

On Saturday, May 11, 2013 1:46:00 AM UTC+7, divyanshu das wrote:

> @steve, for the user you inserted using mysql dump, the password field 
> encryption function needs to be md5. This is one problem I also faced. I 
> had to set the function to md5.
>
> To create a login form with admin prefix, you need to pass the url option 
> in form as something like this:-
> url => array( 'controller' => 'users', 'action' => 'login', 'admin' => 
> true)
>
> then use auth component in users controller -> admin_login function
> basically whenever you set 'admin' => true, it automatically checks for 
> admin_prefix function.
>
>
> On Fri, May 10, 2013 at 2:19 PM, steve van christie <
> steve.van...@gmail.com <javascript:>> wrote:
>
>> thank you so much for your pointer divyanshu das, i've followed the 
>> tutorial on book, but found a strange things. i can't login with the user 
>> i've inserted via mysql dump. for the users i've input via form can login. 
>> actually i'm generated the code via cake bake (cake bake model all, cake 
>> bake controller all --admin, cake bake view -all). the things that i want 
>> to achieve here is create the login form for admin prefix and then redirect 
>> all the admin function (CRUD). any ideas, suggestions or pointers?
>>
>> thank you so much in advance
>>
>> best regards
>>
>> -- 
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Find us on Twitter http://twitter.com/CakePHP
>>  
>> --- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "CakePHP" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/cake-php/otbwtUZ0RFI/unsubscribe?hl=en.
>> To unsubscribe from this group and all its topics, send an email to 
>> cake-php+u...@googlegroups.com <javascript:>.
>> To post to this group, send email to cake...@googlegroups.com<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Regards
> Divyanshu Das,
> AlphaBeta Labs,
> Bangalore, India
> Contact# 9591999094
>  

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to