07.04
php
saved
josoroma
Note
user model
user model
- <?php
- class User extends AppModel {
- var $name = 'User';
- 'foreignKey' => 'role_id',
- 'conditions' => '',
- 'fields' => '',
- 'order' => ''
- )
- );
- 'required' => true,
- 'message' => 'Usted debe ingresar al menos tres caracteres.'
- )
- ),
- 'rule' => 'email',
- 'required' => true,
- 'message' => 'Por favor, ingrese una dirección de correo electrónico válida.'
- ),
- 'rule' => 'isUnique',
- 'message' => 'Debe ser única, parece que la dirección de correo electrónico ya existe.'
- )
- ),
- 'rule' => 'alphaNumeric',
- 'required' => true,
- 'message' => 'Solo letras y números.'
- ),
- 'message' => 'Debe tener entre 5 y 25 caracteres.'
- ),
- 'rule' => 'isUnique',
- 'message' => 'Debe ser único, nombre de persona usuaria ya existe.'
- )
- ),
- 'on' => 'create',
- 'message' => 'Debe tener entre 5 y 20 caracteres de largo.'
- ),
- 'on' => 'create',
- 'message' => 'Por favor, ingrese nuevamente la misma contraseña en el campo de confirmar contraseña.'
- ),
- ),
- 'on' => 'update',
- 'allowEmpty' => true,
- 'message' => 'Debe tener entre 5 y 20 caracteres de largo.'
- )
- )
- );
- /**
- * Allows the AclBehavior to determine parental ownership of
- * currently active record.
- *
- * @access public
- * @returns array data array to be used by AclBehavior for node lookup
- */
- function parentNode(){
- if (!$this->id) {
- return null;
- }
- $data = $this->read();
- if (!$data['User']['parent_id']){
- return null;
- } else {
- }
- }
- function beforeSave(){
- $this->setNewPassword();
- return true;
- }
- function afterSave($created = null){
- if( $created ){
- $this->id = $this->getLastInsertId();
- // Primero se crea el alias para el nuevo Aro.
- // AclBehavior no crea un alias de manera automática.
- $this->__createAroAlias($userAliasAndRole);
- } else {
- $this->__updateAclRole();
- }
- return TRUE;
- }
- function __createAroAlias($userAliasAndRole=null) {
- $aroId = $this->Aro->getLastInsertId();
- $this->Aro->create();
- $this->Aro->id = $aroId;
- $aroAliasAndRole['Aro']['alias'] = $userAliasAndRole['User']['username'];
- $aroAliasAndRole['Aro']['parent_id'] = $userAliasAndRole['User']['role_id'];
- if($this->Aro->save($aroAliasAndRole)){
- return TRUE;
- } else {
- return FALSE;
- }
- }
- /**
- * When the parent_id has changed, then need to also change the parent_id field in the
- * matching Aro row.
- *
- * @access private
- */
- function __updateAclRole(){
- if ($this->data['User']['role_id'] != $this->data['User']['old_role_id']){
- 'id' => $userAro['Aro']['id'],
- 'parent_id' => $roleInfo['Aro']['id'],
- 'alias' => $this->data['User']['username']
- )
- );
- $this->Aro->save($updatedAro);
- } else {
- 'id' => $this->id,
- 'parent_id' => $this->data['User']['role_id'],
- 'alias' => $this->data['User']['username']
- )
- );
- $this->Aro->save($updatedAro);
- }
- }
- /**
- * sets the password to be equal to the verified value from the temporary password field
- *
- * Under AuthComponent, any time a form is submitted with a field name that matches the
- * expected password field, it is hashed before any other operation can be done. This
- * prevents the equalTo() rule check from working, so we take the password in a form input
- * named something else. Then after verification, but before saving the record, we pass
- * the hashed value to the correct password field.
- *
- * @return boolean TRUE
- */
- function setNewPassword(){
- $this->data['User']['passwd'] = $this->data['User']['new_passwd_hash'];
- }
- return TRUE;
- }
- /**
- * Overrides core equalTo() to verify that two form fields are equal
- *
- * @param array $field contains the name of the primary field and the value of that field
- * @param string $compare_field contains the name of the field to compare the primary field to
- * @access public
- * @return boolean FALSE if the fields do not match TRUE if they do
- */
- foreach ($field as $key => $value){
- $v1 = $value;
- $v2 = $this->data[$this->name][$compare_field];
- if ($v1 !== $v2) {
- return FALSE;
- } else {
- continue;
- }
- }
- return TRUE;
- }
- }
- ?>
Parsed in 0.394 seconds, using GeSHi 1.0.7.14