本文整理汇总了PHP中Zend_Auth_Adapter_DbTable::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Auth_Adapter_DbTable::authenticate方法的具体用法?PHP Zend_Auth_Adapter_DbTable::authenticate怎么用?PHP Zend_Auth_Adapter_DbTable::authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Auth_Adapter_DbTable
的用法示例。
在下文中一共展示了Zend_Auth_Adapter_DbTable::authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
*
* @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']);
}
示例2: indexAction
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();
}
示例3: logarAction
/**
*
*/
public function logarAction()
{
$resposta = array();
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout();
$dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('sca_usuario')->setIdentityColumn('login_usuario')->setCredentialColumn('password_usuario');
$authAdapter->setIdentity($this->getRequest()->getParam('login_usuario'))->setCredential($this->getRequest()->getParam('password_usuario'))->setCredentialTreatment('MD5(?) and st_usuario = 1');
//Realiza autenticacao
$result = $authAdapter->authenticate();
//Verifica se a autenticacao foi validada
if ($result->isValid()) {
//obtem os dados do usuario
$usuario = $authAdapter->getResultRowObject();
//Armazena seus dados na sessao
$storage = Zend_Auth::getInstance()->getStorage();
$storage->write($usuario);
//Redireciona para o Index
$resposta['situacao'] = "sucess";
$resposta['msg'] = "Logando aguarde...";
} else {
$resposta['situacao'] = "error";
$resposta['msg'] = "Usuário inativo ou senha incorreta, favor contate ao administrador.";
}
echo json_encode($resposta);
}
示例4: loginAction
public function loginAction()
{
$userForm = new Form_LoginForm();
$userForm->setAction('/auth/login');
if ($this->_request->isPost() && $userForm->isValid($_POST)) {
$data = $userForm->getValues();
$db = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'utils', 'username', 'source');
$authAdapter->setIdentity($data['username']);
$authAdapter->setCredential($data['password']);
$result = $authAdapter->authenticate();
if ($result->isValid()) {
$auth = Zend_Auth::getInstance();
$data1 = $authAdapter->getResultRowObject(null, 'source');
// $auth->getStorage()->write($data1);
// $auth->getStorage()->write($data);
$dom = $auth->getIdentity()->domainadmin;
$host = $auth->getIdentity()->hostadmin;
$mySession = SessionWrapper::getInstance();
$mySession->setSessVar('username', $formData['username']);
date_default_timezone_set('Europe/Brussels');
echo 'valid';
} else {
$this->view->loginMessage = "Sorry, your username or password was incorrect";
}
}
$this->view->form = $userForm;
}
示例5: authenticate
public static function authenticate(array $values)
{
$email = isset($values['email']) ? $values['email'] : null;
$senha = isset($values['senha']) ? $values['senha'] : null;
if (!count($values)) {
throw new Exception('Não foi passado valores para autenticar');
}
// Pegar os dados da autenticacao e checa
$dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('usuario')->setIdentityColumn('email')->setCredentialColumn('senha');
$authAdapter->setIdentity($email)->setCredential($senha)->setCredentialTreatment('MD5(?)');
$select = $authAdapter->getDbSelect();
$select->join(array('g' => 'grupo'), 'g.id = usuario.grupo_id', array('grupo' => 'nome'));
//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
return true;
}
return false;
}
示例6: loginAction
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;
}
示例7: logarAction
public function logarAction()
{
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout();
$resposta = array();
$dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('sca_usuario')->setIdentityColumn('login_usuario')->setCredentialColumn('password_usuario')->getDbSelect()->join(array('g' => 'sca_grupo'), 'g.id_grupo = sca_usuario.id_grupo', array('nm_grupo', 'is_root'));
$authAdapter->setIdentity($this->getRequest()->getParam('login_usuario'))->setCredential($this->getRequest()->getParam('password_usuario'))->setCredentialTreatment('MD5(?) and st_usuario = 1');
//Realiza autenticacao
$result = $authAdapter->authenticate();
//Verifica se a autenticacao foi validada
if ($result->isValid()) {
//obtem os dados do usuario
$usuario = $authAdapter->getResultRowObject();
//Armazena seus dados na sessao
$storage = Zend_Auth::getInstance()->getStorage();
$storage->write($usuario);
// se não for para lembrar os dados expira a sessao em 30 minutos
if (!$this->getRequest()->getParam('lembrar')) {
$session = new Zend_Session_Namespace('Zend_Auth');
$session->setExpirationSeconds(1800);
}
//Redireciona para o Index
$resposta['situacao'] = "success";
$resposta['msg'] = "Logando aguarde...";
} else {
$resposta['situacao'] = "error";
$resposta['msg'] = "Usuário inativo ou senha incorreta.";
}
echo json_encode($resposta);
}
示例8: testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsSet
/**
* Test to see same usernames with different passwords can authenticate when
* a flag is set
*
* @group ZF-7289
*/
public function testEqualUsernamesDifferentPasswordShouldAuthenticateWhenFlagIsSet()
{
$this->_db->insert('users', array (
'username' => 'my_username',
'password' => 'my_otherpass',
'real_name' => 'Test user 2',
));
// test if user 1 can authenticate
$this->_adapter->setIdentity('my_username')
->setCredential('my_password')
->setAmbiguityIdentity(true);
$result = $this->_adapter->authenticate();
$this->assertFalse(in_array('More than one record matches the supplied identity.',
$result->getMessages()));
$this->assertTrue($result->isValid());
$this->assertEquals('my_username', $result->getIdentity());
$this->_adapter = null;
$this->_setupAuthAdapter();
// test if user 2 can authenticate
$this->_adapter->setIdentity('my_username')
->setCredential('my_otherpass')
->setAmbiguityIdentity(true);
$result2 = $this->_adapter->authenticate();
$this->assertFalse(in_array('More than one record matches the supplied identity.',
$result->getMessages()));
$this->assertTrue($result->isValid());
$this->assertEquals('my_username', $result->getIdentity());
}
示例9: login
public function login()
{
if ($this->_router->isPostRequest()) {
if ($_POST['login'] != '' && $_POST['passwd'] != '') {
$db = Zend_Db_Table::getDefaultAdapter();
// tworzymy instancję adaptera autoryzacji
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'cms_user', 'user_login', 'user_passwd');
$authAdapter->setIdentity($_POST['login']);
$authAdapter->setCredential(sha1($_POST['passwd']));
// sprawdzamy, czy użytkownik jest aktywny
$authAdapter->setCredentialTreatment("? AND user_active = '1'");
// autoryzacja
$result = $authAdapter->authenticate();
if ($result->isValid()) {
$user_data = $authAdapter->getResultRowObject();
/* zapisanie roli zalogowanego uzytkownika */
$this->_roles = RolesModel::Instance();
$role = $this->_roles->getRoleData($user_data->role_id);
$user_data->role_code = $role['role_code'];
$this->_storage->write($user_data);
// ustawienie ACL dla użytkownika
$this->_engine->addHttpHeader("Location: /" . $this->_router->getUrl('cms', 'index'));
} else {
$this->_view->error = '1';
}
} else {
$this->_view->error = '1';
}
}
$this->_engine->setToRender('login.tpl');
}
示例10: indexAction
/**
* 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);
}
示例11: indexAction
public function indexAction()
{
$form = new Application_Form_Login();
$form->setAction('/auth');
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$auth = Zend_Auth::getInstance();
$db = Zend_Registry::get('db');
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'users', 'username', 'password');
$authAdapter->setIdentity($formData['username']);
$authAdapter->setCredential($formData['password']);
$result = $authAdapter->authenticate();
$session = Zend_Registry::get('session');
switch ($result->getCode()) {
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
$session->erro = 'senha';
$form->populate($formData);
break;
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
$session->erro = 'Usuario Inválido';
$form->populate($formData);
break;
case Zend_Auth_Result::SUCCESS:
$data = $authAdapter->getResultRowObject();
$session->role = $data->role;
$this->_redirect('/post/retrieve');
break;
}
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
}
示例12: loginAction
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');
}
}
示例13: Login
/**
* Login function authentication system
* @param Zend_Db_Table_Row $account
* @return boolean
*/
function Login(Zend_Db_Table_Row $account)
{
$select = $this->select()->where('email=?', $account->email)->limit(1);
$row = $this->fetchRow($select);
// set up the auth adapter
$db = Acl_Model_Account::getDefaultAdapter();
$authAdapter = new OS_Application_Adapter_Auth($account->email, $account->password);
$authAdapter = new Zend_Auth_Adapter_DbTable($db);
$authAdapter->setTableName($this->_name)->setIdentityColumn('email')->setCredentialColumn('password')->setCredentialTreatment('block = 0');
#->setCredentialTreatment('MD5(?) and block = 0');
$authAdapter->setIdentity($account->email);
$authAdapter->setCredential(crypt($account->password, $row->password));
$result = $authAdapter->authenticate();
Zend_Session::regenerateId();
if ($result->isValid()) {
$auth = Zend_Auth::getInstance();
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(array('id', 'email', 'registerdate', 'lastvisitdate', 'role_id', 'fullname', 'email_alternative')));
$account = $this->find($authAdapter->getResultRowObject()->id)->current();
#$account = $this->createRow( $account->toArray() );
$account->lastvisitdate = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss');
$account->save();
return true;
}
return false;
}
示例14: indexAction
public function indexAction()
{
$form = new Application_Form_Login();
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
if ($form->isValid($data)) {
$login = $form->getValue('login');
// <input name='login'>
$pass = md5($form->getValue('pass'));
$adaptateur = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
$adaptateur->setTableName('membre')->setIdentityColumn('login')->setCredentialColumn('pass')->setIdentity($login)->setCredential($pass);
if ($adaptateur->authenticate()->isValid()) {
// BRAVO
$storage = Zend_Auth::getInstance()->getStorage();
$mapper = new Application_Model_Mapper_Membre();
$membre = $mapper->getByLogin($login);
$storage->write($membre);
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/auth.ini');
$controller = $config->auth->defaultController;
$action = $config->auth->defaultAction;
$this->_helper->getHelper('Redirector')->gotoSimple($action, $controller);
} else {
$this->view->msgErreur = "Mauvais login/pass";
$form->populate($data);
}
} else {
$form->populate($data);
$form->buildBootstrapErrorDecorators();
$this->view->msgErreur = "Veuillez vérifier votre formulaire !";
}
}
$this->view->form = $form;
}
示例15: authenticate
public function authenticate()
{
// we first try if the user is the super user
$rootLogin = Zend_Registry::get('config')->superuser->login;
$rootPassword = Zend_Registry::get('config')->superuser->password;
$rootToken = Piwik_UsersManager_API::getTokenAuth($rootLogin, $rootPassword);
// echo $rootToken;
// echo "<br>". $this->_credential;exit;
if ($this->_identity == $rootLogin && $this->_credential == $rootToken) {
return new Piwik_Auth_Result(Piwik_Auth::SUCCESS_SUPERUSER_AUTH_CODE, $this->_identity, array());
}
// we then look if the user is API authenticated
// API authentication works without login name, but only with the token
// TODO the logic (sql select) should be in the Login plugin, not here
// this class should stay simple. Another Login plugin should only have to create an auth entry
// of this class in the zend_registry and it should work
if (is_null($this->_identity)) {
$authenticated = false;
if ($this->_credential === $rootToken) {
return new Piwik_Auth_Result(Piwik_Auth::SUCCESS_SUPERUSER_AUTH_CODE, $rootLogin, array());
}
$login = Zend_Registry::get('db')->fetchOne('SELECT login FROM ' . Piwik::prefixTable('user') . ' WHERE token_auth = ?', array($this->_credential));
if ($login !== false) {
return new Piwik_Auth_Result(Zend_Auth_Result::SUCCESS, $login, array());
} else {
return new Piwik_Auth_Result(Zend_Auth_Result::FAILURE, $this->_identity, array());
}
}
// if not then we return the result of the database authentification provided by zend
return parent::authenticate();
}