BConnect Business - Reference PHP

UserController extends AbstractController
in package

Table of Contents

Constants

RECAPTCHA_THRESHOLD  : mixed = 0.5

Methods

addUser()  : Response
Adds a new user.
apiLogin()  : void
deleteAccount()  : Response
Supprime (anonymise) le compte de l'utilisateur connecté.
forgotPassword()  : Response
Handles the forgot password functionality.
index()  : Response
Displays a list of users.
login()  : Response
Login method
logout()  : void
Logout method
register()  : Response
Method for register a new user in bconnect
reset()  : Response
Handles the password reset process.
showUser()  : Response
Displays the details of a specific retail user.
updateUser()  : Response
Updates an existing user.
userProfile()  : Response
Handles the user profile update and password change.
verifyEmail()  : Response
Verifies the user's email using the provided token.
uploadAllFileType()  : void
Uploads files associated with a business.
validateRecaptcha()  : array<string|int, mixed>
Validate reCAPTCHA submission

Constants

Methods

addUser()

Adds a new user.

public addUser(Request $request, UserPasswordHasherInterface $passwordHasher, EntityManagerInterface $entityManager, UserRegistrationService $registrationService, MailerService $mailerService) : Response

This method handles the creation of a new user, either for a business (when user has ROLE_ROOT) or as a regular user. It processes the form submission, hashes the user's password, assigns appropriate roles, sets the parent user if applicable, and persists the user entity.

Parameters
$request : Request

The HTTP request object.

$passwordHasher : UserPasswordHasherInterface

The password hasher service.

$entityManager : EntityManagerInterface

The entity manager for database operations.

$registrationService : UserRegistrationService

The user registration service.

$mailerService : MailerService

The mailer service.

Tags
throws
TransportExceptionInterface
Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
$path: '/add/user'
$name: 'app_user_create'
Return values
Response

The HTTP response object.

apiLogin()

public apiLogin() : void
Attributes
#[Route]
$path: '/api/login_check'
$name: "api_login"

deleteAccount()

Supprime (anonymise) le compte de l'utilisateur connecté.

public deleteAccount(Request $request, AccountDeletionService $deletionService, RequestStack $requestStack) : Response

RG1 : La confirmation est gérée côté template via un modal. RG2 : Le bouton "Annuler" ferme le modal sans action. RG3 : Le bouton "Valider" soumet ce formulaire POST avec un token CSRF. Le compte est anonymisé, un email est envoyé à l'utilisateur et aux ROLE_ROOT. RG4 : L'action est tracée dans AccountDeletionLog.

Parameters
$request : Request
$deletionService : AccountDeletionService
$requestStack : RequestStack
Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
'/users/delete-account'
$name: 'app_user_delete_account'
$methods: ['POST']
Return values
Response

forgotPassword()

Handles the forgot password functionality.

public forgotPassword(Request $request, EntityManagerInterface $entityManager, MailerService $mailer) : Response

This method displays a form for the user to enter their email address. If the form is submitted and valid, it checks if a user with the provided email exists. If a user is found, it generates a reset token, sets its expiration time, and sends a password reset email. If no user is found, it adds an error flash message.

Parameters
$request : Request

The HTTP request object.

$entityManager : EntityManagerInterface

The entity manager for database operations.

$mailer : MailerService

The mailer service for sending emails.

Attributes
#[Route]
'/forgot-password'
$name: "forgot_password"
Return values
Response

The response object, either rendering the form or redirecting to the login route.

index()

Displays a list of users.

public index(UserRepository $repository) : Response

This method handles the route '/users/index' and displays a list of users. If the current user has the "ROLE_MANAGER" role, it will display users that have the current user as their parent. Otherwise, it will display all users.

Parameters
$repository : UserRepository

The repository to fetch users from.

Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
'/users/index'
$name: 'app_user_index'
Return values
Response

The response object containing the rendered view.

login()

Login method

public login(AuthenticationUtils $authenticationUtils) : Response
Parameters
$authenticationUtils : AuthenticationUtils
Attributes
#[Route]
$path: '/login'
$name: 'app_login'
Return values
Response

logout()

Logout method

public logout() : void
Attributes
#[Route]
$path: '/logout'
$name: 'app_logout'

register()

Method for register a new user in bconnect

public register(Request $request, ActivitySectorRepository $activitySectorRepository, UserRegistrationService $registrationService, EntityManagerInterface $entityManager, MailerService $mailerService, Recaptcha3Validator $recaptcha3Validator) : Response
Parameters
$request : Request
$activitySectorRepository : ActivitySectorRepository
$registrationService : UserRegistrationService
$entityManager : EntityManagerInterface
$mailerService : MailerService
$recaptcha3Validator : Recaptcha3Validator
Tags
throws
TransportExceptionInterface
Attributes
#[Route]
$path: '/register'
$name: 'app_register'
Return values
Response

reset()

Handles the password reset process.

public reset(string $token, Request $request, EntityManagerInterface $entityManager, UserPasswordHasherInterface $userPasswordHasher) : Response
Parameters
$token : string

The reset token.

$request : Request

The HTTP request object.

$entityManager : EntityManagerInterface

The entity manager.

$userPasswordHasher : UserPasswordHasherInterface

The password hasher.

Tags
throws
NotFoundHttpException

If the user is not found.

Attributes
#[Route]
'/reset-password/{token}'
$name: 'reset_password'
Return values
Response

The HTTP response.

showUser()

Displays the details of a specific retail user.

public showUser(User $user) : Response
Parameters
$user : User

The user entity to display.

Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
'/user/retail/{id}'
$name: 'app_user_show'
Return values
Response

The response object containing the rendered template.

updateUser()

Updates an existing user.

public updateUser(User $user, UserPasswordHasherInterface $passwordHasher, EntityManagerInterface $entityManager, Request $request) : Response

This method handles the form submission for updating a user. It checks if the form is submitted and valid, hashes the password if it is provided, sets the user's roles and parent, persists the changes to the database, and then redirects to the user index page with a success message.

Parameters
$user : User

The user entity to be updated.

$passwordHasher : UserPasswordHasherInterface

The password hasher service.

$entityManager : EntityManagerInterface

The entity manager service.

$request : Request

The HTTP request object.

Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
'/user/update/{id}'
$name: 'app_user_update'
Return values
Response

The HTTP response object.

userProfile()

Handles the user profile update and password change.

public userProfile(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, UploaderService $uploaderService, MailerService $mailer) : Response
Parameters
$request : Request

The HTTP request object.

$userPasswordHasher : UserPasswordHasherInterface

The password hasher service.

$entityManager : EntityManagerInterface

The entity manager for database operations.

$uploaderService : UploaderService

The service for handling file uploads.

$mailer : MailerService

The service for sending emails.

Attributes
#[IsGranted]
'IS_AUTHENTICATED_FULLY'
#[Route]
'/users/profile'
$name: 'app_user_profil'
Return values
Response

The HTTP response object.

verifyEmail()

Verifies the user's email using the provided token.

public verifyEmail(string $token, EntityManagerInterface $entityManager) : Response
Parameters
$token : string

The verification token.

$entityManager : EntityManagerInterface

The entity manager.

Attributes
#[Route]
'/verify-email/{token}'
$name: 'app_verify_email'
Return values
Response

The response object.

This method checks if the provided token is valid and not expired. If the token is invalid or expired, it redirects the user to the registration page with an error message. If the token is valid, it verifies the user's account, removes the token and its expiration date, and redirects the user to the login page with a success message.

uploadAllFileType()

Uploads files associated with a business.

private uploadAllFileType(FormInterface $form, mixed $uploaderService, User $user) : void
Parameters
$form : FormInterface
$uploaderService : mixed
$user : User

validateRecaptcha()

Validate reCAPTCHA submission

private validateRecaptcha(Recaptcha3Validator $recaptcha3Validator) : array<string|int, mixed>
Parameters
$recaptcha3Validator : Recaptcha3Validator
Return values
array<string|int, mixed>
On this page

Search results