Login into Phraseanet

@param  Request $request The current request
@return Response
555291
public function login(Request $request)
    {
        try {
            $this->getApplicationBox()->get_connection();
        } catch (\Exception $e) {
            $this->app->addFlash('error', $this->app->trans('login::erreur: No available connection - Please contact sys-admin'));
        }

        $feeds = $this->getFeedRepository()->findBy(['public' => true], ['updatedOn' => 'DESC']);

        $form = $this->app->form(new PhraseaAuthenticationForm($this->app));
        $form->setData([
            'redirect' => $request->query->get('redirect')
        ]);

        return $this->render('login/index.html.twig', array_merge(
            $this->getDefaultTemplateVariables($request),
            [
                'feeds' => $feeds,
                'form'  => $form->createView(),
            ]));
    }
1150612
public function loginAction($request)
    {
        $data = $request->get('data');
        $userModel = new ModelUser();
        $validUser = $userModel->validateLogin($data['email'], $data['password']);

        if (!$validUser) {
            $this->setMessage('danger', 'Not valid user / password combination');
            return $this->redirect(url('login'));
        }

        $this->session()->set('user', $userModel->record);
        $this->sessionClearMessages();
        return $this->redirect('/');
    }
330231
public function prosesLogin(UserFormLoginRequest $request)
    {
        // print_r($request->all());
        $users = User::where('email', $request->get('username'))->where('password',$request->get('password'))->get();
        if($users->count() > 0){
            Auth::login($users->first());
            return redirect()->intended();
            
            return redirect()->to('/')->with("message", ['alert'=> 'success', 'message'=> 'Welcome '.$users->first()->name.'.'. ' You successfully logged in.']);
        }
        return redirect()->back()->with("message", ['alert'=> 'danger', 'message'=> 'Combination Username and Password is not match']);
    }
242497
protected function sendLockoutResponse( Request $request )
	{
		$seconds = $this->secondsRemainingOnLockout( $request );

		return redirect()->back()->withInput( $request->only( $this->loginUsername(), 'remember' ) )->withErrors( [
				$this->loginUsername() => $this->getLockoutErrorMessage( $seconds ),
			] );
	}
1009447
public function postLogin(\Illuminate\Http\Request $request)
	{
		$this->validate($request, [
			'username' => 'required', 'password' => 'required',
		], [ 
			'required' => trans('common::admin.validation.required')
		]);
		
		$return_url = $request->input('return_url', '');
		if ($return_url == '') $return_url = null;

		$credentials = $request->only('username', 'password');
		
		if ($this->auth->attempt($credentials, $request->has('remember')))
		{
			if ($request->ajax())
			{
				return [ 'success' => true, 'token' => csrf_token() ];
			}
			
			return ($return_url != null ? redirect($return_url) : redirect()->route('admin-home'));
		}
		
		if ($request->ajax() || $request->wantsJson())
		{
			throw new \Illuminate\Http\Exception\HttpResponseException(
				new \Illuminate\Http\JsonResponse([ 'username' => 'Wrong username or password' ], 422)
			);
		}
		
		return redirect(route('admin-login') . '?return_url=' . urlencode($return_url))
			->withInput($request->only('username', 'remember'))
			->withErrors([
				'username' => 'Wrong username or password',
			]);
	}
1086742
public function login(Request $request)
    {
        $form = $this->form(new LoginForm());
        $form->handleRequest($request);

        if ($form->isValid()) {
            if ($this->attemptLogin($request, $form)) {
                return $this->sendLoginResponse($request);
            }
        }

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        $this->sendFailedLoginResponse($request);
    }
1265906
final public function autoLogin(Request $request): ?TokenInterface
    {
        if (null === $cookie = $request->cookies->get($this->options['name'])) {
            return null;
        }

        if (null !== $this->logger) {
            $this->logger->debug('Remember-me cookie detected.');
        }

        $cookieParts = $this->decodeCookie($cookie);

        try {
            $user = $this->processAutoLoginCookie($cookieParts, $request);

            if (!$user instanceof UserInterface) {
                throw new \RuntimeException('processAutoLoginCookie() must return a UserInterface implementation.');
            }

            if (null !== $this->logger) {
                $this->logger->info('Remember-me cookie accepted.');
            }

            return new RememberMeToken($user, $this->providerKey, $this->secret);
        } catch (CookieTheftException $e) {
            $this->loginFail($request, $e);

            throw $e;
        } catch (UsernameNotFoundException $e) {
            if (null !== $this->logger) {
                $this->logger->info('User for remember-me cookie not found.', ['exception' => $e]);
            }

            $this->loginFail($request, $e);
        } catch (UnsupportedUserException $e) {
            if (null !== $this->logger) {
                $this->logger->warning('User class for remember-me cookie not supported.', ['exception' => $e]);
            }

            $this->loginFail($request, $e);
        } catch (AuthenticationException $e) {
            if (null !== $this->logger) {
                $this->logger->debug('Remember-Me authentication failed.', ['exception' => $e]);
            }

            $this->loginFail($request, $e);
        } catch (\Exception $e) {
            $this->loginFail($request, $e);

            throw $e;
        }

        return null;
    }
792152
protected function attemptLogin(Request $request)
    {
        $token = $this->guard()->attempt($this->credentials($request));

        if ($token) {
            $this->guard()->setToken($token);

            return true;
        }

        return false;
    }
652831
public function resetPassword(Request $request)
    {
        $event = new AccessControlEvent($request);
        $this->password()->resetPasswordConfirm($request->get('token'), $request->getClientIp(), $event);

        return $this->redirectToRoute('login', ['action' => 'login']);
    }
