本文整理汇总了PHP中Zend_Auth_Adapter_DbTable类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Auth_Adapter_DbTable类的具体用法?PHP Zend_Auth_Adapter_DbTable怎么用?PHP Zend_Auth_Adapter_DbTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Auth_Adapter_DbTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginAction
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;
}
示例2: _getAuthAdapter
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;
}
示例3: login
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');
}
示例4: indexAction
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;
}
示例5: indexAction
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>';
}
}
}
示例6: _getAuthAdapter
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;
}
示例7: loginAction
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'));
}
}
}
}
示例8: indexAction
/**
* Авторизация
*/
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;
}
示例9: indexAction
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();
}
}
}
示例10: getAuthAdapter
/**
* 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;
}
示例11: loginAction
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);
}
示例12: loginAction
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");
}
}
}
}
示例13: 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>');
}
示例14: getAuthAdapter
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;
}
示例15: loginAction
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;
}