Login Form:
$authAdapter = Zend_Registry::get('authAdapter');
$authAdapter
->setIdentity($formData['email'])
->setCredential($password)
->setCredential(1);
Bootstrap:
protected function _initAuth(){
$this->bootstrap('db');
$this->bootstrap('session');
$db = $this->getPluginResource('db')->getDbAdapter();
$auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', 'enabled');
Zend_Registry::set('authAdapter', $authAdapter);
return $authAdapter;
}
Obviously since adding 'enabled' its stopped working, if I remove:
->setCredential(1);
and 'enabled' from there:
($db, 'User', 'email', 'password', 'enabled');
it works just fine...
I would like to only enable users who have an enabled account to login though.
EDIT:
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', '(?) AND `enabled` = 1');
works :)
You need to modify your adapter like so:
$authAdapter = new Zend_Auth_Adapter_DbTable(
$db,
'user',
'email',
'password',
'MD5(?) AND `enabled` = "true"');
please try:
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', 'AND enabled > 1');
and remove:
->setCredential(1);
You can set additional conditions in the auth adapter i.e.
$select = $authAdapter->getDbSelect();
$select->where("isActive = ?","Active");
Related
I'm building an authentication system and I use Composer to manage dependencies.
When I run my project it seems none of the classes can be found. I generated the files using cmd. I found similar threads here and here but it does not quite do it... Any idea?
The error
Fatal error: Class 'Bixxcom\User\User' not found in
C:\xampp\htdocs\authentication\app\start.php on line 34
start.php
<?php
use Slim\Slim;
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Noodlehaus\Config;
use Bixxcom\User\User;
use Bixxcom\Helpers\Hash;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new Slim([
'mode' => file_get_contents(INC_ROOT . '/mode.php'),
'view' => new Twig(),
'templates.path' => INC_ROOT . '/app/views'
]);
$app->configureMode($app->config('mode'), function() use ($app){
$app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});
require 'database.php';
require 'routes.php';
$app->container->set('user', function(){
return new User;
} );
$app->container->singleton('hash', function() use ($app){
return new Hash ($app->config);
});
$view = $app->view();
$view->parserOptions = [
'debug' => $app->config->get('twig.debug')
];
$view->parserExtensions = [
new TwigExtension
];
composer.json
{
"autoload":{
"psr-4":{
"Bixxcom\\": "app/Bixxcom"
}
},
"require": {
"monolog/monolog": "1.0.*",
"slim/slim": "~2.0",
"slim/views": "0.1.*",
"twig/twig": "~1.0",
"phpmailer/phpmailer": "~5.2",
"hassankhan/config": "0.8.*",
"illuminate/database": "~5.0",
"ircmaxell/random-lib": "~1.1"
}
}
User.php
<?php
namespace Bixxcom\User;
use Illuminate\Database\Eloquent\Model as Eloquent;
class User extends Eloquent
{
protected $table = 'users';
protected $fillable = [
'username',
'password',
'active',
'active_hash',
'recover_hash',
'remember_user',
'remember_token',
'first_name',
'last_name',
'age',
'email',
'phone',
'address',
'city',
'country'
];
}
Is it possible to use a REST API as Doctrine database?
Regarding the configuration on http://doctrine-orm.readthedocs.org/projects/doctrine-dbal/en/latest/reference/configuration.html I can change the "driver" property.
But in the list of allowed drivers there is no one to use a REST API.
What I would like to do is:
<?php
$config = new \Doctrine\DBAL\Configuration();
//..
$connectionParams = array(
'dbname' => 'my_rest_api',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost:3000',
'driver' => 'rest',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
$entityManager = EntityManager::create($conn, $config);
// Sends a GET request to localhost:3000/myentity/1 and maps it properly to my configured entity
$entity = $entityManager->find("MyNamespace\Entity\MyEntity", 1);
// Sends a POST request to localhost:3000/myentity
$entity = new MyEntity();
$entityManager->persist($entity);
$entityManager->flush();
// and so on
Thank you for your answers!!
DoctrineRestDriver is exactly doing what you are looking for!
https://github.com/CircleOfNice/DoctrineRestDriver
Have fun!
I was wondering if there anyway to move this configuration from the INI into the bootstrap.php in a way it would be the default globally. If so, how should I do it? I'm with zend 1.11.
thanks in advance.
;resources.mail.transport.type = smtp
;resources.mail.transport.host = "smtp.gmail.com"
;resources.mail.transport.auth = login
;resources.mail.transport.ssl = ssl
;resources.mail.transport.port = 465
;resources.mail.transport.username = email#example.com
;resources.mail.transport.password = pass
;resources.mail.transport.register = true ; True by default
;resources.mail.defaultFrom.email = email#example.com
;resources.mail.defaultFrom.name = "Foo"
;resources.mail.defaultReplyTo.email = email#example.com
;resources.mail.defaultReplyTo.name = "Foo"
[SOLUTION]
Actually it worked for me adding:
$config = array(
'ssl' => $transport_ssl,
'port' => $transport_port,
'auth' => $transport_auth,
'username' => $transport_username,
'password' => $transport_password,
'register' => $transport_register,
);
$transport = new \Zend_Mail_Transport_Smtp($transport_host, $config);
// var_dump($transport);exit;
\Zend_Mail::setDefaultTransport($transport);
In my Users controller I have an editAction. The below declaration is from editAction.
$form = $this->_getEditForm();//here I need to pass $user->email to the form class.
I have another class _gerEditForm() in same controller.
private function _getEditForm()
{
$form = new Form_Admin_Users_Add(array(
'method' => 'post',
'action' => $this->_helper->url('edit', 'users'),
));
return $form;
}
enter code here
//form class
class Form_Admin_Users_Add extends Form_Abstract
{
public function __construct($mail=null)
{
parent::__construct();
$this->setName('user');
//$userId = new Zend_Form_Element_Text('userId');
//$userId->addFilter('Int');
//$this->addElement($userId);
$this->setAttrib('id', 'addUserForm');
$this->setAttrib('class', 'formInline');
$firstName = new Zend_Form_Element_Text('firstName');
$firstName->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty', false, array('messages'=>'First name cannot be empty'))
->addValidator('StringLength', false, array(1, 256))
->setLabel('First Name:');
$this->addElement($firstName);
$lastName = new Zend_Form_Element_Text('lastName');
$lastName->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty', false, array('messages'=>'Last name cannot be empty'))
->addValidator('StringLength', false, array(1, 256))
->setLabel('Last Name:');
$this->addElement($lastName);
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email :')
->addValidator('NotEmpty', false, array('messages'=>'email cannot be empty'))
->addFilter('StripTags')
->addFilter('StringTrim')
->addValidator('EmailAddress')
->addValidator(new BusinessForum_Validate_UniqueEmail($mail));
Now I need to pass the email the form class. But I don't know how to do this.
Please help me in this regard.
Thanks
I'm a bit confused. The __construct function takes one argument, $mail. You're passing that to your BusinessForum_Validate_UniqueEmail class.
But in your _getEditForm function, you're passing in an array to that $mail argument that looks like it has settings for the form, not email information.
If that's just how you named stuff, and that's how it works, fine. Then you should just need to add a second parameter to your __construct function:
public function __construct($mail=null, $emailAddress="")
Pass it in from your _getEditForm function:
private function _getEditForm($emailAddress="")
{
$form = new Form_Admin_Users_Add(array(
'method' => 'post',
'action' => $this->_helper->url('edit', 'users')
), $emailAddress);
return $form;
}
And pass the email address to your _getEditForm function:
$form = $this->_getEditForm($user->email);
I am trying to read my Gmail account with Zend_Mail. The request just seems to time out. Is there an issue with my $config?
public function indexAction()
{
$config = array(
'host'=> 'pop.gmail.com',
'user' => 'xxx',
'password' => 'xxx',
'ssl' => 'tls',
'port' => 995);
$mail = new Zend_Mail_Storage_Pop3($config);
$maxMessage = $mail->countMessages();
$this->view->maxMessage = $maxMessage;
$message = $mail->getMessage(1);
$this->view->message = $message;
}
I think you need to use SSL as the ssl type. Also, are you using your full email as the username?
$config = array('host'=> 'pop.gmail.com',
'user' => 'xxx',
'password' => 'xxx',
'ssl' => 'SSL',
'port' => 995);
You don't need to enter ssl and port in case of gmail.
your config should be
$config = array('host'=> 'pop.gmail.com',
'user' => 'xxx',
'password' => 'xxx');