Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/login", name="login")
- * @param AuthenticationUtils $authenticationUtils
- * @return SymfonyComponentHttpFoundationRedirectResponse|SymfonyComponentHttpFoundationResponse
- */
- public function index(AuthenticationUtils $authenticationUtils)
- {
- if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
- return $this->redirectToRoute('home');
- }
- //Login
- $error = $authenticationUtils->getLastAuthenticationError();
- $lastUsername = $authenticationUtils->getLastUsername();
- //endLogin
- return $this->render('security/login.html.twig', [
- 'last_username' => $lastUsername,
- 'error' => $error,
- ]);
- }
- public function reg_index(Request $request)
- {
- if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
- return $this->redirectToRoute('home');
- }
- //Regist
- // 1) build the form
- $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
- $user = new User();
- $form = $this->createForm(RegisterForm::class, $user);
- // 2) handle the submit (will only happen on POST)
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid() && $this->captchaverify($request->get('g-recaptcha-response'))) {
- // 3) Encode the password (you could also do this via Doctrine listener)
- $user->setSalt(md5(time()));
- $password = $encoder->encodePassword($user->getUsername(), $user->getSalt());
- $user->setPassword($password);
- $role = $this->getDoctrine()->getRepository(Role::class)->findOneBy(array('name' => "ROLE_USER"));
- $user->addUserRole($role);
- // 4) save the User!
- $entityManager = $this->getDoctrine()->getManager();
- $entityManager->persist($user);
- $entityManager->flush();
- $token = new UsernamePasswordToken(
- $user->getUsername(),
- $user->getPassword(),
- 'main',
- $user->getRoles()
- );
- $this->get('security.token_storage')->setToken($token);
- $this->get('session')->set('_security_main', serialize($token));
- return $this->redirectToRoute('home');
- }
- //endRegist
- return $this->render('security/register.html.twig', [
- 'formR' => $form->createView(),
- ]);
- }
- {% block body %}
- <div class="col-12 col-md-4" onclick="window.location='/'">
- <div id="logo" href="/">
- <img src="{{ asset('img/logo.png') }}" alt="emr developer place" width="220">
- </div>
- </div>
- <div>
- <div id="map">
- <div class="login-wrap">
- <div class="login-html">
- <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" checked class="tab">ВХОД</label>
- <input id="tab-2" type="radio" {#onclick="window.location='/registration'"#} name="tab" class="sign-up" ><label for="tab-2" class="tab">Регистрация</label>
- <div class="login-form">
- <div class="sign-in-htm">
- <form action="{{ path('login') }}" method="post" id="formLogin">
- <div class="group">
- <label for="user" class="label">Логин</label>
- <input type="text" class="input" id="username" name="_username" value="{{ last_username }}" />
- </div>
- <div class="group">
- <label for="pass" class="label">Пароль</label>
- <input type="password" class="input" id="password" name="_password" />
- </div>
- <div class="group">
- <input id="check" type="checkbox" class="check" checked>
- <label for="check"><span class="icon"></span> Запомнить пароль</label>
- </div>
- <div class="group">
- <input type="submit" class="button" value="Войти" form="formLogin">
- </div>
- {% if error %}
- <div class="alert alert-danger" role="alert">
- {{ error.messageKey|trans(error.messageData, 'security') }}
- </div>
- {% endif %}
- <div class="hr"></div>
- <div class="foot-lnk">
- <a href="#forgot">Забыли пароль?</a>
- </div>
- </form>
- </div>
- <div class="sign-up-htm">
- {{ render(controller(
- 'App\Controller\SecurityController::reg_index'))}}
- </div>
- </div>
- </div>
- </div>
- </div>
Add Comment
Please, Sign In to add comment