-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple entities #110
Comments
Good morning, The short answer is kind of - the bundle it self consumes a user at runtime, and then persists a request object that references that user. However, The bundle can handle multiple user entities, maker's I'll add this to the board for possible future features - perhaps we could better support multiple user entity objects. |
Thank you very much for your answer ! What could the config/packages/reset_password.yaml file look like as there are mutiple repositories? Thanks |
If I get a second tonight, I'll try coding it out to confirm. But off the top of my head, the What would change would be the If you have multiple entities, you couldn't use a |
Hi, $repoclass='App\Repository\UserType1ResetPasswordRequestRepository'; That's all ! |
Hi @jrushlow |
@jrushlow Could you make the change to make this bundle work with multiple entities please? Thanks :) |
I had the same problem and my fastly (it's not the best) solution was these:
|
But as a result, you have 2 user fields. This is obviously not ideal. |
Answer of @cristobal85 is not ideal for sure, but it helped me do the job. Note that you also have to modify
and in
|
Sorry, I forgot to explain that I have two controllers, one for each entity "App\Entity\{Category1}\{User1}" and "App\Entity\{Category2}\{User2}" and the controllers are on "App\Controller\{Category1}\ResetPasswordController" and "App\Controller\{Category2}\ResetPasswordController" |
I think your solution is better than my |
Yes, the truth is that it is not the best solution. |
Has anyone considered using inheritance mapping? It looks like it could solve the problem in most cases since password reset would apply on the parent instance. I can't try right now, but maybe it is a hint to a better resolution of this problem... |
Hello everyone. I also faced this problem and searching for the best approach. @jrushlow could you manage to work on an example of your approach? I also thought about inheritance mapping as one approach but for me this is a bit too difficult. Maybe one the more experienced guys here can provide an example with multiple tragetEntities for $user property of ResetPasswordRequest? Thanks in advance. |
Could you possibly suggest how to put my logic in here? I want to differential between two cases based on URL of the request. How to get here the request object? |
I think the current best way is create your own controller to handle your request. You may reuse the token component from this bundle to achieve your goal there Or use signed url bundle https://github.com/coopTilleuls/UrlSignerBundle it is almost the same way to reset password except that the token is not persisted to database. |
It can be done, thanks to the Symfony DI ! For the default user in the symfonycasts_reset_password:
request_password_repository: App\Repository\UserRepository
lifetime: 3600
throttle_limit: 3600
enable_garbage_collection: true This will instantiate a helper with the alias Then for the custom helper, in the admin.reset_password_helper:
class: SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelper
arguments:
$generator: '@symfonycasts.reset_password.token_generator'
$cleaner: '@symfonycasts.reset_password.cleaner'
$repository: '@App\Repository\AdminRepository'
$resetRequestLifetime: 3600
$requestThrottleTime: 3600 So if you have a UserService that is handling the reset password namespace App;
class UserService
{
public function __construct(
private ResetPasswordHelperInterface $userResetPasswordHelper,
private ResetPasswordHelperInterface $adminResetPasswordHelper
) {}
public function resetAdminPassword()
{
// ...
}
public function resetUserPassword()
{
// ...
}
} In the App\UserService:
arguments:
$userResetPasswordHelper: '@symfonycasts.reset_password.helper'
$adminResetPasswordHelper: '@admin.reset_password_helper' |
@savvasal It's still a hack but I would have preferred a feature in the heart of the bundle :) |
I do something like this: #reset_password.yaml
symfonycasts_reset_password:
request_password_repository: App\Repository\UsersResetPasswordRequestRepository #services.yaml
client.reset_password.cleaner:
class: SymfonyCasts\Bundle\ResetPassword\Util\ResetPasswordCleaner
arguments:
$repository: '@App\Repository\ClientsResetPasswordRequestRepository'
client.reset_password_helper:
class: SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelper
arguments:
$generator: '@symfonycasts.reset_password.token_generator'
$cleaner: '@client.reset_password.cleaner'
$repository: '@App\Repository\ClientsResetPasswordRequestRepository'
$resetRequestLifetime: 3600
$requestThrottleTime: 3600
App\Controller\ClientController:
arguments:
$resetPasswordHelper: '@client.reset_password_helper' I have 2 differents entities Clients & Users. /**
* @ORM\Entity(repositoryClass=ClientsResetPasswordRequestRepository::class)
*/
class ClientsResetPasswordRequest implements ResetPasswordRequestInterface
{
use ResetPasswordRequestTrait;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Clients::class)
* @ORM\JoinColumn(name="client_id", nullable=false)
*/
private $user;
} |
@savvasal it's awesome. Thank you so much |
Hi, |
i recently got the Idea of using FirewallConfiguration symfony/symfony#54713 to get the UserProvider for the Current Firewall (or Chain) then an extended UserProvider can be used to fetch the right ResetPasswordRequestRepository (or make one Repository work for Multiple Users, separated by their Firewall?) i need try to make a demo Project to show my idea |
Hi,
Is it possible to use this bundle with multiple entities? A User entity and an Admin entity for example.
If not, it would be a good idea of feature :)
Thank you :)
The text was updated successfully, but these errors were encountered: