E
E
e-hot2016-02-17 16:54:11
symfony
e-hot, 2016-02-17 16:54:11

How to implement a single registration and authorization form in Symfony 2?

Welcome all.
Initial situation:
1. On the site for the user, it is necessary to build a single form for implementation and authorization (remember-me is also implied) so that the user does not run through two different forms: register in the registration form, log in - in authorization. In other words: we need a 2 in 1 form.
2. The project is written in Symfony 2.3
3. Documentation and examples in Symfony 2 show how to create authorization separately and registration separately, I did not find anything about something unified and integral.
4. I began to dig this task in depth: for now, I think that you need to implement your method in the controller instead of the notorious method, which is indicated by the logic_check recommended by the documentation in security.yml:

...
form_login:
    login_path: /account/login
    check_path: /account/login_check
...

and routing.yml:
...
login_check:
    pattern: /account/login_check
...

But, judging by the docs, Symfony 2 intercepts the event and the login:password input is processed somewhere in itself. Where exactly this happens in Symfony - from all the documentation found, I did not find it.
At the moment, I understand this, it is necessary (either-or):
  1. just rewrite "somewhere in Symfony 2" the functionality of processing data from the form;
  2. cancel the action "somewhere in Symfony 2" of the data processing functionality from the form and write your own functionality instead.
Question: if anyone has encountered similar tasks or knows this part of Symfony 2 to the marrow of their bones, please help me understand the problem (when searching for information, I somehow ran into the topic of events ( Events ), you need to rewrite some Events to fit your requirements for firewall?). Or in other words: how and where to write custom login_check in Symfony 2?
Note: a single registration/authorization form ( method POST ) is one form with login (email), password (and remember-me checkbox) fields. The controller method receives data from the form via request. Checks if the database already has a login (email), then looks for a password, if the password matches, then the authorization process starts.
If there is no login (email) in the database, then the registration process starts (adding new login:password to the database with a bunch of service information, such as: date-time, active, etc.). Regardless of which process is running, after registration or authorization, the user is redirected to the personal account. The output of errors about the wrong password is not yet needed.
Thank you in advance for your help, advice, recommendations and educational program. I will answer all counter questions, if something is not clear from the question posed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BoShurik, 2016-02-17
@BoShurik

I would dig towards a custom UserProvider: symfony.com/doc/current/cookbook/security/custom_p...

public function loadUserByUsername($username)
    {
        // make a call to your webservice here
        $userData = ...
        // pretend it returns an array on success, false if there is no user

        if ($userData) {
            $password = '...';

            // ...

            return new WebserviceUser($username, $password, $salt, $roles);
        }

        // Тут создаем пользователя
    }

Those. if the user has an error in the login, will he be automatically registered without asking? -_-

W
WarGot, 2016-02-23
@WarGot

Look towards the FOS user bundle, you will need to redefine the authorization and registration controllers on your own, add a couple of lines and profit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question