Skip to content

Instantly share code, notes, and snippets.

@imrvelj imrvelj/seemfoni
Created Jan 19, 2017

Embed
What would you like to do?
$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
You can’t perform that action at this time.