Retrieve Login form

@return Login
15719
public function getForm()
    {
        if (null === $this->form) {
            $this->setForm($this->getUserService()->getLoginForm());
        }

        return $this->form;
    }
914623
public function actionLogin()
    {
        if (! Yii::$app->getUser()->getIsGuest()) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->renderPartial('login', [
                'model' => $model,
            ]);
        }
    }
113578
public function login()
    {
        $this->defaultData();
        /** @var common_ext_ExtensionsManager $extensionManager */
        $extensionManager = $this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID);
        $extension = $extensionManager->getExtensionById('tao');
        $config = $extension->getConfig('login');

        $disableAutoComplete = !empty($config['disableAutocomplete']);
        $enablePasswordReveal = !empty($config['enablePasswordReveal']);

        $enableIframeProtection = !empty($config['block_iframe_usage']) && $config['block_iframe_usage'];
        if ($enableIframeProtection) {
            \oat\tao\model\security\IFrameBlocker::setHeader();
        }

        $params = array(
            'disableAutocomplete' => $disableAutoComplete,
            'enablePasswordReveal' => $enablePasswordReveal,
        );

        if ($this->hasRequestParameter('redirect')) {
            $redirectUrl = $_REQUEST['redirect'];

            if (substr($redirectUrl, 0,1) == '/' || substr($redirectUrl, 0, strlen(ROOT_URL)) == ROOT_URL) {
                $params['redirect'] = $redirectUrl;
            }
        }

        $container = new tao_actions_form_Login($params);
        $form = $container->getForm();

        if ($form->isSubmited()) {
            if ($form->isValid()) {

                /** @var UserLocks $userLocksService */
                $userLocksService = $this->getServiceLocator()->get(UserLocks::SERVICE_ID);
                /** @var EventManager $eventManager */
                $eventManager = $this->getServiceLocator()->get(EventManager::SERVICE_ID);

                try {
                    if ($userLocksService->isLocked($form->getValue('login'))) {
                        $this->logInfo("User '" . $form->getValue('login') . "' has been locked.");

                        $statusDetails = $userLocksService->getStatusDetails($form->getValue('login'));
                        if ($statusDetails['auto']) {
                            $msg = __('You have been locked due to too many failed login attempts. ');
                            if ($userLocksService->getOption(UserLocks::OPTION_USE_HARD_LOCKOUT)) {
                                $msg .= __('Please contact your administrator.');
                            } else {
                                /** @var DateInterval $remaining */
                                $remaining = $statusDetails['remaining'];

                                $reference = new DateTimeImmutable;
                                $endTime = $reference->add($remaining);

                                $diffInSeconds = $endTime->getTimestamp() - $reference->getTimestamp();

                                $msg .= __('Please try in %s.',
                                    $diffInSeconds > 60
                                        ? tao_helpers_Date::displayInterval($statusDetails['remaining'], tao_helpers_Date::FORMAT_INTERVAL_LONG)
                                        : $diffInSeconds . ' ' . ($diffInSeconds == 1 ? __('second') : __('seconds'))
                                );
                            }
                        } else {
                            $msg = __('Your account has been locked, please contact your administrator.');
                        }

                        $this->setData('errorMessage', $msg);
                    } else {
                        if (LoginService::login($form->getValue('login'), $form->getValue('password'))) {
                            $logins = $this->getSession()->getUser()->getPropertyValues(UserRdf::PROPERTY_LOGIN);

                            $eventManager->trigger(new LoginSucceedEvent(current($logins)));

                            $this->logInfo("Successful login of user '" . $form->getValue('login') . "'.");

                            if ($this->hasRequestParameter('redirect') && tao_models_classes_accessControl_AclProxy::hasAccessUrl($_REQUEST['redirect'])) {
                                $this->redirect($_REQUEST['redirect']);
                            } else {
                                $this->forward('entry');
                            }
                        } else {
                            $eventManager->trigger(new LoginFailedEvent($form->getValue('login')));

                            $this->logInfo("Unsuccessful login of user '" . $form->getValue('login') . "'.");

                            $msg = __('Invalid login or password. Please try again.');

                            if ($userLocksService->getOption(UserLocks::OPTION_USE_HARD_LOCKOUT)) {
                                $remainingAttempts = $userLocksService->getLockoutRemainingAttempts($form->getValue('login'));
                                if ($remainingAttempts !== false) {
                                    if ($remainingAttempts === 0) {
                                        $msg = __('Invalid login or password. Your account has been locked, please contact your administrator.');
                                    } else {
                                        $msg = $msg . ' ' .
                                            ($remainingAttempts === 1
                                                ? __('Last attempt before your account is locked.')
                                                : __('%d attempts left before your account is locked.', $remainingAttempts));
                                    }
                                }
                            }

                            $this->setData('errorMessage', $msg);
                        }
                    }
                } catch (core_kernel_users_Exception $e) {
                    $this->setData('errorMessage', __('Invalid login or password. Please try again.'));
                }
            } else {
                foreach ($form->getElements() as $formElement) {
                    $fieldError = $formElement->getError();
                    if ($fieldError) {
                        $this->setData('fieldMessages_' . $formElement->getName(), $fieldError);
                    }
                }
            }
        }

        $this->setData('title', __("TAO Login"));

        $this->setData('autocompleteDisabled', (int)$disableAutoComplete);
        $this->setData('passwordRevealEnabled', (int)$enablePasswordReveal);

        $entryPointService = $this->getServiceLocator()->get(EntryPointService::SERVICE_ID);
        $this->setData('entryPoints', $entryPointService->getEntryPoints(EntryPointService::OPTION_PRELOGIN));

        if ($this->hasRequestParameter('msg')) {
            $this->setData('msg', $this->getRequestParameter('msg'));
        }

        $this->setData('show_gdpr', !empty($config['show_gdpr']) && $config['show_gdpr']);

        $this->setData('content-template', array('blocks/login.tpl', 'tao'));

        $this->setView('layout.tpl', 'tao');
    }
892170
public function loginApplication()
    {
        $request = [
            'auth' => [
                $this->applicationKey,
                $this->applicationSecret,
            ],
            'headers' => [
                'Content-Type'  => 'application/json',
                'Accept'        => 'application/json',
            ],
            'json'  => [
                'application_bundle' => '',
            ],
        ];

        $url = $this->getRequestUrl().'/auth/login/application';

        $response = $this->getHttpClient()->post($url, $request);
        $response = json_decode($response->getBody());

        $this->connectionToken = $response->connection->token;

        return $this->connectionToken;
    }
64875
protected function getPageLogin()
    {
        $this->debug('Controller and action changed to: ' . implode("/", $this->pageLogin));
        if (isset($this->pageLogin[3]))
            $this->request()->setModule($this->pageLogin[3]);
        if (isset($this->pageLogin[2]) && is_string($this->pageLogin[2]))
            $this->request()->setModule($this->pageLogin[2]);
        elseif (isset($this->pageLogin[2]) && is_array($this->pageLogin[2]) && !empty($this->pageLogin[2]))
            $this->request()->setParams($this->pageLogin[2]);
        $this->request()->setController($this->pageLogin[0]);
        $this->request()->setAction($this->pageLogin[1]);
        return $this->getControllerClassFromNameAndModule($this->pageLogin[0], $this->request()->getModule());
    }
1320258
public function getLogin(Request $request)
    {
        $user = $this->getUser();
        if ($user && $user->getEnabled() == 1) {
            $response = $this->redirectToRoute('dashboard');

            $token = $this->session()->get('authentication');
            $this->setAuthenticationCookie($request, $response, $token);

            return $response;
        }

        if ($this->getOption('general/enforce_ssl') && !$request->isSecure()) {
            return $this->redirect(preg_replace('/^http:/i', 'https:', $request->getUri()));
        }

        $userEntity = new Entity\Users();
        // Generate the form
        $form = $this->createFormBuilder(FormType\UserLoginType::class, $userEntity)
            ->getForm()
            ->handleRequest($request)
        ;
        /** @var Form $form */
        if ($form->isSubmitted() && $form->isValid()) {
            $action = $form->getClickedButton()->getName();
            if ($action === 'login') {
                $response = $this->handlePostLogin($request, $form);
            } elseif ($action === 'reset') {
                $response = $this->handlePostReset($request, $form);
            } else {
                // Let's not disclose any internal information.
                throw new HttpException(Response::HTTP_BAD_REQUEST, 'Invalid request');
            }
            if ($response instanceof Response) {
                return $response;
            }
        }
        $context = [
            'form'        => $form->createView(),
            'randomquote' => true,
        ];

        return $this->render('@bolt/login/login.twig', $context);
    }
1038900
public function login()
    {
        $_SESSION['auth'] = 'login';

        if ($this->userStore->find()->count() === 0) {
            return $this->redirect('/setup');
        }

        Event::trigger('beforeLogin', $this);

        if ($this->request->getMethod() == 'POST') {
            $user = Store::get('User')->getByEmail($this->getParam('email'));

            if ($user && password_verify($this->getParam('password', ''), $user->getHash())) {
                $_SESSION['user_id'] = $user->getId();

                $url = $this->config->get('site.full_admin_url');

                if (isset($_SESSION['previous_url'])) {
                    $url = $_SESSION['previous_url'];
                }

                return $this->redirect($url);
            } else {
                Event::trigger('loginFailed', $this->view);
                $this->template->errorMessage = 'Your email address or password were incorrect.';
            }
        }
    }
175165
public function getLoginLinkElement()
    {
        $element = $this->getElement($this->_tokenFieldName);

        if (! $element) {
            // Login link
            if ($link = $this->getLoginLink()) {
                $element = new \MUtil_Form_Element_Html($this->_loginLinkFieldName);
                // $element->br();
                $element->setValue($link);

                $this->addElement($element);
            }

            return $element;
        }
    }
