public function beforeSave($options = array()) { /* password hashing */ if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } }
public function install() { //TODO check if tables are present in db. If not, trigger schema create --plugin Backend // setup default backend user groups $groups = array('superuser' => array('name' => 'Superuser', 'root' => true), 'admin' => array('name' => 'Administrator', 'root' => false)); $BackendUserGroup = ClassRegistry::init('Backend.BackendUserGroup'); foreach ($groups as &$group) { $BackendUserGroup->create(); if (!$BackendUserGroup->save(array('BackendUserGroup' => $group))) { $this->out('<warning>Failed to create Backend User Group ' . $group['name'] . '</warning>'); } else { $this->out('<success>Created Backend User Group ' . $group['name'] . '</success>'); } } // setup superuser $superGroup = $BackendUserGroup->find('first', array('conditions' => array('BackendUserGroup.root' => true))); if (!$superGroup) { $this->error('No root BackendUserGroup found'); } $email = $this->in('Superuser email:', '', '*****@*****.**'); $superuser = array('backend_user_group_id' => $superGroup['BackendUserGroup']['id'], 'username' => 'superuser', 'password' => AuthComponent::password('superPass'), 'first_name' => 'John', 'last_name' => 'Doe', 'mail' => $email, 'published' => true); $BackendUser = ClassRegistry::init('Backend.BackendUser'); if (!$BackendUser->save(array('BackendUser' => $superuser), true)) { $this->out('<warning>Failed to create Backend Superuser</warning>'); } else { $this->out('<success>Superuser created (Password: superPass)</success>'); } }
public function beforeSave($options = array()) { //when password field if (isset($this->data[$this->alias]['password']) && isset($this->data[$this->alias]['password2'])) { if (empty($this->data[$this->alias]['password']) && empty($this->data[$this->alias]['password2'])) { unset($this->data[$this->alias]['password']); unset($this->data[$this->alias]['password2']); } elseif (!empty($this->data[$this->alias]['password'])) { if ($this->data[$this->alias]['password'] != $this->data[$this->alias]['password2']) { $this->invalidate('password', __d('backend', "The passwords do not match")); $this->invalidate('password2', __d('backend', "The passwords do not match")); $this->data[$this->alias]['password2'] = null; return false; } } } elseif (isset($this->data[$this->alias]['password'])) { $this->invalidate('password', __d('backend', 'Password verification not submitted')); $this->invalidate('password2', __d('backend', 'Password verification not submitted')); return false; } if (isset($this->data[$this->alias]['password']) && !empty($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } return true; }
public function index() { if ($this->Auth->user('id')) { $user = $this->User->findById($this->Auth->user()); $this->set('user', $user); if ($this->request->is('post')) { $req = $this->request->data; if ($user['User']['password'] == AuthComponent::password($req['User']['old_password'])) { if ($req['User']['password'] == $req['User']['password_verify']) { $user['User']['password'] = $req['User']['password']; if ($this->User->save($user)) { $this->Session->setFlash('New Password Saved!'); } else { $this->Session->setFlash('The new passwords didn\'t match.'); } } else { $this->Session->setFlash('The new passwords didn\'t match.'); } } else { $this->Session->setFlash('The old password you entered was incorrect'); } } } else { $this->redirect('/login'); } }
function save_user($data = null) { $user_id = ""; if (isset($data['User']['parent_id']) && $data['User']['parent_id'] == "") { $data['User']['parent_id'] = 0; } if (isset($data['User']['is_dealer']) && $data['User']['is_dealer'] == "") { $data['User']['is_dealer'] = 0; } if (isset($data['User']['role_id']) && $data['User']['role_id'] == 2) { //|| ($data['User']['role_id'] == 3) } else { unset($data['User']['selling_price_limit']); } if (!empty($data['User']['powd'])) { $data['User']['powd'] = AuthComponent::password(AuthComponent::password($data['User']['powd'])); } if (isset($data['User']['id']) && trim($data['User']['powd'] == "")) { unset($data['User']['powd']); } if ($this->saveAll($data)) { if (isset($data['User']['id']) && !empty($data['User']['id'])) { $user_id = $data['User']['id']; } else { $user_id = $this->getLastInsertId(); } } return $user_id; }
public function beforeSave($options = array()) { parent::beforeSave($options); if (isset($this->data['User']['password'])) { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); } }
public function beforeSave($options = array()) { if (!empty($this->data['User']['image'])) { if ($this->data['User']['image']['size'] != 0) { $fileData = $this->resizeImage(512, $this->data['User']['image']['tmp_name']); if (!isset($fileData)) { $fileData = fread(fopen($this->data['User']['image']['tmp_name'], 'r'), $this->data['User']['image']['size']); } // debug($fileData); // throw new Exception; $this->data['User']['image_type'] = $this->data['User']['image']['type']; $this->data['User']['image'] = $fileData; } else { $this->data['User']['image'] = null; $this->data['User']['image_extension'] = null; } } //App::import('Component','Auth'); //$AuthComponent = new AuthComponent(new ComponentCollection); //AuthComponent->password($this->data['User']['password']) if (isset($this->data[$this->alias]['password']) && strlen(trim($this->data[$this->alias]['password'])) != 0) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data['User']['password']); } else { unset($this->data['User']['password']); } return true; }
/** * Hash passwords * @see Model::beforeSave() */ public function beforeSave($options = array()) { if (!empty($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } return TRUE; }
public function change_password($id = null) { $this->set('subid', 'change_pass'); $this->set('titulo', 'Usuários'); $this->set('subtitulo', ''); $this->loadModel('Group'); $erros = array(); if ($this->request->is('post')) { $currentpass = $this->Auth->password($this->request->data['User']['current_password']); $exists = $this->User->findByUsernameAndPassword($this->Auth->user('username'), $currentpass); if (!$exists) { $this->Session->setFlash('Senha Errada', 'flash_custom', array('type' => 'error')); return; } $pass = $this->request->data['User']['password']; if ($pass != $this->request->data['User']['password_confirm']) { $this->Session->setFlash('A senha e a confirmação precisam ser iguais', 'flash_custom', array('type' => 'error')); return; } $novocurso = array('password' => $this->Auth->password($pass)); $this->User->id = $this->Auth->user('id'); if ($this->User->save($novocurso, false) && !count($erros)) { $this->Session->setFlash('Senha trocada com sucesso', 'flash_custom', array('type' => 'success')); $this->redirect(array('controller' => 'Users', 'action' => 'index')); } else { $erros = array_merge($erros, $this->User->validationErrors); $this->set('user', $novocurso); } } if (count($erros)) { $this->Session->setFlash('O formulário contém erros', 'flash_custom', array('type' => 'error')); } $this->set('erros', $erros); }
public function beforeSave($options = array()) { if (isset($this->data['CloggyUser']['user_password']) && !empty($this->data['CloggyUser']['user_password'])) { $this->data['CloggyUser']['user_password'] = AuthComponent::password($this->data['CloggyUser']['user_password']); } return true; }
public function recover() { $this->autoRender = false; $email = $this->param('email'); $this->loadModel('User'); $usr = $this->User->findByEmail($email); if ($usr) { $this->User->create(); $this->User->id = $usr['User']['id']; $mail = $this->PHPMailer->getPHPMailer(); $nova = $this->randomPassword(); $this->User->saveField('password', AuthComponent::password($nova)); $mail->AddAddress($email); $mail->SetFrom('*****@*****.**', 'Website'); $mail->Subject = utf8_decode("Recuperação de Senha"); $mail->MsgHTML("Sua nova senha: {$nova}"); $sent = $mail->Send(); if (!$sent) { echo json_encode(new Message(0, 'E-mail nao pode ser enviado')); return; } echo json_encode(new Message(1, 'Nova senha enviada para seu email')); return; } echo json_encode(new Message(0, 'Erro ao recuperar sua senha')); return; }
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; }
public function change_password() { if ($this->request->is('post')) { $old_pass = AuthComponent::password($this->data['Admin']['old_password']); $check_exist = $this->Admin->findByPassword($old_pass); if ($check_exist) { $update_new_pass = array(); $update_new_pass['Admin']['id'] = $this->activeUser['User']['id']; $update_new_pass['Admin']['password'] = $this->data['Admin']['new_password']; if ($this->Admin->save($update_new_pass)) { // Display success message and redirect $this->Session->setFlash('Password changed successfully.', 'default', array('class' => 'alert alert-success'), 'success'); $this->redirect(array('controller' => 'home', 'action' => 'index')); } else { // Display failure message and redirect $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error'); $this->redirect(array('controller' => 'admins', 'action' => 'change_password')); } } else { // Display failure message and redirect $this->Session->setFlash('Invalid current password.', 'default', array('class' => 'alert alert-danger'), 'error'); $this->redirect(array('controller' => 'admins', 'action' => 'change_password')); } } // Set the view variables to controller variable values and layout for the view $this->set('page_title', 'Change Password'); $this->layout = "base_layout"; }
/** * beforeSave callback * Check if user name is unique and allowed in aro * Encrypt password * * @param array model options * @access public * @return boolean */ public function beforeSave($options = array()) { App::uses('Aro', 'Model'); $this->Aro = new Aro(); // alias = user name , must be unique $this->Aro->validate = array('alias' => array('rule' => 'isUnique', 'message' => __('This name is restricted by system.'))); $aro = $this->Aro->findByForeignKey($this->id); if ($aro) { $aro['Aro']['alias'] = $this->data['User']['name']; $aro = $aro['Aro']; $this->Aro->set($aro); } if ($aro && !$this->Aro->validates($aro)) { $errors = $this->Aro->validationErrors; $this->data = null; return false; } // crypt and truncate password if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password(substr($this->data[$this->alias]['password'], 0, 8)); } // truncate username if (isset($this->data[$this->alias]['username'])) { $this->data[$this->alias]['username'] = substr($this->data[$this->alias]['username'], 0, 8); } return true; }
/** * Cada vez que um um usuario for salvo, faz hash da senha dele, que sera * gravada no banco * @return boolean */ public function beforeSave() { if (isset($this->data[$this->alias]['senha'])) { $this->data[$this->alias]['senha'] = AuthComponent::password($this->data[$this->alias]['senha']); } return true; }
public function beforeSave($options = array()) { if (!empty($this->data['User']['password'])) { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); } return true; }
public function edit($id = null) { if ($this->Auth->user('role') == 'admin') { if (!$id) { $this->Session->setFlash('Please provide a user id'); $this->redirect(array('action' => 'index')); } $user = $this->User->findById($id); if (!$user) { $this->Session->setFlash('Invalid User ID Provided'); $this->redirect(array('action' => 'index')); } if ($this->request->is('post') || $this->request->is('put')) { $this->User->id = $id; $this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password_update']); if ($this->User->save($this->request->data)) { $this->Session->setFlash(__('The user has been updated')); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('Unable to update your user.')); } } if (!$this->request->data) { $this->request->data = $user; } } else { $use = $this->Auth->user('username'); $this->Session->setFlash(__($use . ' are not edited an other user,required an admin\'s user')); } }
public function beforeFilter() { if (isset($this->request->data['User']['password']) && !empty($this->request->data['User']['password'])) { $this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']); } /* if (isset($this->request->data['User']['password'])) { $this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']); } */ $this->currentUser = ""; if ($this->Session->read('Auth.User.id')) { $this->currentUser = $this->Session->read('Auth.User'); } if (isset($this->currentUser['group_id'])) { if (in_array($this->currentUser['group_id'], array(1, 2))) { $this->layout = 'defaultAdmins'; } } $this->set('currentUser', $this->currentUser); $this->loadModel('SiteConstant'); $dataEmptyMessage = $this->SiteConstant->field('value', array('siteConstant' => 'DATA_EMPTY_MESSAGE')); $this->set('dataEmptyMessage', $dataEmptyMessage); return true; }
/** * callback function * * @return void. */ public function beforeSave() { if (isset($this->data['User']['password'])) { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); } return true; }
public function admin_login() { //prd(AuthComponent::password('123456')); $this->set('title_for_layout', 'Admin Login'); $this->layout = "admin_login"; //if already logged-in, redirect if ($this->Session->check('Auth.Admin')) { $this->redirect($this->Auth->loginRedirect); } if ($this->request->is('post')) { $data = $this->request->data; //pr($data); $this->Auth->authenticate = array('Form' => array('userModel' => 'User', 'fields' => array('username' => 'email', 'password' => 'password'))); $userInfo = $this->User->find('first', array('conditions' => array('email' => $data['User']['email'], 'password' => AuthComponent::password($data['User']['password']), 'role_id' => 0))); //prd($userInfo); if (isset($userInfo['User'])) { if ($userInfo['User']['status'] == 0) { $this->Session->setFlash(__('Your account is disabled.'), 'flash_error'); $this->redirect($this->Auth->loginAction); } if ($userInfo['User']['status'] == 1) { $this->Auth->login($userInfo['User']); $_schoolMeta = array('_currentYear' => 'YEAR' . date('Y')); $this->Session->write('SchoolMeta', $_schoolMeta); $this->Session->setFlash(__('Welcome, ' . $this->Session->read('Auth.Admin.fname') . " " . $this->Session->read('Auth.Admin.lname')), 'flash_success'); $this->redirect($this->Auth->redirectUrl()); } } else { $this->Session->setFlash(__('Invalid username or password'), 'flash_error'); } } }
public function beforeSave() { parent::beforeSave(); if (!empty($this->data['User']['password'])) { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); } return true; }
public function beforeSave($options = array()) { if (!empty($this->data[$this->alias]['password'])) { App::uses('AuthComponent', 'Controller/Component'); $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } parent::beforeSave($options); }
public function beforeSave($options = array()) { parent::beforeSave($options); if (!empty($this->data[$this->alias]['a_password'])) { $this->data[$this->alias]['a_password'] = AuthComponent::password($this->data[$this->alias]['a_password']); } return true; }
public function beforeSave() { // パスワードは暗号化して保存する if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } return true; }
/** validate only run through Model->save() or Model->validates() */ function validateConfirmPassword($data) { if ($this->data['User']['password'] == AuthComponent::password($this->data['User']['repeat_password'])) { return true; } // fi return false; }
/** * Before save method. * * @param Model $Model Model instance * @param array $options Options passed from Model::save(). * @return boolean true to continue, false to abort the save */ public function beforeSave(Model $Model, $options = array()) { // Hash the password field before saving if (isset($Model->data[$Model->alias][$this->settings['passwordField']])) { $Model->data[$Model->alias][$this->settings['passwordField']] = AuthComponent::password($Model->data[$Model->alias][$this->settings['passwordField']]); } return true; }
public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } $this->data['User']['resetkey'] = Security::hash(mt_rand(), 'md5', true); return true; }
public function beforeSave($options = array()) { // encrypt the password before savig user info if (isset($this->data['User']['password'])) { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); } return true; }
public function afterFind($results, $primary = false) { foreach ($results as $key => $result) { if (isset($results[$key][$this->alias]['code']) && strlen(trim($results[$key][$this->alias]['code'])) != 0) { $results[$key][$this->alias]['code'] = AuthComponent::password($results[$key][$this->alias]['code']); } } return $results; }
/** * Before Save * @param array $options * @return boolean */ public function beforeSave($options = array()) { // hash our password if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); } // fallback to our parent return parent::beforeSave($options); }