Skip to content

Instantly share code, notes, and snippets.

@emir
Created April 28, 2018 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emir/dcbdfef7ee0c52a976518dfbe0870125 to your computer and use it in GitHub Desktop.
Save emir/dcbdfef7ee0c52a976518dfbe0870125 to your computer and use it in GitHub Desktop.
<?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()));
}
}
@nawatend
Copy link

nawatend commented Dec 4, 2019

where is login_check function?

@mitchobrian
Copy link

:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment