From 1942f11d5ee6926ad93dc1b79fae18325ba5de18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Jun 2020 14:49:20 +0200 Subject: Lazy load all routes --- client/src/app/+login/login-routing.module.ts | 27 +++++ client/src/app/+login/login.component.html | 114 ++++++++++++++++++++ client/src/app/+login/login.component.scss | 66 ++++++++++++ client/src/app/+login/login.component.ts | 147 ++++++++++++++++++++++++++ client/src/app/+login/login.module.ts | 28 +++++ 5 files changed, 382 insertions(+) create mode 100644 client/src/app/+login/login-routing.module.ts create mode 100644 client/src/app/+login/login.component.html create mode 100644 client/src/app/+login/login.component.scss create mode 100644 client/src/app/+login/login.component.ts create mode 100644 client/src/app/+login/login.module.ts (limited to 'client/src/app/+login') diff --git a/client/src/app/+login/login-routing.module.ts b/client/src/app/+login/login-routing.module.ts new file mode 100644 index 000000000..aad55eac8 --- /dev/null +++ b/client/src/app/+login/login-routing.module.ts @@ -0,0 +1,27 @@ +import { NgModule } from '@angular/core' +import { RouterModule, Routes } from '@angular/router' +import { MetaGuard } from '@ngx-meta/core' +import { LoginComponent } from './login.component' +import { ServerConfigResolver } from '@app/core/routing/server-config-resolver.service' + +const loginRoutes: Routes = [ + { + path: '', + component: LoginComponent, + canActivate: [ MetaGuard ], + data: { + meta: { + title: 'Login' + } + }, + resolve: { + serverConfig: ServerConfigResolver + } + } +] + +@NgModule({ + imports: [ RouterModule.forChild(loginRoutes) ], + exports: [ RouterModule ] +}) +export class LoginRoutingModule {} diff --git a/client/src/app/+login/login.component.html b/client/src/app/+login/login.component.html new file mode 100644 index 000000000..599b203ae --- /dev/null +++ b/client/src/app/+login/login.component.html @@ -0,0 +1,114 @@ +
+
+ Login +
+ +
+ Sorry but there was an issue with the external login process. Please contact an administrator. +
+ + + + + + + + + +
+ + + + + + + + diff --git a/client/src/app/+login/login.component.scss b/client/src/app/+login/login.component.scss new file mode 100644 index 000000000..fde6cc15e --- /dev/null +++ b/client/src/app/+login/login.component.scss @@ -0,0 +1,66 @@ +@import '_variables'; +@import '_mixins'; + +label { + display: block; +} + +input:not([type=submit]) { + @include peertube-input-text(340px); + display: inline-block; + margin-right: 5px; + +} + +input[type=submit] { + @include peertube-button; + @include orange-button; +} + +.create-an-account, .forgot-password-button { + color: pvar(--mainForegroundColor); + cursor: pointer; + transition: opacity cubic-bezier(0.39, 0.575, 0.565, 1); + + &:hover { + text-decoration: none !important; + opacity: .7 !important; + } +} + +.login-form-and-externals { + display: flex; + flex-wrap: wrap; + font-size: 15px; + + form { + margin: 0 50px 20px 0; + } + + .external-login-blocks { + min-width: 200px; + + .block-title { + font-weight: $font-semibold; + } + + .external-login-block { + @include disable-default-a-behaviour; + + cursor: pointer; + border: 1px solid #d1d7e0; + border-radius: 5px; + color: pvar(--mainForegroundColor); + margin: 10px 10px 0 0; + display: flex; + justify-content: center; + align-items: center; + min-height: 35px; + min-width: 100px; + + &:hover { + background-color: rgba(209, 215, 224, 0.5) + } + } + } +} diff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.ts new file mode 100644 index 000000000..cbc51ee21 --- /dev/null +++ b/client/src/app/+login/login.component.ts @@ -0,0 +1,147 @@ +import { environment } from 'src/environments/environment' +import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core' +import { ActivatedRoute } from '@angular/router' +import { AuthService, Notifier, RedirectService, UserService } from '@app/core' +import { HooksService } from '@app/core/plugins/hooks.service' +import { FormReactive, FormValidatorService, LoginValidatorsService } from '@app/shared/shared-forms' +import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models' + +@Component({ + selector: 'my-login', + templateUrl: './login.component.html', + styleUrls: [ './login.component.scss' ] +}) + +export class LoginComponent extends FormReactive implements OnInit, AfterViewInit { + @ViewChild('usernameInput', { static: false }) usernameInput: ElementRef + @ViewChild('forgotPasswordModal', { static: true }) forgotPasswordModal: ElementRef + + error: string = null + forgotPasswordEmail = '' + + isAuthenticatedWithExternalAuth = false + externalAuthError = false + externalLogins: string[] = [] + + private openedForgotPasswordModal: NgbModalRef + private serverConfig: ServerConfig + + constructor ( + protected formValidatorService: FormValidatorService, + private route: ActivatedRoute, + private modalService: NgbModal, + private loginValidatorsService: LoginValidatorsService, + private authService: AuthService, + private userService: UserService, + private redirectService: RedirectService, + private notifier: Notifier, + private hooks: HooksService, + private i18n: I18n + ) { + super() + } + + get signupAllowed () { + return this.serverConfig.signup.allowed === true + } + + isEmailDisabled () { + return this.serverConfig.email.enabled === false + } + + ngOnInit () { + const snapshot = this.route.snapshot + + this.serverConfig = snapshot.data.serverConfig + + if (snapshot.queryParams.externalAuthToken) { + this.loadExternalAuthToken(snapshot.queryParams.username, snapshot.queryParams.externalAuthToken) + return + } + + if (snapshot.queryParams.externalAuthError) { + this.externalAuthError = true + return + } + + this.buildForm({ + username: this.loginValidatorsService.LOGIN_USERNAME, + password: this.loginValidatorsService.LOGIN_PASSWORD + }) + } + + ngAfterViewInit () { + if (this.usernameInput) { + this.usernameInput.nativeElement.focus() + } + + this.hooks.runAction('action:login.init', 'login') + } + + getExternalLogins () { + return this.serverConfig.plugin.registeredExternalAuths + } + + getAuthHref (auth: RegisteredExternalAuthConfig) { + return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}` + } + + login () { + this.error = null + + const { username, password } = this.form.value + + this.authService.login(username, password) + .subscribe( + () => this.redirectService.redirectToPreviousRoute(), + + err => this.handleError(err) + ) + } + + askResetPassword () { + this.userService.askResetPassword(this.forgotPasswordEmail) + .subscribe( + () => { + const message = this.i18n( + 'An email with the reset password instructions will be sent to {{email}}. The link will expire within 1 hour.', + { email: this.forgotPasswordEmail } + ) + this.notifier.success(message) + this.hideForgotPasswordModal() + }, + + err => this.notifier.error(err.message) + ) + } + + openForgotPasswordModal () { + this.openedForgotPasswordModal = this.modalService.open(this.forgotPasswordModal) + } + + hideForgotPasswordModal () { + this.openedForgotPasswordModal.close() + } + + private loadExternalAuthToken (username: string, token: string) { + this.isAuthenticatedWithExternalAuth = true + + this.authService.login(username, null, token) + .subscribe( + () => this.redirectService.redirectToPreviousRoute(), + + err => { + this.handleError(err) + this.isAuthenticatedWithExternalAuth = false + } + ) + } + + private handleError (err: any) { + if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect username or password.') + else if (err.message.indexOf('blocked') !== -1) this.error = this.i18n('You account is blocked.') + else this.error = err.message + } +} diff --git a/client/src/app/+login/login.module.ts b/client/src/app/+login/login.module.ts new file mode 100644 index 000000000..c41902426 --- /dev/null +++ b/client/src/app/+login/login.module.ts @@ -0,0 +1,28 @@ +import { NgModule } from '@angular/core' +import { SharedFormModule } from '@app/shared/shared-forms' +import { SharedGlobalIconModule } from '@app/shared/shared-icons' +import { SharedMainModule } from '@app/shared/shared-main' +import { LoginRoutingModule } from './login-routing.module' +import { LoginComponent } from './login.component' + +@NgModule({ + imports: [ + LoginRoutingModule, + + SharedMainModule, + SharedFormModule, + SharedGlobalIconModule + ], + + declarations: [ + LoginComponent + ], + + exports: [ + LoginComponent + ], + + providers: [ + ] +}) +export class LoginModule { } -- cgit v1.2.3