/** * @param string $uname * @param string $password * @return bool True iff login attempt was successful */ public function authenticate($uname, $password) { self::$_authAdapter->setIdentity($uname)->setCredential($password); // $zendAuthInstance = Zend_Auth::getInstance(); // $zendAuthInstance->setStorage(new Zend_Auth_Storage_Session('prosecco')); return Zend_Auth::getInstance()->authenticate(self::$_authAdapter)->isValid(); }
public function loginAction() { // action body $request = $this->getRequest(); $form = new Application_Form_Login(); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $bootstrap = $this->getInvokeArg('bootstrap'); $dbAdapter = $bootstrap->getResource('db'); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter, 'user', 'name', 'password'); $data = $form->getValidValues($request->getPost()); $authAdapter->setIdentity($data['name']); $password = sha1($data['password']); $authAdapter->setCredential($password); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $user = $authAdapter->getResultRowObject(null, 'password'); $storage = $auth->getStorage(); $storage->write($user); if ($user->confirmed == 1) { $this->_redirect('dashboard'); // Redirect to dashboard } else { Zend_Auth::getInstance()->clearIdentity(); $this->view->errors = array('You\'re registration is not yet confirmed'); } } else { $form->getElement('password')->addError('Invalid password.'); } } } $this->view->form = $form; }
protected function _getAuthAdapter() { $admins = new Application_Model_DbTable_Admins(); $authAdapter = new Zend_Auth_Adapter_DbTable($admins->getAdapter()); $authAdapter->setTableName('admins')->setIdentityColumn('admin_username')->setCredentialColumn('hashed_password')->setCredentialTreatment('SHA1(?)'); return $authAdapter; }
public static function login($login, $senha) { $dbAdapter = Zend_Db_Table::getDefaultAdapter(); //Inicia o adaptador Zend_Auth para banco de dados $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('users')->setIdentityColumn('login')->setCredentialColumn('password')->setCredentialTreatment('SHA1(?)'); //Define os dados para processar o login $authAdapter->setIdentity($login)->setCredential($senha); //Faz inner join dos dados do perfil no SELECT do Auth_Adapter $select = $authAdapter->getDbSelect(); $select->join('roles', 'roles.id_role = users.id_role', array('role_roles' => 'role', 'id_role')); //Efetua o login $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); //Verifica se o login foi efetuado com sucesso if ($result->isValid()) { //Recupera o objeto do usuário, sem a senha $info = $authAdapter->getResultRowObject(null, 'password'); $usuario = new Application_Model_Users(); $usuario->setFullName($info->nome); $usuario->setUserName($info->login); $usuario->setRoleId($info->role_roles); $usuario->setRoleCod($info->id_role); $storage = $auth->getStorage(); $storage->write($usuario); return true; } throw new Exception('Nome de usuário ou senha inválida'); }
public function indexAction() { $form = new Application_Form_Login(); $request = $this->getRequest(); if ($request->isPost()) { // if ($form->isValid($this->_getAllParams())) if ($form->isValid($request->getPost())) { $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('smo_usuario')->setIdentityColumn('usu_rut')->setCredentialColumn('usu_passwd')->setCredentialTreatment('md5(CONCAT(?,usu_passwd_salt))'); $authAdapter->setIdentity($form->getValue('rut'))->setCredential($form->getValue('pass')); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { // get all info about this user from the login table // ommit only the password, we don't need that $userInfo = $authAdapter->getResultRowObject(null, 'password'); // the default storage is a session with namespace Zend_Auth $authStorage = $auth->getStorage(); $authStorage->write($userInfo); return $this->_helper->redirector->gotoSimple('index', 'index'); //$this->_redirect('view/index/index'); } else { $errorMessage = "Datos Incorrectos, intente de nuevo."; } } } $this->view->form = $form; $this->view->errorMessage = $errorMessage; }
public function indexAction() { $storage = new Zend_Auth_Storage_Session('admin_type'); $data = $storage->read(); if ($data && $data != null) { $this->_redirect('admin/'); } $this->view->messages = $this->_flashMessenger->getMessages(); //$this->_helper->layout()->disableLayout(); $this->_helper->layout()->setLayout('adminlogin'); $users = new Admin_Model_DbTable_AdminUsers(); if ($this->getRequest()->isPost()) { $formdata = $this->getRequest()->getPost(); $enc_pwd = md5($formdata['user_password']); //print_r($formdata);exit; $auth = Zend_Auth::getInstance(); $authAdapter = new Zend_Auth_Adapter_DbTable($users->getAdapter(), TBL_ADMIN); $authAdapter->setIdentityColumn('user_name')->setCredentialColumn('user_password'); $authAdapter->setIdentity($formdata['user_name'])->setCredential($enc_pwd); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $storage = new Zend_Auth_Storage_Session('admin_type'); $storage->write($authAdapter->getResultRowObject()); $this->_redirect('admin/'); } else { $this->view->errorMessage = '<div class="div-error">Invalid username or password</div>'; } } }
protected function _getAuthAdapter() { $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('school_staff')->setIdentityColumn('email')->setCredentialColumn('password')->setCredentialTreatment('md5(?)'); return $authAdapter; }
public function loginAction() { $formLogin = new Form_Admin_Login(); $formLogin->submit->setLabel("Logar"); $this->view->form = $formLogin; if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); if ($formLogin->isValid($data)) { $email = $formLogin->getValue('administrador_email'); $senha = $formLogin->getValue('administrador_senha'); $db = Zend_Registry::get('db'); $authAdapter = new Zend_Auth_Adapter_DbTable($db); $authAdapter->setTableName('administrador')->setIdentityColumn('administrador_email')->setCredentialColumn('administrador_senha')->setIdentity($email)->setCredential(md5($senha)); $authAdapter->getDbSelect()->where("administrador_ativo = ?", 1); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $modelAdministrador = new Model_DbTable_Administrador(); $administrador = $modelAdministrador->getByField("administrador_email", $email); Zend_Auth::getInstance()->getStorage()->write($administrador); $this->_redirect("admin/"); } else { $this->_helper->flashMessenger->addMessage(array('danger' => 'Usuário e/ou senha inválidos')); } } } }
/** * Авторизация */ public function indexAction() { // вывод загаловков $this->view->title = "Авторизация"; $this->view->headTitle($this->view->title, 'PREPEND'); // форма $form = new Application_Form_Auth(); $message = ''; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $auth = Zend_Auth::getInstance(); $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter(), 'users', 'login', 'password'); $data = $form->getValues(); $authAdapter->setIdentity($data['login'])->setCredential($data['password']); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $currentUser = $authAdapter->getResultRowObject(array('id_user', 'login', 'role')); Zend_Auth::getInstance()->getStorage()->write($currentUser); $this->_redirect($data['redirect']); } else { $message = 'Попробуйте еще раз.'; } } } // вывод в шаблон $this->view->message = $message; $this->view->form = $form; }
public function indexAction() { $form = new Login_Form(); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { $authAdapter = new Zend_Auth_Adapter_DbTable(); $authAdapter->setTableName("employees")->setIdentityColumn("login")->setCredentialColumn("password")->setCredentialTreatment("SHA1(CONCAT(?, salt)) && (active = 1 || super_admin = 1)")->setIdentity($form->getValue("login"))->setCredential($form->getValue("password")); $auth = Zend_Auth::getInstance(); if ($auth->authenticate($authAdapter)->isValid()) { $authStorage = $auth->getStorage(); $employee = $authAdapter->getResultRowObject(); $authStorage->write($employee); $db = Zend_Db_Table::getDefaultAdapter(); $data = array("last_login" => date("Y-m-d H:i:s")); $db->update('employees', $data, "employee_id =" . $employee->employee_id); $session = new Zend_Session_Namespace(\Application\Controller\Plugin\Auth::SESSION_NAMESPACE); $uri = $session->referer; if ($uri == "/" || $uri == "/login" || $uri == "/logout") { $this->getHelper("redirector")->gotoSimple("index", "index"); } else { $this->getHelper("redirector")->gotoUrl($uri); } } else { $this->view->formErrors = array("Niepoprawny login lub hasło"); $this->view->data = $form->getUnfilteredValues(); } } else { $this->view->formErrors = $form->getMessages(); $this->view->data = $form->getUnfilteredValues(); } } }
/** * Gets the adapter for authentication against a database table * * @return object */ public static function getAuthAdapter() { $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('cc_subjs')->setIdentityColumn('login')->setCredentialColumn('pass')->setCredentialTreatment('MD5(?)'); return $authAdapter; }
function loginAction() { $form = $this->getForm(); if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $auth = Zend_Auth::getInstance(); // Setup adapter $adapter = new Zend_Auth_Adapter_DbTable($this->_db, 'Extranet_Users', 'EU_Username', 'EU_Password', 'MD5(?)'); $adapter->setIdentity($_POST['username'])->setCredential($_POST['password']); // Authenticate $result = $auth->authenticate($adapter); switch ($result->getCode()) { case Zend_Auth_Result::FAILURE: case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID: case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND: case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS: $error = Cible_Translation::getCibleText('error_auth_failure'); } if (!$result->isValid()) { $this->view->assign('error', $error); } else { $auth->getStorage()->write($adapter->getResultRowObject(array('EU_ID', 'EU_LName', 'EU_FName', 'EU_Email'))); // build ACL rights $data = (array) $auth->getStorage()->read(); $acl = Cible_FunctionsAdministrators::getACLUser($data['EU_ID']); $defaultSession = new Zend_Session_Namespace(); $defaultSession->acl = $acl; $this->_redirect($this->getRequest()->getParam('redirect')); } } } $this->view->assign('form', $form); }
public function loginAction() { //$this->_helper->layout()->disableLayout(); $formAuthLogin = new Form_Auth_Login(); $this->view->form = $formAuthLogin; if ($this->getRequest()->isPost()) { if ($formAuthLogin->isValid($this->getRequest()->getPost())) { $dadosAutenticacao = $formAuthLogin->getValues(); $db = Zend_Registry::get('db'); $authAdapter = new Zend_Auth_Adapter_DbTable($db); try { $authAdapter->setTableName('administrador')->setIdentityColumn('administrador_email')->setCredentialColumn('administrador_senha')->setIdentity($dadosAutenticacao['administrador_email'])->setCredential(md5($dadosAutenticacao['administrador_senha'])); $authAdapter->getDbSelect()->where("administrador_ativo = ?", 1); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $dadosAdministrador = array(); Zend_Auth::getInstance()->getStorage()->write($dadosAdministrador); $this->_redirect("index/"); } else { $this->_helper->flashMessenger->addMessage(array('class' => 'alert alert-danger', 'message' => 'Usuário e/ou senha inválidos!')); Zend_Debug::dump($result); die; $this->_redirect("admin/autenticacao/login"); } } catch (Exception $e) { $this->_helper->flashMessenger->addMessage(array('class' => 'alert alert-danger', 'message' => 'Houve um erro na autenticação - ' . $e->getMessage())); $this->_redirect("auth/login"); } } } }
public static function login($login, $senha) { $dbAdapter = Zend_Db_Table::getDefaultAdapter('db'); // Inicia o adaptador Zend_Auth para banco de dados $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('users')->setIdentityColumn('login')->setCredentialColumn('password')->setCredentialTreatment('SHA1(?) AND active=1'); // Define os dados para processar o login $authAdapter->setIdentity($login)->setCredential($senha); // Efetua o login $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); // Verifica se o login foi efetuado com sucesso if ($result->isValid()) { // Recupera o objeto do usuário, sem a senha $info = $authAdapter->getResultRowObject(null, 'password'); $usuario = new Home_Model_User(); $usuario->setUserId($info->id); $usuario->setName($info->name); $usuario->setLogin($info->login); $usuario->setRoleId($info->role); $storage = $auth->getStorage(); $storage->write($usuario); return true; } throw new Exception('<div class="alert alert-danger">Nome de usuário ou senha inválida</div>'); }
public function getAuthAdapter() { //$authAdapter = new Zend_Auth_Adapter_DbTable ( Zend_Db_Table::getDefaultAdapter () ); $authAdapter = new Zend_Auth_Adapter_DbTable($this->db); $authAdapter->setTableName('employe')->setIdentityColumn('username')->setCredentialColumn('password'); return $authAdapter; }
public function loginAction() { $this->view->pagina_action = "Login"; $this->view->pagina_descricao = "Informe seu usuário e senha para acessar o sistema."; // Instancia o formulário de login $objFormLogin = new Default_Form_Login(); if ($this->_request->isPost()) { $data = $this->getRequest()->getPost(); if ($objFormLogin->isValid($data)) { $objAuth = Zend_Auth::getInstance(); $authAdapter = new Zend_Auth_Adapter_DbTable(Lepard_Db_Adapter::get(), 'usuario', 'login', 'password'); $authAdapter->setIdentity($data['login'])->setCredential($data['password']); //print_r($authAdapter);die; $result = $objAuth->authenticate($authAdapter); if ($result->isValid()) { /** * Pega os dados do usuário, omitindo a senha * http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html */ $authData = $authAdapter->getResultRowObject(null, 'password'); // Armazena os dados do usuário $objAuth->getStorage()->write($authData); echo 'Login efetuado com sucesso!'; $this->getHelper('Redirector')->setGotoUrl('/index'); } else { echo 'Os dados informados (login/senha) não são válidos.'; } } } $this->view->form = $objFormLogin; }
public function loginAction() { //Desabilita renderização da view $this->_helper->viewRenderer->setNoRender(); //Obter o objeto do adaptador para autenticar usando banco de dados $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); //Seta qual tabela e colunas procurar o usuário $authAdapter->setTableName('usuario')->setIdentityColumn('login')->setCredentialColumn('senha'); //Seta as credenciais com dados vindos do formulário de login $authAdapter->setIdentity($this->_getParam('login'))->setCredential($this->_getParam('senha'))->setCredentialTreatment('MD5(?)'); //Realiza autenticação $result = $authAdapter->authenticate(); //Verifica se a autenticação foi válida if ($result->isValid()) { //Obtém dados do usuário $usuario = $authAdapter->getResultRowObject(); //Armazena seus dados na sessão $storage = Zend_Auth::getInstance()->getStorage(); $storage->write($usuario); //Redireciona para o Index $this->_redirect('index'); } else { $this->_redirect('autenticacao/falha'); } }
/** * IS: Parameter username, password, remember terdeklarasi * FS: Mengirimkan ke viewer: fail, * Session berisi data userId dan username * Desc: Fungsi untuk login biasa */ public function indexAction() { $this->_helper->viewRenderer->setNoRender(true); // Jika request ajax //if ($this->_request->isXmlHttpRequest()) { // Tidak menggunakan layout dan view $this->_helper->layout()->disableLayout(); $loginForm = new Form_LoginForm(); if ($this->getRequest()->isPost() and $loginForm->isValid($this->getRequest()->getPost())) { // Param $username = $this->_getParam('username'); $password = $this->_getParam('password'); $remember = $this->_getParam('remember'); // Menggunakan auth adapter bawaan Zend $db = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($db, "user", 'username', 'password'); // Set username dan password $authAdapter->setIdentity($username); $authAdapter->setCredential(md5($password)); // Authentikasi $result = $authAdapter->authenticate(); // Jika ada if ($result->isValid()) { // Menggunakan auth adapter bawaan Zend $db = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($db, "user", 'username', 'password', 'activationkey'); // Set username dan password $authAdapter->setIdentity($username); $authAdapter->setCredential(md5($password)); // Authentikasi $result = $authAdapter->authenticate(); $auth = Zend_Auth::getInstance(); $storage = $auth->getStorage(); $storage->write($authAdapter->getResultRowObject(array('user_id', 'username', 'activationkey'))); $identity = $auth->getIdentity(); if ($this->_hasParam('remember')) { $expire = time() + 1728000; // 20 hari expired $cookiePass = sha1(md5($password) . $identity->activationkey); setcookie('budpar_userId', $identity->user_id, $expire, '/'); setcookie('budpar_user', $identity->username, $expire, '/'); setcookie('budpar_pass', $cookiePass, $expire, '/'); } // Set Blacklist jika ada $this->_setBlacklist($identity->user_id); // Set nilai session $this->_sess->userId = $identity->user_id; $this->_sess->username = $identity->username; //echo 'success'; } else { echo 'fail'; $this->view->fail = true; $this->_sess->error = true; } } else { echo 'fail'; $this->view->fail = true; } $this->_redirector->gotoUrl($this->_sess->previousUri); }
/** * @return boolean */ public function validate() { $this->actionController->oAcl->getStorage()->clear(); if (!parent::validate()) { return false; } $sUserLogin = $this->controls['login']->getValue(); $sUserPassword = $this->controls['password']->getValue(); $oAuth = Zend_Auth::getInstance(); $oAuthAdapter = new Zend_Auth_Adapter_DbTable(); $oAuthAdapter->setTableName('user')->setIdentityColumn('login')->setCredentialColumn('password')->setCredentialTreatment('MD5(?)'); $oAuthAdapter->setIdentity($sUserLogin)->setCredential($sUserPassword); $oSelect = $oAuthAdapter->getDbSelect(); $oSelect->where('user.deleted = ?', 'no')->joinLeft('client', 'client.id = user.client', array('client_title' => 'client.title')); $oResult = $oAuth->authenticate($oAuthAdapter); if ($oResult->isValid()) { $aResult = (array) $oAuthAdapter->getResultRowObject(); $aResult['role'] = $aResult['is_admin'] == 0 ? 'user' : 'admin'; $oAuth->getStorage()->write($aResult); return true; } else { $this->errors[] = 'Invalid login or password'; return false; } }
public static function validate($username, $hash, $rememberme = false) { if (!$username) { return false; } // TODO: try to make only one sql request $adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($adapter, 'users', 'pseudo', 'password'); $authAdapter->setIdentity($username)->setCredential($hash); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if (!$result->isValid()) { self::$_current = null; return false; } $userid = $authAdapter->getResultRowObject('id')->id; $userMapper = new Syj_Model_UserMapper(); $user = new Syj_Model_User(); if (!$userMapper->find($userid, $user)) { throw new Zend_Exception(); } $request = Zend_Controller_Front::getInstance()->getRequest(); if (!$request->getCookie('syj_user') or !$request->getCookie('syj_hashpass')) { if ($rememberme) { // cookie will be valid for 2 weeks $time = time() + 14 * 60 * 24 * 60; } else { $time = 0; } setcookie("syj_user", $username, $time, "", "", false, true); setcookie("syj_hashpass", $hash, $time, "", "", false, true); } self::$_current = $user; return true; }
/** * * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed * @return Zend_Auth_Result * @see Zend_Auth_Adapter_Interface::authenticate() */ public function authenticate() { $result = array('code' => Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, 'identity' => null, 'messages' => array()); /** @var Zend_Config */ $config = Zend_Registry::get('config'); if (isset($config['admin']['pass']) && $this->_data['code'] == $config['admin']['pass'] && $this->_data['email'] == 'admin') { $result['code'] = Zend_Auth_Result::SUCCESS; $result['identity'] = new Reg2_Model_Identity('admin'); Zend_Registry::get('log')->info('Admin login from ' . $_SERVER['REMOTE_ADDR']); return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']); } $this->_dbauth->setIdentity($this->_data['email'])->setCredential($this->_data['code']); $dbresult = $this->_dbauth->authenticate(); if ($dbresult->isValid()) { $result['code'] = Zend_Auth_Result::SUCCESS; $user = $this->_dbauth->getResultRowObject(); $result['identity'] = new Reg2_Model_Identity($user->role, $user); Zend_Registry::get('log')->info(sprintf("Login with '%s' as '%s'(%d) from %s", $this->_data['email'], $user->role, $user->tid, $_SERVER['REMOTE_ADDR'])); } else { $result['code'] = $dbresult->getCode(); $result['messages'] = $dbresult->getMessages(); Zend_Registry::get('log')->info(sprintf("Login attempt: %d from %s", $dbresult->getCode(), $_SERVER['REMOTE_ADDR'])); } return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']); }
public function authAction() { $request = $this->getRequest(); $registry = Zend_Registry::getInstance(); $auth = Zend_Auth::getInstance(); $DB = $registry['DB']; $authAdapter = new Zend_Auth_Adapter_DbTable($DB); $authAdapter->setTableName('fitness_admin_accounts')->setIdentityColumn('admin_username')->setCredentialColumn('admin_password'); // Set the input credential values $uname = $request->getParam('user_username'); $paswd = $request->getParam('user_password'); $authAdapter->setIdentity($uname); $authAdapter->setCredential(md5($paswd)); // Perform the authentication query, saving the result $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $data = $authAdapter->getResultRowObject(null, 'password'); $auth->getStorage()->write($data); $sess = new Zend_Session_Namespace('AdminSession'); if ($sess->isLocked()) { $sess->unlock(); } $sess->username = $uname; $this->_redirect('/admin/homeuser'); } else { $this->_redirect('/admin/index'); } }
protected function _getAuthAdapter() { $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('users')->setIdentityColumn('username')->setCredentialColumn('password')->setCredentialTreatment('SHA1(CONCAT(?,salt))'); return $authAdapter; }
public function loginAction() { $this->_helper->layout->disablelayout(); $authorization = Zend_Auth::getInstance(); $identity = $authorization->getIdentity(); if ($authorization->hasIdentity()) { $this->redirect("categories/list"); } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getParams(); $db = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password'); $authAdapter->setIdentity($data['username']); $authAdapter->setCredential(md5($data['password'])); $result = $authAdapter->authenticate(); if ($result->isValid()) { $active = (new Application_Model_Users())->getUserByUsername($data['username'])[0]['active']; if ($active) { $auth = Zend_Auth::getInstance(); $storage = $auth->getStorage(); $storage->write($authAdapter->getResultRowObject(array('f_name', 'username', 'id', 'user_type'))); $authorization = Zend_Auth::getInstance(); $identity = $authorization->getIdentity(); $this->view->identity = $identity; $this->redirect('categories/list'); } else { $this->view->user_msg = "The page not allowed for normal user."; $this->redirect("users/login"); } } } $form = new Application_Form_Login(); $this->view->form = $form; }
public function loginAction() { // // set template login $template_path = TEMPLATE_PATH . "/default/before"; $this->loadTemplate($template_path, 'template.ini', 'default'); $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $this->_redirect(HOST_PATH_PUBLIC); } if ($this->_request->isPost()) { $authTable = new Zend_Auth_Adapter_DbTable(); // tao adapter $authTable->setTableName('user')->setIdentityColumn('email')->setCredentialColumn('password'); //cot du lieu 2 $fname = $this->_request->getPost('email'); $fpass = $this->_request->getPost('password'); $fpass = md5($fpass); $authTable->setIdentity($fname)->setCredential($fpass); $authTable->getDbSelect(); $auth = Zend_Auth::getInstance(); $kq = $auth->authenticate($authTable); if ($kq->isValid()) { $user = $authTable->getResultRowObject(null, array("password")); $auth->getStorage()->write($user); $this->_redirect(HOST_PATH_PUBLIC); } else { $this->_redirect(HOST_PATH_PUBLIC . '/index/login'); } } }
public function loginAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $formLogin = new Application_Form_Login(); if ($this->getRequest()->isPost()) { foreach ($this->_request->getPost('dataPost') as $dataArray) { $name = $dataArray['name']; $formDataForValidation["{$name}"] = $dataArray['value']; } if ($formLogin->isValid($formDataForValidation)) { $user = $formDataForValidation['email']; $password = $formDataForValidation['password']; $adapter = new Zend_Auth_Adapter_DbTable(null, 'users', 'email', 'password'); $adapter->setIdentity($user); $adapter->setCredential($password); Zend_Session::regenerateId(); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($adapter); if ($result->isValid()) { $user = $adapter->getResultRowObject(); $auth->getStorage()->write($user); $this->_helper->json(0); } else { $this->_helper->json(1); } } else { $this->_helper->json(1); } } }
public function indexAction() { $filter = new Zend_Filter_StripTags(); $login = trim($filter->filter($this->_request->getPost('login'))); $senha = trim($filter->filter($this->_request->getPost('senha'))); $uri = str_replace('kahina/', '', base64_decode($this->_request->getParam('u', base64_encode('painel/index')))); if (empty($login) || empty($senha)) { $this->view->message = 'Por favor, informe seu Usuário e Senha.'; return; } else { $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('login')->setIdentityColumn('login')->setCredentialColumn('senha'); $authAdapter->setIdentity($this->_getParam('login'))->setCredential($this->_getParam('senha'))->setCredentialTreatment('MD5(?)'); $result = $authAdapter->authenticate(); if ($result->isValid()) { $user = $authAdapter->getResultRowObject(); $storage = My_Auth::getInstance('Painel')->getStorage(); $storage->write($user); $this->_redirect($uri); } else { $this->view->error = 'Você deve informar Login e Senha.'; } } $this->render(); }
/** * Gets the adapter for authentication against a database table * * @return object */ protected function getAuthAdapter() { $dbAdapter = Zend_Db_Table::getDefaultAdapter(); $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter); $authAdapter->setTableName('login')->setIdentityColumn('username')->setCredentialColumn('password')->setCredentialTreatment('MD5(?)'); return $authAdapter; }
public function loginAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $storage = new Zend_Auth_Storage_Session(); $storage->clear(); } $users = new Application_Model_User(); $form = new Application_Form_Login(); $this->view->form = $form; if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); $auth = Zend_Auth::getInstance(); $authAdapter = new Zend_Auth_Adapter_DbTable($users->getAdapter(), 'user'); $authAdapter->setIdentityColumn('name')->setCredentialColumn('password'); $authAdapter->setIdentity($data['name'])->setCredential($data['password']); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $storage = new Zend_Auth_Storage_Session(); $storage->write($authAdapter->getResultRowObject(array('id', 'name', 'image'))); if ($auth->getIdentity()->name == 'admin') { $this->redirect("Order/adminhome"); } elseif ($auth->getIdentity()->name != 'admin') { $this->redirect("Order/adduserorder"); } } else { $this->view->errorMessage = "Invalid username or password. Please try again."; } } } }
public function processAction() { $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('dbAdapter')); $authAdapter->setTableName('user')->setIdentityColumn('username')->setCredentialColumn('password')->setIdentity($_POST['username'])->setCredential($_POST['password']); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); $data = array(); if ($result->isValid()) { unset($this->_session->messages); $identity = $auth->getIdentity(); $user = new User(); $user->username = $identity; $user->populateWithUsername(); Zend_Auth::getInstance()->getStorage()->write($user); //$this->_redirect('login/complete'); //$this->_forward('index','main'); $data['msg'] = __("Login successful."); $data['code'] = 200; } else { $auth->clearIdentity(); $this->_session->messages = $result->getMessages(); //$this->_redirect('login'); $data['err'] = __("Invalid username/password."); $data['code'] = 404; } header('Content-Type: application/xml;'); $this->view->data = $data; $this->completeAction(); //$this->render(); }