Lastest news for classes zfcuser, bjyauthorize and orm - zend-framework

I am working with zfcuser, zfcuser-doctrine-orm and bjyauthorize but I'm not sure on how to handle all the configurations. I have setted
return array(
'bjyauthorize' => array(
// default role for unauthenticated users
'default_role' => 'guest',
// default role for authenticated users (if using the
// 'BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider' identity provider)
'authenticated_role' => 'user',
// identity provider service name
'identity_provider' => 'BjyAuthorize\Provider\Identity\AuthenticationDoctrineEntity',
// Role providers to be used to load all available roles into Zend\Permissions\Acl\Acl
// Keys are the provider service names, values are the options to be passed to the provider
'role_providers' => array(
/* here, 'guest' and 'user are defined as top-level roles, with
* 'admin' inheriting from user
*/
'BjyAuthorize\Provider\Role\DoctrineEntity' => array(
'role_entity_class' => 'Application\Entity\Role',
),
[...]
(I am using BjyAuthorize\Provider\Role\DoctrineEntity as suggested by #ocramius on Add BjyAuthorize Roles (using ZfcUser and Doctrine))
But "BjyAuthorize\Provider\Role\DoctrineEntity" does not exists in the module and it's not in the factories. I tried to use:
'BjyAuthorize\Provider\Role\DoctrineEntity' => 'BjyAuthorize\Service\DoctrineEntityRoleProviderFactory',
But it does not work:
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotCreatedException' with message 'While attempting to create bjyauthorizeproviderroledoctrineentity(alias: BjyAuthorize\Provider\Role\DoctrineEntity) an invalid factory was registered for this instance type.' in D:\wamp\www\vidum\src\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php on line 860
Does anyone know which is the class for this factory?

The correct class to hook up a Doctrine role provider is
BjyAuthorize\Provider\Role\ObjectRepositoryProvider
You can see an example setup in the docs.

Related

CAS username field value to be manually added to the existing user on import?

I installed the CAS module on a Drupal 8 site, and it is working fine. For new users, it auto-registers the user with cas_username, but I would like to import the cas_username manually for the existing Drupal 8 user.
I also tried importing users in CSV format(https://github.com/steveoliver/user_import); I have been able to add the $account(row[0],row[1]), but for the CAS username import, i don't know how to import it, and in which field is stored.
'uid' => NULL,
'name' => $username,
'field_first_name' => row[0],
'field_last_name' => $row[1],
'pass' => $username,
'mail' => $row[2],
'status' => 1,
'created' => REQUEST_TIME,
'roles' => array_values($config['roles']),
I tried Managing CAS username; the suggestion given is for Drupal 7, but the same method doesn't work for Drupal 8.
Kindly suggest me solution import the cas username in CSV.
I find out the solution for the CAS_username import in CSV method. The method of db_insert in (authmap) table, which dynamically insert the CAS_username in respective field.
The authmap table is present in external authentication module.
db_insert('authmap')
->fields(array(
'uid' => $uid,
'provider' => 'cas',
'authname' => $row[0],
'data' => 'N;',
))
->execute();
So this is the method, i dynamically update the CAS_username using CSV. If any suggestions or update in that. Kindly Prescribe it.

After adding new column "name" to user table in yii2 advanced, data not getting saved in it

After assigning all required values to user model (column which i have added also). When I am using $model->save() data for all default attributes getting saved except the one I have added. I trying insert via REST call. If there is any other way to do please let me know. I have also followed this link https://github.com/dektrium/yii2-user/blob/master/docs/adding-new-field-to-user-model.md which is of no use.
this is my rules method in users model
public function rules()
{
return [
[['username', 'email'], 'filter', 'filter' => 'trim'],
[['username', 'email', 'status','name'], 'required'],
['email', 'email'],
['username', 'string', 'min' => 2, 'max' => 255],
// password field is required on 'create' scenario
['password', 'required', 'on' => 'create'],
// use passwordStrengthRule() method to determine password strength
$this->passwordStrengthRule(),
['username', 'unique', 'message' => 'This username has already been taken.'],
['email', 'unique', 'message' => 'This email address has already been taken.'],
];
}
Thank you.
User model which I was using extended from UserIdentity So I have added rules method in UserIdentity class but after adding new column to users table, that column should be specified in rules method of users model only which ever it might be extending. Previously there was no need of adding like this till Yii v2.1.0 may be in Yii 2.2.0 it has to be.

Bind the doctrine ORM entity and doctrine ODM document and use it in SonataAdminBundle

I have a User entity and Address document. They are linked between each other with #gedmo\references doctrine extension. This relation works just fine. I can get both referenceMany and referenceOne linked objects.
Now i need to use it at the sonataUserBundle form to let user to add multiple addresses for the user. (user - in mysql, address - in mongodb).
I tried to use this in the userAdmin class:
$formMapper->add('addresses', 'sonata_type_model', array(
'class' => 'Application\Sonata\UserBundle\Document\Address',
'required' => false,
'expanded' => true,
'multiple' => true
))
it gives me an error:
No entity manager defined for class Application\Sonata\UserBundle\Document\Address
Please, answer what should I do!
You get that error because a ModelManager of an Admin Class only supports the manager_type that you configured which is the ORM default. So it is looking for an entityManager.
I have a similar case but the other way around. Inside my Document Admin Class I have to link to an Entity. It works this way:
$formMapper->add('user', 'entity', array(
'class' => 'ApplicationSonataUserBundle:User',
'label' => 'User'
));
You should simply be able to use entity and document as type instead of sonata_type_model.

Zend Sessions getting mixed up

I'm currently working on the login for a Zend Framework application, and I'm using a combination of Zend_Auth and Zend_Session using a database adapter (as described in the Zend Framework manuals).
I've made a resource for the session:
class DC_Resource_DbSession extends Zend_Application_Resource_ResourceAbstract{
public function init(){
}
public function setadapter($value){
$this->dbAdapter = $value;
}
public function setSession($adapter){
//put your code here
$config = array(
'name' => 'sessions',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime',
'db' => $adapter
);
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
Zend_Session::setOptions(array('name'=>'MY_SESSION_NAME'));
Zend_Session::start();
}
}
Zend Auth then uses the session to store some rudimentary authentication information.
However, when testing the login (from the same IP) if one user in our office logs in and another user goes to the site, they are logged in as the user!!! Can anyone help me figure out why they are using each other's sessions?
DOH!!!!
My humble, humiliated apologies. The id column datatype had been set to INT by our migrations guy - and obviously it needs to be VARCHAR....
smacks self in face...

Using Zend Framework Db Tables without MVC

I am trying to use the Zend Framework without using the MVC structure, specifically the Db_Table classes.
I have created a couple of classes representing my database tables, i.e.
class DBTables_Templates extends Zend_Db_Table_Abstract
{
protected $_name = "templates";
}
When I try to instantiate this class (it is included fine), I get the following error:
Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for DBTables_Templates'
Does anyone know how I create and include the database adapter for the Db_Table classes to use?
Any pointers are greatly appreciated! I am using the latest version of ZF.
You need to create a Zend_Db_Adapter, which is the class you use to connect to the database.
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
Or you can use the factory() method to make instantiation more configurable:
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => 'webuser',
'password' => 'xxxxxxxx',
'dbname' => 'test'
));
See http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.connecting
Then specify this adapter object to your table class. There are at least three ways to do this:
Set an application-wide default for all tables:
Zend_Db_Table_Abstract::setDefaultAdapter($db);
Specify the adapter to the table constructor:
$table = new MyTable( array('db'=>$db) );
Store the adapter in the registry and specify it to the table or set it as default:
Zend_Registry::set('my_db', $db);
$table = new MyTable( array('db'=>'my_db') );
// alternatively:
Zend_Db_Table_Abstract::setDefaultAdapter('my_db');
See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.constructing