674515
public function actionLogin()
    {
        $requiredPackages = [
            'rbac' => \Yiisoft\Rbac\Permission::class,
            #'db-mysql' => \Yiisoft\Db\Mysql\Schema::class,
            'yii-bootstrap4' => \Yiisoft\Yii\Bootstrap4\ActiveForm::class,
        ];
        $setupIncomplete = in_array(false, array_map('class_exists', $requiredPackages));

        if (!$setupIncomplete && !$this->app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load($this->app->request->post()) && $model->login()) {
            return $this->goBack();
        }

        $model->password = '';
        return $this->render('login', [
            'model' => $model,
            'requiredPackages' => $requiredPackages,
            'setupIncomplete' => $setupIncomplete,
        ]);
    }
1012456
public function loginAction()
    {
        if ($this->getUser()) {
            return $this->redirectToRoute($this->get(Configuration::class)->getHomeRoute());
        }
        $authenticationUtils = $this->get('security.authentication_utils');

        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();

        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();

        return [
            'last_username' => $lastUsername,
            'error' => $error,
        ];
    }
293615
protected function createComponentForgottenPasswordForm(): Form
	{
		$form = $this->formFactory->create();
		$form->addProtection();

		$form->addText('usernameOrEmail', 'cms.user.usernameOrEmail')
			->setRequired();

		$form->addSubmit('send', 'form.send');

		$form->addLink('back', 'form.back', $this->link('in'));

		$form->onSuccess[] = [$this, 'forgottenPasswordFormSucceeded'];

		return $form;
	}
1110508
public function getPostLogin()
    {
        $form       = new UserLoginForm($this->di);
        $form->check();

        $views = [
            ["comment/user/pre/login", ["form" => $form->getHTML()], "main"]
        ];

        $this->di->get("pageRenderComment")->renderPage([
            "views" => $views,
            "title" => "Login"
        ]);
    }
1344838
public function getLoginUrl()
	{
		$loginUrl = $this->helper->getLoginUrl($this->callBackUrl, $this->scope);
		return $loginUrl;
	}
845862
public function login()
    {
        $requestBody = $this->request->getBody();
        if (empty($requestBody['apiKey'])) {
            return $this->api->createAPIError("Missing required parameter: 'apiKey'.");
        }
        if (empty($requestBody['email'])) {
            return $this->api->createAPIError("Missing required parameter: 'email'.");
        }

        $isCreated = $this->dataStore->createUserDataStore($requestBody['apiKey'], $requestBody['email'], null, null);
        if (!$isCreated) {
            return $this->api->createAPIError('Unable to save user credentials');
        }

        //Make a test request to see if the API Key, email are valid
        $testRequest = new Request('GET', 'user/', array(), array());
        $testResponse = $this->clientAPI->callAPI($testRequest);
        if (!$this->clientAPI->responseOk($testResponse)) {
            //remove bad credentials
            $this->dataStore->createUserDataStore(null, null, null, null);

            return $this->api->createAPIError('Email address or API key invalid.');
        }

        $response = $this->api->createAPISuccessResponse(array('email' => $requestBody['email']));

        return $response;
    }
547228
public function print_login() {
        $keyword = new stdClass();
        $keyword->label = get_string('keyword', 'repository_wikimedia').': ';
        $keyword->id    = 'input_text_keyword';
        $keyword->type  = 'text';
        $keyword->name  = 'wikimedia_keyword';
        $keyword->value = '';
        $maxwidth = array(
            'label' => get_string('maxwidth', 'repository_wikimedia').': ',
            'type' => 'text',
            'name' => 'wikimedia_maxwidth',
            'value' => get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH),
        );
        $maxheight = array(
            'label' => get_string('maxheight', 'repository_wikimedia').': ',
            'type' => 'text',
            'name' => 'wikimedia_maxheight',
            'value' => get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH),
        );
        if ($this->options['ajax']) {
            $form = array();
            $form['login'] = array($keyword, (object)$maxwidth, (object)$maxheight);
            $form['nologin'] = true;
            $form['norefresh'] = true;
            $form['nosearch'] = true;
            $form['allowcaching'] = false; // indicates that login form can NOT
            // be cached in filepicker.js (maxwidth and maxheight are dynamic)
            return $form;
        } else {
            echo <<<EOD
<table>
<tr>
<td>{$keyword->label}</td><td><input name="{$keyword->name}" type="text" /></td>
</tr>
</table>
<input type="submit" />
EOD;
        }
    }
393004
public function actionLogin()
    {
        if (!Yii::$app->user->isGuest) {
            Yii::$app->session->setFlash('danger', Yii::t('user', 'You are already logged in.'));
            return $this->goHome();
        }
        if (Yii::$app->request->isGet) {
            Yii::$app->user->setReturnUrl(Yii::$app->request->getReferrer());
        }

        /**
         * @var LoginForm $model
         */
        $model = new LoginForm();
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
            return $this->goBack(Yii::$app->getHomeUrl());
        }
        if (Yii::$app->request->isAjax) {
            return $this->renderAjax('login_modal', [
                'model' => $model,
                'module' => $this->module,
            ]);
        }
        return $this->render('login', ['model' => $model, 'module' => $this->module]);
    }
685160
public function login() {
        $state = Str::randomNumber(7);
        Factory::session()->set('state', $state);
        $this->set('state', $state);
        return $this->getLogin()->getUrl();
    }