Created
April 28, 2018 22:38
-
-
Save emir/dcbdfef7ee0c52a976518dfbe0870125 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
<?php | |
namespace App\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use App\Entity\User; | |
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; | |
class AuthController extends AbstractController | |
{ | |
public function register(Request $request, UserPasswordEncoderInterface $encoder) | |
{ | |
$em = $this->getDoctrine()->getManager(); | |
$username = $request->request->get('_username'); | |
$password = $request->request->get('_password'); | |
$user = new User($username); | |
$user->setPassword($encoder->encodePassword($user, $password)); | |
$em->persist($user); | |
$em->flush(); | |
return new Response(sprintf('User %s successfully created', $user->getUsername())); | |
} | |
public function api() | |
{ | |
return new Response(sprintf('Logged in as %s', $this->getUser()->getUsername())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where is login_check function?