/** * Delete session record(s) when delete user login * @param int $user_id */ public function deleteSession($user_id) { // get user login by user Id Zend_Loader::loadClass('Wbusers'); $users = new Wbusers(); $where = $users->getAdapter()->quoteInto('id = ?', $user_id); $row = $users->fetchRow($where); unset($where); if (isset($row->login)) { $where = $this->getAdapter()->quoteInto('login = ?', $row->login); $this->delete($where); } else { throw new Exception(__METHOD__ . ' : User login not found'); } }
public function delete($where, $role_id = null) { if (empty($role_id)) { throw new Exception(__METHOD__ . ' : "Empty input parameters"'); } /* * если есть ссылки из таблиц: webacula_roles или webacula_users * то удаление не производить */ Zend_Loader::loadClass('Wbusers'); $users = new Wbusers(); // $select = $this->select()->where('inherit_id = ?', $role_id)->where('inherit_id != id'); $rows = $this->fetchAll($select); if ($users->fetchRow($this->getAdapter()->quoteInto('role_id = ?', $role_id)) || $rows->count() > 0) { $translate = Zend_Registry::get('translate'); throw new Zend_Exception($translate->_('Can not delete. Role is used.')); } else { /* * delete cascade */ $arr_table = array('WbCommandACL', 'Wbresources', 'WbStorageACL', 'WbPoolACL', 'WbClientACL', 'WbFilesetACL', 'WbJobACL', 'WbWhereACL'); $where_tbl = $this->getAdapter()->quoteInto('role_id = ?', $role_id); foreach ($arr_table as $tbl) { Zend_Loader::loadClass($tbl); $table = new $tbl(); $table->delete($where_tbl); unset($table); } // delete main record return parent::delete($where); } }
public function forgotPasswordAction() { Zend_Loader::loadClass('FormForgotPassword'); $form = new formForgotPassword(); if ($this->_request->isPost()) { /* Проверяем валидность данных формы */ if ($form->isValid($this->_getAllParams())) { $db = Zend_Registry::get('db_bacula'); Zend_Loader::loadClass('Wbusers'); $table = new Wbusers(); // ищем email $select = $table->select()->where('login = ?', $this->_getParam('login'))->where('email = ?', $this->_getParam('email')); $row = $table->fetchRow($select); /* login + email найдены ? */ if ($row) { // генерируем новый пароль $new_password = md5(uniqid(rand())); // высылаем пароль $res = $this->emailForgotPassword($row->email, $row->name, $new_password); if ($res) { // сохраняем пароль в БД if (Zend_Registry::get('DB_ADAPTER') != 'PDO_SQLITE') { // Sqlite do not have MD5 function $new_password = md5($new_password); } $data = array('pwd' => $new_password); $where = $table->getAdapter()->quoteInto('id = ?', $row->id); $table->update($data, $where); // goto home page $this->view->msg = $this->view->translate->_("New password set"); $this->_redirector->gotoSimple('login', 'auth', null, array('from_forgot' => 1)); // action, controller } else { $this->view->msg = $this->view->translate->_("Error while sending email. Email not send"); } } else { sleep(2); // TODO increase this value $this->view->msg = $this->view->translate->_("Username or email is incorrect"); } } } /* Если данные не передавались или неверный логин, то выводим форму для авторизации */ $this->view->title = $this->view->translate->_('Reset password'); $this->view->form = $form; }