Empfehlungen: Erweiterte Suche
ich habe das Passwortfeld umbenannt, so dass cake keinen Wert in inputfeld schreibt.
Im Model ist abr natürlich definiert, dass jeder User ein Passwort haben muss.
// password change check
if (!empty($this->data['User']['new_password'])) {
$this->data['User']['password'] = $this->Auth->password($this->data['User']['new_password']);
} function admin_edit() {
$this->set('title', 'Edit User');
if (!empty($this->data)) {
if (empty($this->data['User']['new_password'])) { # Hat das Feld einen Wert?
unset($this->User->validate['new_password']); # Nein. Ignoriere die Regel.
} else {
$this->data['User']['password'] = $this->Auth->password($this->data['User']['new_password']); # Ja. Verschlüssele den Wert und speicher ihn in der Passwortvariable des Users um später über save() in der Datenbank gespeichert zu werden.
}
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('Preferences saved', true), 'admin_flash_success');
} else {
$this->Session->setFlash(__('Preferences could not be saved. Please check the error messages', true), 'admin_flash_failure');
}
} else {
$this->data = $this->User->find('first', array('conditions' => array('User.id' => $this->Session->read('Auth.User.id')), 'recursive' => 0));
}
} var $validate = array(
'first_name' => array(
array('rule' => 'alphaNumeric'),
VALID_NOT_EMPTY
),
'last_name' => array(
array('rule' => 'alphaNumeric'),
VALID_NOT_EMPTY
),
'username' => array(
array('rule' => 'alphaNumeric'),
VALID_NOT_EMPTY,
array('rule' => array('isUnique'))
),
'email' => array(
array('rule' => 'email'),
VALID_NOT_EMPTY
),
'new_password' => array(
array('rule' => array('identicalFieldValues', 'password2')),
array('rule' => array('minLength', '5'))
)
);
function identicalFieldValues( $field=array(), $compare_field=null ) {
foreach( $field as $key => $value ) {
$v1 = $value;
$v2 = $this->data[$this->name][ $compare_field ];
if($v1 !== $v2) {
return FALSE;
} else {
continue;
}
}
return TRUE;
}<div class="form">
<?php echo $form->create('User');?>
<?php
echo $form->error('first_name', array(
0 => __('First name must contain letters or digits', true),
1 => __('First name must not be empty', true)
)
);
echo $form->error('last_name', array(
0 => __('Last name must contain letters or digits', true),
1 => __('Last name must not be empty', true)
)
);
echo $form->error('username', array(
0 => __('Username must contain letters or digits', true),
1 => __('Username must not be empty', true),
3 => __('Username already in use', true)
)
);
echo $form->error('email', array(
0 => __('E-Mail must be a valid address', true),
1 => __('E-Mail must not be empty', true)
)
);
echo $form->error('new_password', array(
0 => __('Passwords do not match', true),
1 => __('Password must have more than 5 characters', true)
)
);
echo $form->input('id');
echo $form->input('first_name', array('label' => __('First Name', true), 'error' => false));
echo $form->input('last_name', array('label' => __('Last Name', true), 'error' => false));
echo $form->input('username', array('label' => __('Username', true), 'error' => false));
echo $form->input('email', array('label' => __('E-mail', true), 'error' => false));
echo $form->input('new_password', array('type' => 'password', 'value' => '', 'label' => __('Password', true), 'error' => false));
echo $form->input('password2', array('type' => 'password', 'value' => '', 'label' => __('Repeat Password', true), 'error' => false));
echo $form->input('startpage_id', array('empty' => __('Standard behavior', true), 'label' => __('Startpage', true), 'error' => false));
?>
<?php echo $form->end(__('Save', true));?>
</div>
function admin_form($form_action = 'add', $id = null) {
if(!empty($id)){
$user = $this->User->read(null, $id);
$this->set('user', $user);
}
if (!empty($this->data)) {
/* Email pruefen */
if (($form_action == 'add') && ($this->User->findByEmail($this->data['User']['email'])))
{
$this->Session->setFlash(__('Email address already exists', true), 'default', array(), 'info');
}
else
{
$this->User->create();
if ($this->User->save($this->data)) { // hier wird gespeichert, aber das Passwortfeld hat schon den falschen Hash
$this->Session->setFlash(__('The User has been saved', true), 'default', array(), 'info');
if(!empty($id)){
$this->redirect(array('action' => 'view', $id));
}else{
$this->redirect($this->referer());
}
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true), 'default', array(), 'error');
}
}
}else{
$this->data = array();
$this->data['User'] = array();
if(!empty($user)){
$this->data = $user;
}
foreach($this->passedArgs as $fieldName => $value){
$this->data['User'][$fieldName] = $value;
}
}
$groups = $this->User->Group->generateTreeList(null, "{n}.Group.id", "{n}.Group.name", '--', 0);
$this->set(compact('groups'));
$form_url = '/' . $this->params['url']['url'];
$this->set('form_url', $form_url);
$this->set('form_action', $form_action);
}Mitglieder in diesem Forum: 0 Mitglieder und 0 Gäste