0

I would like to authentificate user after its registration.

So registrationAction is:

public function registrationAction(Request $request) {
    //Creating user...

    return $this->forward('AcmeFrontBundle:Mobile:securityCheck', array(
        '_username' => $customer->getEmail(),
        '_password' => 'pwd',
    ));
}

The problem is that Symfony security system doesn't interceipt this redirecting, but executes directly securityCheckAction which is naturally empty.

Redirection works in that way:

    return $this->redirect($this->generateUrl('mobile_login_check') . "?_username=" . $customer->getEmail() . "&_password=pass");

Forwarding is preferable because I would like to use POST request for registrationAction and securityCheckAction.

Any ideas?

In the other hand maybe it would be better to authentificate user by myself? Just like described here: http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html

What is your opinion?

VladRia
  • 1,475
  • 3
  • 20
  • 32
  • have a look at FOSUserBundle. It provides all this functionality and masses more. – DevDonkey Nov 18 '14 at 12:42
  • I just used `$token = new UsernamePasswordToken($customer, $customer->getPassword(), 'secured_mobile', $customer->getRoles()); $this->get('security.context')->setToken($token);`. This is simple and effective. – VladRia Nov 18 '14 at 13:10

1 Answers1

0

Trying to perform a redirect with POST is not a good idea. Here's why: https://softwareengineering.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect

The best way is to create token & emit login event: How to programmatically login/authenticate a user?

Community
  • 1
  • 1
kozlice
  • 714
  • 7
  • 12