1090264
public function loginAction(Request $request)
    {
        /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
        $session = $request->getSession();

        $authErrorKey = Security::AUTHENTICATION_ERROR;
        $lastUsernameKey = Security::LAST_USERNAME;

        // get the error if any (works with forward and redirect -- see below)
        if ($request->attributes->has($authErrorKey)) {
            $error = $request->attributes->get($authErrorKey);
        } elseif (null !== $session && $session->has($authErrorKey)) {
            $error = $session->get($authErrorKey);
            $session->remove($authErrorKey);
        } else {
            $error = null;
        }

        if (!$error instanceof AuthenticationException) {
            $error = null; // The value does not come from the security component.
        }

        // last username entered by the user
        $lastUsername = (null === $session) ? '' : $session->get($lastUsernameKey);
        $csrfToken = $this->get('security.csrf.token_manager')->getToken('authenticate')->getValue();

        return $this->render('EkynaAdminBundle:Security:login.html.twig', [
            'last_username' => $lastUsername,
            'error'         => $error,
            'token'         => $csrfToken,
        ]);
    }
325880
public function handleLogin(Login $request)
    {
        // Set the auth data
        $userData = [
            'username' => $request->get('username'),
            'password' => $request->get('password'),
        ];

        // Log in successful
        if (auth()->attempt($userData, $request->get('remember', false))) {
            event(new UserLoggedIn(auth()->user()));

            return redirect()
                ->intended(route('home'))
                ->with('message', 'You have been logged in.');
        }

        // Login failed
        return redirect(route('auth.login'))
            ->with('errors', ['Your username or password was incorrect.']);
    }
666951
public function logout(Request $request)
    {
        $event = new AccessControlEvent($request);
        /** @var Token $sessionAuth */
        $sessionAuth = $this->session()->get('authentication');
        $userId = $sessionAuth ? $sessionAuth->getToken()->getUserId() : false;
        if ($userId && $sessionAuth->getUser()) {
            $userName = $sessionAuth->getUser()->getUsername();
            $this->app['logger.system']->info('Logged out: ' . $userName, ['event' => 'authentication']);
            $event->setUserName($userName);
        }
        $this->app['dispatcher']->dispatch(AccessControlEvents::LOGOUT_SUCCESS, $event);

        // Clear the session
        $this->accessControl()->revokeSession();
        $this->session()->invalidate(-1);

        // Clear cookie data
        $response = $this->redirectToRoute('login');
        $response->headers->clearCookie(
            $this->app['token.authentication.name'],
            $request->getBasePath(),
            $this->getOption('general/cookies_domain'),
            $this->getOption('general/enforce_ssl')
        );

        return $response;
    }
581556
public function entryAction(Request $request)
    {
        $language = $this->getLanguage($request);
        $webspace = $this->getWebspace($request);

        $depth = $this->getRequestParameter($request, 'depth', false, 1);
        $ghostContent = $this->getBooleanRequestParameter($request, 'ghost-content', false, false);

        $view = $this->responseGetById(
            null,
            function() use ($language, $webspace, $depth, $ghostContent) {
                try {
                    return $this->getRepository()->getWebspaceNode(
                        $webspace,
                        $language,
                        $depth,
                        $ghostContent
                    );
                } catch (DocumentNotFoundException $ex) {
                    return;
                }
            }
        );

        return $this->handleView($view);
    }
1022376
public function logout(Request $request)
    {
        $activeGuards = 0;
        $this->guard()->logout();

        foreach (config('auth.guards') as $guard => $guardConfig) {
            if ($guardConfig['driver'] === 'session') {
                if ($this->isActiveGuard($request, $guard)) {
                    $activeGuards++;
                }
            }
        }

        if ( ! $activeGuards) {
            $request->session()->flush();
            $request->session()->regenerate();
        }

        return redirect()->to($this->logoutToPath());
    }
1130206
public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required',
            'password' => 'required',
        ]);

        if (
            $this->core->auth()
                ->login($request->input('email'), $request->input('password'), $request->has('remember'))
        ) {
            return redirect()->intended(
                $this->core->route(NamedRoute::HOME)
            );
        }

        return redirect()->back()
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'email' => Lang::has('cms::auth.failed')
                    ?   Lang::get('cms::auth.failed')
                    :   'These credentials do not match our records.',
            ]);
    }
603784
public function postLogout (Request $request)
    {
        if ($redirect = $request->getSession ()->get ('post-login-redirect'))
        {
            $request->getSession ()->set ('post-login-redirect', null);
            $request->getSession ()->set ('cancel-login-redirect', null);

            return Response::redirect ($redirect);
        }

        return Response::redirect (URLBuilder::getURL ('/'));
    }
1244529
public static function handleOAuthError(Request $request)
    {
        $error = null;

        // Try to parse content if error was not in request query
        if ($request->query->has('error')) {
            $content = json_decode($request->getContent(), true);
            if (isset($content['error']) && JSON_ERROR_NONE === json_last_error()) {
                if (isset($content['error']['message'])) {
                    throw new AuthenticationException($content['error']['message']);
                }

                if (isset($content['error']['code'])) {
                    $error = $content['error']['code'];
                } elseif (isset($content['error']['error-code'])) {
                    $error = $content['error']['error-code'];
                } else {
                    $error = $request->query->get('error');
                }
            }
        } elseif ($request->query->has('oauth_problem')) {
            $error = $request->query->get('oauth_problem');
        }

        if (null !== $error) {
            if (isset(static::$translatedOAuthErrors[$error])) {
                $error = static::$translatedOAuthErrors[$error];
            } else {
                $error = sprintf('Unknown OAuth error: "%s".', $error);
            }

            throw new AuthenticationException($error);
        }
    }