How to load or save Doctrine associated entity into Zend_Auth session - zend-framework

I am looking for some good solutions for a problem.
I am usig Doctrine 2.1 integrated to Zend Framework. I am using Zend_Auth with Zend_Auth_Storage_Session where I have stored User's entity. But entity of User is associtad to other Entity => AclRole. Each User has one AclRole.
For the first time, when I load user throught EntityManager, the AclRole is loaded as soon as call it in User. But when other page is loaded and entity of User is loaded from session, her 'locale' attribute is NULL.
Is there any good solution of this?

I have an excellent solution, that i am using in my project, i will send you the github link when i've checked in my code today ;)

Related

Where are are IdentityUsers uploaded to the database?

I have created a ASP.net core web app with user authentication. The user authentication has been auto-implemented and it works like a charm. However, I need to do 2 things:
-Add a text field 'Name' to the user registration
-Write a record into another (custom-made) table when AspNetUsers is written to.
However, I can't seem to find where (meaning in what file/method) either of these things can be done.
I tried and debugged the web app, but it didn't help.
As I expect that IdentityUsers are written to the data base using DbContext.Add, I also searched for that but didn't help either.
Thank you in advance.
The following article explains everything: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.1&tabs=visual-studio .

Zend Framework 2 Doctrine ORM Authentication

I'm developing my first real project with ZF2 and Doctrine ORM. And I cannot find any good example of user authentication through doctrine orm authentication adapter. Now I'm using standard Zend Db Adapter authentication. In addition, I use
$adapter->setIdentityColumn(filter_var($request->getPost('useremail'),FILTER_VALIDATE_EMAIL) ? 'useremail' : 'userlogin');
in my login controller to login either via email and login.
But I want to perform all job through doctrine ORM. Could someone show me a similar example with doctrine.authentication.orm_default and storing user identity data in session/storage to access in any controller or module.php? Is it possible to use two fields - userlogin or email for login?
Thank you in advance for your help.
Updated: I kept seaching and as a result this and this helped me so much
One problem, that i haven't solved yet. How can I check user status (activated or not) with doctrine adapter?
Like
$authAdapter = new AuthAdapter($dbAdapter,'user','username','password','MD5(?) AND status = 1');
You can use credential_callable option (Doctrine Module doc.). It can be any callable (PHP Manual), for example with closure:
'credential_callable' => function(User $user, $passwordGiven) {
return md5($passwordGiven) == $user->getPassword() && $user->isActive();
},
or with static class method:
'credential_callable' => 'Application\User\UserService::verifyUser'
What about an external module idea? If you are OK with that you can take a look at https://github.com/ZF-Commons/ZfcUser and https://github.com/SocalNick/ScnSocialAuth or the whole modules repositories http://modules.zendframework.com/?query=user. Even if you don't install just download and see what other people do stuff.

How to check drupal user role in module written by Zend Framework

I have written a web application using Zend framework, and I convertered it to the drupal module using ".module" file.
But I need to authorize current drupal user in that module.
How could I check the drupal user role in Zend?
By the way I find out Drupal has its own session handler to store data in database and zend use default handler which store sessions data into file system.
So it make them separate.
Any solution?
It's considered bad practice to check the roles array itself in Drupal, the correct method is to assign an appropriate permission to that role, and check for that permission with user_access(), e.g.
if (user_access('an appropriate permission')) {
// User is authorised.
}
So you actually have a Drupal module.
Try
<?php
global $user;
if (in_array('administrator', array_values($user->roles))) {
}

Web.api Get method to show only selected properties from entity

Let's say I have 3 entities: Advert, User and UserRole. And in Web.Api project GetAllAdverts method.
public IEnumerable<Advert> GetAllAdverts()
{
return repository.GetAll<Advert>();
}
When i enter url ../api/advert I get JSON with all Adverts and data about adverts, but I get all data about user and user role too.
How can I get for example all advert data and only UserName form entity User ?
Is this done by creating DTOs ?
Thanks in advance !
Using DTO's is usually a good idea. It is more work, but it gives you full control and it abstracts out peculiarities of a specific data layer.
In your case, if you really only want UserName you even have to use a DTO, because it is impossible to partly load the User as navigation property from Advert.
If it does not matter that you see all properties of User except its navigation properties (like role), you may also consider to (temporarily) turn off lazy loading for the context in the repository and eager load Advert.User by using Include.

ASP.Net MVC 2 Forms Authentication cookieless = "UseUri" while submit authorization fails

I just started working with ASP.Net MVC 2.
I created a new ASP.Net MVC application and created one vehicle controler with a database table connected with LINQ. Then created forms authentication mechanism for the application and tried to use the uri instead of cookies it was working smoothly but when i submit the form by creating a "Create" view from the controler using the utility it just dont work. The autherization got failed and asking to enter the user name and password again.I had created the authorization mechanism by adding Authorise attribute to the Controller so as to get authorized for all the actions.
namespace MVCNEW.Controllers
{
[Authorize]
public class VehicleController : Controller
{
But if i use the cookies instead of uri it works fine.
Thanks in advance...
Please see http://forums.asp.net/p/1517391/3634908.aspx for an official response.
Summary: Cookieless Session support is essentially obsolete, and the MVC framework isn't likely to include additional support for it.
I found the problem and a solution.
This was due to some error in the framework. They are not creating the Uri string for the Form action while calling
Html.BeginForm()
But if we make it call overloading of this method like the providing the Controller name and Action name it is working fine.
view plaincopy to clipboardprint?
Html.BeginForm("Create","Vehicle")