Created
January 19, 2017 13:10
-
-
Save imrvelj/75740af51707e2e52a06f5dbf728965d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = $request->request->get('username'); | |
$password = $request->request->get('password'); | |
if(is_null($username) || is_null($password)) { | |
return new Response( | |
'Please verify all your inputs.', | |
Response::HTTP_UNAUTHORIZED, | |
array('Content-type' => 'application/json') | |
); | |
} | |
$user_manager = $this->get('fos_user.user_manager'); | |
$factory = $this->get('security.encoder_factory'); | |
$user = $user_manager->findUserByUsername($username); | |
$encoder = $factory->getEncoder($user); | |
$salt = $user->getSalt(); | |
if($encoder->isPasswordValid($user->getPassword(), $password, $salt)) { | |
$response = new Response( | |
'Welcome '. $user->getUsername(), | |
Response::HTTP_OK, | |
array('Content-type' => 'application/json') | |
); | |
} else { | |
$response = new Response( | |
'Username or Password not valid.', | |
Response::HTTP_UNAUTHORIZED, | |
array('Content-type' => 'application/json') | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment