Oh, interesting. I've got the User model handling the flash messages. Maybe
my logic about this is wrong.
<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
//public $primaryKey = 'id';
public $validate = array(
'full_name' => array(
'rule' => array('custom', '/^[a-z0-9 ]*$/i'),
'message' => 'We need your name!',
'required' => true
),
'email' => array (
'is_valid' => array(
'rule' => 'notEmpty',
'rule' => array('email', true),
'message' => 'A valid email is required',
'last' => true
),
'is_unique' => array(
'rule' => 'isUnique',
'message' => 'That email address is already in our
database.'
)
),
'password' => array(
'min' => array(
'rule' => array('minLength', 6),
'message' => 'Your password must be more than 6 characters',
'required' => true
),
'required' => array(
'rule' => 'notEmpty',
'message'=>'Please enter a password.'
),
),
'password_confirm' => array(
'required'=>'notEmpty',
'match'=>array(
'rule' => 'validatePasswdConfirm',
'message' => 'Passwords do not match'
)
),
); //END VALIDATE
function beforeSave() {
if (isset($this->data['User']['password']))
{
$this->data['User']['password'] =
AuthComponent::password($this->data['User']['password']);
}
if (isset($this->data['User']['password_confirm']))
{
}
return true;
}
function validatePasswdConfirm($data) {
if ($this->data['User']['password'] !== $data['password_confirm'])
{
return false;
}
return true;
}
}
?>
My UsersController.php has the register action/function like this --
public function register() {
$this->set('title_for_layout', 'Register');
if ($this->Auth->user()) {
$this->redirect(array('controller' => 'users', 'action' =>
'dashboard'));
}
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
//$this->User->setFlash(__('The user has been
saved'));
$this->Auth->login($this->request->data);
$this->Session->setFlash(__('Welcome to your
dashboard!'));
$this->redirect(array('controller' => 'users', 'action'
=> 'dashboard'));
} else {
}
}
} // END REGISTER
I'm building this from the ground up, to learn both php and cakephp. So
things might not seem secure, etc etc. I do appreciate the help.
On Thursday, April 4, 2013 7:51:37 AM UTC-4, Jeremy Burns wrote:
>
> Model arrays? You set this in the controller. So when your form posts to
> the controller action it then calls the appropriate action (either in the
> Auth component or the User model). If the action returns an error you set
> the flash message (in the controller). At that point you'd set the fourth
> parameter to (e.g.) 'login-failed' or 'registration-failed'. Then you'd
> flash out the 'login-failed' message on the login form/element and the
> registration-failed message on the registration form/element.
>
> Jeremy Burns
> Class Outfit
>
> http://www.classoutfit.com
>
> On 4 Apr 2013, at 12:47:14, Nathan Pierce <[email protected]<javascript:>>
> wrote:
>
> Thanks Jeremy, I actually tried that yesterday. I guess I didn't set it
> properly in the User model arrays. I'll try it again.
>
> On Thursday, April 4, 2013 7:43:13 AM UTC-4, Jeremy Burns wrote:
>>
>> You can set a specific key for each flash message and then flash it out
>> where and when needed. See:
>> http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages
>>
>> Jeremy Burns
>> Class Outfit
>>
>> http://www.classoutfit.com
>>
>> On 4 Apr 2013, at 12:37:50, Nathan Pierce <[email protected]> wrote:
>>
>> Fortunately there is no admin role. In fact, if they changed it to
>> teacher, they would just have access to the teacher stuff. Not a security
>> risk fortunately.
>>
>> What I'm trying to do is have two forms on the same page, but them not
>> share the flash verification warnings that come back. Right now if I don't
>> type the email correctly in the register form, the warning tells me in both
>> the login and registration form that the email is not formatted properly.
>> I'd like two separate auth models to post to the same database, but not
>> share the same "email", "password" names to work properly.
>>
>> Can someone point me to some examples or documentation?
>>
>> On Thursday, April 4, 2013 7:32:00 AM UTC-4, André Luis wrote:
>>>
>>> I really didnt get what you want to do, but one thing... if anyone can
>>> register, do not use the hidden field for the role, because it´s value can
>>> be changed easily with some javascript, or even with webdesigner toold. For
>>> example, if I (studant) will register and watch the code in Chrome, with
>>> developer tools, and see the hidden field with que "student" value, i would
>>> try to change the value to "admin" for example, or try another possible
>>> keywords for example.
>>>
>>> Em quarta-feira, 3 de abril de 2013 20h25min51s UTC-3, Nathan Pierce
>>> escreveu:
>>>>
>>>> Hey all! I have to say this community is awesome. I'm pleased to see
>>>> there is help for newbies like me.
>>>>
>>>> I have an issue which I need suggestions for. I like doing things the
>>>> proper way and not creating an obtuse mess of code to do something simple.
>>>> Here it is:
>>>>
>>>> Uses Auth (nothing crazy)
>>>>
>>>> View - register.ctp contains a registration form:
>>>>
>>>> <?php
>>>> echo $this->Form->create('User', array('action' => 'register'));
>>>> echo $this->Form->input('full_name', array('label' => 'Full Name'));
>>>> echo $this->Form->input('email_register', array('label' => 'Email'));
>>>> echo $this->Form->input('password', array('type' => 'password', 'label'
>>>> => 'Password'));
>>>> echo $this->Form->input('password_confirm', array('type' => 'password',
>>>> 'label' => 'Confirm Password'));
>>>> echo $this->Form->hidden('role', array('value' => 'student'));
>>>> echo $this->Form->end('Register');
>>>> ?>
>>>>
>>>> Then, the layout it uses (login.ctp) calls another form:
>>>>
>>>> <?php
>>>> echo $this->Form->create('User', array('action' => 'login'));
>>>> echo $this->Form->input('email', array('label' => false, 'type' =>
>>>> 'email_login', 'value' => '', 'placeholder' => 'Email'));
>>>> echo $this->Form->input('password', array('label' => false, 'type' =>
>>>> 'password_login', 'value' => '', 'placeholder' => 'Password'));
>>>> echo $this->Form->submit('GO', array('class' => 'login_submit'));
>>>> echo $this->Form->end();
>>>> ?>
>>>>
>>>> My problem is that when register.ctp passes the data to the User.php
>>>> model, and does the validation, the login.ctp form gets the 'message =>'
>>>> from the model as well as the register.ctp form.
>>>>
>>>> Now, I need both the register.ctp and login.ctp form to check the
>>>> database if the email exists, run the validation if it's valid, etc etc. I
>>>> think you get the idea. My first idea was to change the login.ctp form
>>>> from
>>>> input('email' to input('email_login' and have it act the same as the
>>>> normal
>>>> email, just ignore the validation message. I looked and looked and
>>>> couldn't
>>>> find any examples of how to achieve this.
>>>>
>>>> Any suggestions?
>>>>
>>>> Thanks!
>>>>
>>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>>
> --
> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected]<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.
>
>
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.