From a21d69765ba59a8d83e82cc392524ba4249b1a55 Mon Sep 17 00:00:00 2001 From: bossenti Date: Fri, 20 Jan 2023 20:26:28 +0100 Subject: [PATCH] [#877] apply formatting and linting to login module --- ui/.eslintignore | 1 - ui/.prettierignore | 1 - .../activate-account.component.html | 13 +- .../activate-account.component.ts | 61 ++++--- .../components/auth-box/auth-box.component.ts | 23 +-- .../components/login/login.component.html | 82 ++++++--- .../components/login/login.component.scss | 20 +-- .../login/components/login/login.component.ts | 75 ++++---- .../app/login/components/login/login.model.ts | 4 +- .../register/register.component.html | 62 +++++-- .../components/register/register.component.ts | 95 +++++----- .../components/register/registration.model.ts | 4 +- .../restore-password.component.html | 41 +++-- .../restore-password.component.ts | 72 ++++---- .../set-new-password.component.html | 61 +++++-- .../set-new-password.component.ts | 131 ++++++++------ .../components/setup/setup.component.html | 165 +++++++++++++----- .../components/setup/setup.component.scss | 54 +++--- .../login/components/setup/setup.component.ts | 113 ++++++------ .../components/startup/startup.component.html | 40 ++++- .../components/startup/startup.component.scss | 5 +- .../components/startup/startup.component.ts | 40 +++-- ui/src/app/login/login.module.ts | 11 +- .../services/account-activation.service.ts | 18 +- ui/src/app/login/services/login.service.ts | 69 +++++--- .../services/restore-password.service.ts | 30 ++-- ui/src/app/login/utils/check-password.ts | 16 +- 27 files changed, 793 insertions(+), 514 deletions(-) diff --git a/ui/.eslintignore b/ui/.eslintignore index c980966c1a..40d6f53866 100644 --- a/ui/.eslintignore +++ b/ui/.eslintignore @@ -28,4 +28,3 @@ src/app/data-explorer src/app/editor src/app/files src/app/info -src/app/login diff --git a/ui/.prettierignore b/ui/.prettierignore index 3930e91eeb..3ac17556ea 100644 --- a/ui/.prettierignore +++ b/ui/.prettierignore @@ -28,4 +28,3 @@ src/app/data-explorer src/app/editor src/app/files src/app/info -src/app/login diff --git a/ui/src/app/login/components/activate-account/activate-account.component.html b/ui/src/app/login/components/activate-account/activate-account.component.html index 1dfef7fcd2..b9d61e8959 100644 --- a/ui/src/app/login/components/activate-account/activate-account.component.html +++ b/ui/src/app/login/components/activate-account/activate-account.component.html @@ -23,14 +23,19 @@

Account activation

-
Verifying account activation...
-
Account successfully activated.
-
Your account could not be activated.
+
+ Verifying account activation... +
+
+ Account successfully activated. +
+
+ Your account could not be activated. +
Go to login page
- diff --git a/ui/src/app/login/components/activate-account/activate-account.component.ts b/ui/src/app/login/components/activate-account/activate-account.component.ts index 6608661273..8bc81272f7 100644 --- a/ui/src/app/login/components/activate-account/activate-account.component.ts +++ b/ui/src/app/login/components/activate-account/activate-account.component.ts @@ -21,38 +21,43 @@ import { AccountActivationService } from '../../services/account-activation.serv import { ActivatedRoute, Router } from '@angular/router'; @Component({ - selector: 'sp-activate-account', - templateUrl: './activate-account.component.html', - styleUrls: ['../login/login.component.scss'] + selector: 'sp-activate-account', + templateUrl: './activate-account.component.html', + styleUrls: ['../login/login.component.scss'], }) export class ActivateAccountComponent implements OnInit { + activationCode: string; + activationSuccess: boolean; + activationPerformed = false; - activationCode: string; - activationSuccess: boolean; - activationPerformed = false; + constructor( + private accountActivationService: AccountActivationService, + private route: ActivatedRoute, + private router: Router, + ) {} - constructor(private accountActivationService: AccountActivationService, - private route: ActivatedRoute, - private router: Router) {} - - ngOnInit(): void { - this.route.queryParams.subscribe(params => { - this.activationCode = params['activationCode']; - if (this.activationCode) { - this.accountActivationService.activateAccount(this.activationCode).subscribe(success => { - this.activationPerformed = true; - this.activationSuccess = true; - }, error => { - this.activationPerformed = true; + ngOnInit(): void { + this.route.queryParams.subscribe(params => { + this.activationCode = params['activationCode']; + if (this.activationCode) { + this.accountActivationService + .activateAccount(this.activationCode) + .subscribe( + success => { + this.activationPerformed = true; + this.activationSuccess = true; + }, + error => { + this.activationPerformed = true; + }, + ); + } else { + this.activationPerformed = true; + } }); - } else { - this.activationPerformed = true; - } - }); - } - - navigateToLoginPage() { - this.router.navigate(['/login']); - } + } + navigateToLoginPage() { + this.router.navigate(['/login']); + } } diff --git a/ui/src/app/login/components/auth-box/auth-box.component.ts b/ui/src/app/login/components/auth-box/auth-box.component.ts index 6ad5ad11b9..c0b7210920 100644 --- a/ui/src/app/login/components/auth-box/auth-box.component.ts +++ b/ui/src/app/login/components/auth-box/auth-box.component.ts @@ -16,22 +16,15 @@ * */ -import { Component, OnInit } from '@angular/core'; +import { Component } from '@angular/core'; @Component({ - selector: 'sp-auth-box', - templateUrl: './auth-box.component.html', - styleUrls: ['./auth-box.component.scss'] + selector: 'sp-auth-box', + templateUrl: './auth-box.component.html', + styleUrls: ['./auth-box.component.scss'], }) -export class AuthBoxComponent implements OnInit { - - - ngOnInit(): void { - } - - openDocumentation() { - window.open('https://streampipes.apache.org/docs', '_blank'); - } - - +export class AuthBoxComponent { + openDocumentation() { + window.open('https://streampipes.apache.org/docs', '_blank'); + } } diff --git a/ui/src/app/login/components/login/login.component.html b/ui/src/app/login/components/login/login.component.html index afc06d0536..9dbe7a311f 100644 --- a/ui/src/app/login/components/login/login.component.html +++ b/ui/src/app/login/components/login/login.component.html @@ -21,49 +21,77 @@

Login

-
+
Email - + Password - +
-
- - +
- +
- | + + | + diff --git a/ui/src/app/login/components/login/login.component.scss b/ui/src/app/login/components/login/login.component.scss index 44908d5c98..3b4edba73f 100644 --- a/ui/src/app/login/components/login/login.component.scss +++ b/ui/src/app/login/components/login/login.component.scss @@ -17,23 +17,23 @@ */ .login-error { - background: #ffa2a2; - padding: 8px; - color: #3e3e3e; - border-radius: 5px; + background: #ffa2a2; + padding: 8px; + color: #3e3e3e; + border-radius: 5px; } .info-box { - padding: 8px; - border-radius: 5px; + padding: 8px; + border-radius: 5px; } .register-error { - background: #ffa2a2; - color: #3e3e3e; + background: #ffa2a2; + color: #3e3e3e; } .register-success { - background: #a2ffa2; - color: #3e3e3e; + background: #a2ffa2; + color: #3e3e3e; } diff --git a/ui/src/app/login/components/login/login.component.ts b/ui/src/app/login/components/login/login.component.ts index 8ad2670a89..e02143d6c3 100644 --- a/ui/src/app/login/components/login/login.component.ts +++ b/ui/src/app/login/components/login/login.component.ts @@ -22,15 +22,19 @@ import { LoginService } from '../../services/login.service'; import { Router } from '@angular/router'; import { AuthService } from '../../../services/auth.service'; import { LoginModel } from './login.model'; -import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { + UntypedFormBuilder, + UntypedFormControl, + UntypedFormGroup, + Validators, +} from '@angular/forms'; @Component({ - selector: 'login', + selector: 'sp-login', templateUrl: './login.component.html', - styleUrls: ['./login.component.scss'] + styleUrls: ['./login.component.scss'], }) export class LoginComponent implements OnInit { - parentForm: UntypedFormGroup; configReady = false; loading: boolean; @@ -39,46 +43,55 @@ export class LoginComponent implements OnInit { loginSettings: LoginModel; - constructor(private loginService: LoginService, - private router: Router, - private shepherdService: ShepherdService, - private authService: AuthService, - private fb: UntypedFormBuilder) { + constructor( + private loginService: LoginService, + private router: Router, + private shepherdService: ShepherdService, + private authService: AuthService, + private fb: UntypedFormBuilder, + ) { this.loading = false; this.authenticationFailed = false; this.credentials = {}; } ngOnInit() { - this.loginService.fetchLoginSettings().subscribe(result => { - this.loginSettings = result; - this.configReady = true; - this.parentForm = this.fb.group({}); - this.parentForm.addControl('username', new UntypedFormControl('', Validators.required)); - this.parentForm.addControl('password', new UntypedFormControl('', Validators.required)); + this.loginService.fetchLoginSettings().subscribe(result => { + this.loginSettings = result; + this.configReady = true; + this.parentForm = this.fb.group({}); + this.parentForm.addControl( + 'username', + new UntypedFormControl('', Validators.required), + ); + this.parentForm.addControl( + 'password', + new UntypedFormControl('', Validators.required), + ); - this.parentForm.valueChanges.subscribe(v => { - this.credentials.username = v.username; - this.credentials.password = v.password; + this.parentForm.valueChanges.subscribe(v => { + this.credentials.username = v.username; + this.credentials.password = v.password; + }); }); - }); } - - logIn() { this.authenticationFailed = false; this.loading = true; - this.loginService.login(this.credentials) - .subscribe(response => { // success - this.authService.login(response); - this.loading = false; - this.router.navigate(['']); - }, response => { // error - this.loading = false; - this.authenticationFailed = true; - } - ); + this.loginService.login(this.credentials).subscribe( + response => { + // success + this.authService.login(response); + this.loading = false; + this.router.navigate(['']); + }, + response => { + // error + this.loading = false; + this.authenticationFailed = true; + }, + ); } setSheperdServiceDelay() { diff --git a/ui/src/app/login/components/login/login.model.ts b/ui/src/app/login/components/login/login.model.ts index 6e7dcef110..15e2b3b6c4 100644 --- a/ui/src/app/login/components/login/login.model.ts +++ b/ui/src/app/login/components/login/login.model.ts @@ -17,6 +17,6 @@ */ export interface LoginModel { - allowSelfRegistration: boolean; - allowPasswordRecovery: boolean; + allowSelfRegistration: boolean; + allowPasswordRecovery: boolean; } diff --git a/ui/src/app/login/components/register/register.component.html b/ui/src/app/login/components/register/register.component.html index 19495031b9..3a5f40d23a 100644 --- a/ui/src/app/login/components/register/register.component.html +++ b/ui/src/app/login/components/register/register.component.html @@ -25,37 +25,61 @@

Register

Email - - Must be an email address. + + Must be an email address. Initial password - + Repeat password - + - Passwords do not match. -
- - +
-
{{registrationError}}
+
+ {{ registrationError }} +
-
We've sent out a confirmation mail to this address.
+
+ We've sent out a confirmation mail to this address. +
Go to login page diff --git a/ui/src/app/login/components/register/register.component.ts b/ui/src/app/login/components/register/register.component.ts index 33c88484a8..6be4c59838 100644 --- a/ui/src/app/login/components/register/register.component.ts +++ b/ui/src/app/login/components/register/register.component.ts @@ -18,60 +18,71 @@ import { Component, OnInit } from '@angular/core'; import { - UntypedFormBuilder, - UntypedFormControl, - UntypedFormGroup, - Validators + UntypedFormBuilder, + UntypedFormControl, + UntypedFormGroup, + Validators, } from '@angular/forms'; import { RegistrationModel } from './registration.model'; import { LoginService } from '../../services/login.service'; import { checkPasswords } from '../../utils/check-password'; @Component({ - selector: 'sp-register-user', - templateUrl: './register.component.html', - styleUrls: ['../login/login.component.scss'] + selector: 'sp-register-user', + templateUrl: './register.component.html', + styleUrls: ['../login/login.component.scss'], }) export class RegisterComponent implements OnInit { + parentForm: UntypedFormGroup; - parentForm: UntypedFormGroup; + registrationData: RegistrationModel; - registrationData: RegistrationModel; + registrationInProcess = false; + registrationSuccess = false; + registrationError: string; - registrationInProcess = false; - registrationSuccess = false; - registrationError: string; + constructor( + private fb: UntypedFormBuilder, + private loginService: LoginService, + ) {} - constructor(private fb: UntypedFormBuilder, - private loginService: LoginService) { - } + ngOnInit(): void { + this.parentForm = this.fb.group({}); + this.parentForm.addControl( + 'username', + new UntypedFormControl('', [Validators.required, Validators.email]), + ); + this.parentForm.addControl( + 'password', + new UntypedFormControl('', Validators.required), + ); + this.parentForm.addControl( + 'repeatPassword', + new UntypedFormControl('', Validators.required), + ); + this.parentForm.setValidators(checkPasswords); - ngOnInit(): void { - this.parentForm = this.fb.group({}); - this.parentForm.addControl('username', new UntypedFormControl('', [Validators.required, Validators.email])); - this.parentForm.addControl('password', new UntypedFormControl('', Validators.required)); - this.parentForm.addControl('repeatPassword', new UntypedFormControl('', Validators.required)); - this.parentForm.setValidators(checkPasswords); + this.parentForm.valueChanges.subscribe(v => { + this.registrationData = { + username: v.username, + password: v.password, + }; + }); + } - this.parentForm.valueChanges.subscribe(v => { - this.registrationData = { - username: v.username, - password: v.password - }; - }); - } - - registerUser() { - this.registrationError = undefined; - this.registrationInProcess = true; - this.loginService.registerUser(this.registrationData).subscribe(response => { - this.registrationInProcess = false; - this.registrationSuccess = true; - }, error => { - this.registrationInProcess = false; - this.registrationSuccess = false; - this.registrationError = error.error.notifications[0].title; - }); - } + registerUser() { + this.registrationError = undefined; + this.registrationInProcess = true; + this.loginService.registerUser(this.registrationData).subscribe( + response => { + this.registrationInProcess = false; + this.registrationSuccess = true; + }, + error => { + this.registrationInProcess = false; + this.registrationSuccess = false; + this.registrationError = error.error.notifications[0].title; + }, + ); + } } - diff --git a/ui/src/app/login/components/register/registration.model.ts b/ui/src/app/login/components/register/registration.model.ts index 6f14b16a61..347cf60447 100644 --- a/ui/src/app/login/components/register/registration.model.ts +++ b/ui/src/app/login/components/register/registration.model.ts @@ -17,6 +17,6 @@ */ export interface RegistrationModel { - username: string; - password: string; + username: string; + password: string; } diff --git a/ui/src/app/login/components/restore-password/restore-password.component.html b/ui/src/app/login/components/restore-password/restore-password.component.html index 6aac568449..5d3cf40e55 100644 --- a/ui/src/app/login/components/restore-password/restore-password.component.html +++ b/ui/src/app/login/components/restore-password/restore-password.component.html @@ -16,30 +16,49 @@ ~ --> -

Restore password

-
Enter your mail address and we'll send you a link to restore your password.
+
+ Enter your mail address and we'll send you a link to restore your + password. +
Email - + -
- -
-
Unknown error - contact your administrator to check the mail settings.
+
+
+ Unknown error - contact your administrator to check + the mail settings. +
-
-
In case this account exists, you'll receive a mail with instructions to restore your password shortly.
+
+
+ In case this account exists, you'll receive a mail + with instructions to restore your password shortly. +
Go to login page diff --git a/ui/src/app/login/components/restore-password/restore-password.component.ts b/ui/src/app/login/components/restore-password/restore-password.component.ts index d820fea0e5..53d2dbe764 100644 --- a/ui/src/app/login/components/restore-password/restore-password.component.ts +++ b/ui/src/app/login/components/restore-password/restore-password.component.ts @@ -17,46 +17,54 @@ */ import { Component, OnInit } from '@angular/core'; -import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { + UntypedFormBuilder, + UntypedFormControl, + UntypedFormGroup, + Validators, +} from '@angular/forms'; import { LoginService } from '../../services/login.service'; @Component({ - selector: 'sp-restore-password', - templateUrl: './restore-password.component.html', - styleUrls: ['../login/login.component.scss'] + selector: 'sp-restore-password', + templateUrl: './restore-password.component.html', + styleUrls: ['../login/login.component.scss'], }) export class RestorePasswordComponent implements OnInit { + parentForm: UntypedFormGroup; + restoreSuccess = false; + restoreCompleted = false; - parentForm: UntypedFormGroup; - restoreSuccess = false; - restoreCompleted = false; + username: string; - username: string; + constructor( + private fb: UntypedFormBuilder, + private loginService: LoginService, + ) {} - constructor(private fb: UntypedFormBuilder, - private loginService: LoginService) { - } - - ngOnInit(): void { - this.parentForm = this.fb.group({}); - this.parentForm.addControl('username', new UntypedFormControl('', Validators.required)); - - this.parentForm.valueChanges.subscribe(result => { - this.username = result.username; - }); - } - - sendRestorePasswordLink() { - this.restoreCompleted = false; - this.loginService.sendRestorePasswordLink(this.username).subscribe(response => { - this.restoreSuccess = true; - this.restoreCompleted = true; - }, error => { - this.restoreSuccess = false; - this.restoreCompleted = true; - }); - } + ngOnInit(): void { + this.parentForm = this.fb.group({}); + this.parentForm.addControl( + 'username', + new UntypedFormControl('', Validators.required), + ); + this.parentForm.valueChanges.subscribe(result => { + this.username = result.username; + }); + } + sendRestorePasswordLink() { + this.restoreCompleted = false; + this.loginService.sendRestorePasswordLink(this.username).subscribe( + response => { + this.restoreSuccess = true; + this.restoreCompleted = true; + }, + error => { + this.restoreSuccess = false; + this.restoreCompleted = true; + }, + ); + } } - diff --git a/ui/src/app/login/components/set-new-password/set-new-password.component.html b/ui/src/app/login/components/set-new-password/set-new-password.component.html index 95b159c17e..425f109784 100644 --- a/ui/src/app/login/components/set-new-password/set-new-password.component.html +++ b/ui/src/app/login/components/set-new-password/set-new-password.component.html @@ -25,30 +25,57 @@

Set new password

New password - + Repeat password - + -
- - -
-
There was an error while resetting your password.
+ +
+
+ There was an error while resetting your password. +
-
-
Password successfully changed.
+
+
+ Password successfully changed. +
Go to login page diff --git a/ui/src/app/login/components/set-new-password/set-new-password.component.ts b/ui/src/app/login/components/set-new-password/set-new-password.component.ts index 563108a33d..65d7eb15f4 100644 --- a/ui/src/app/login/components/set-new-password/set-new-password.component.ts +++ b/ui/src/app/login/components/set-new-password/set-new-password.component.ts @@ -18,75 +18,94 @@ import { Component, OnInit } from '@angular/core'; import { RestorePasswordService } from '../../services/restore-password.service'; -import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { + UntypedFormBuilder, + UntypedFormControl, + UntypedFormGroup, + Validators, +} from '@angular/forms'; import { checkPasswords } from '../../utils/check-password'; import { RegistrationModel } from '../register/registration.model'; import { ActivatedRoute, Router } from '@angular/router'; @Component({ - selector: 'sp-set-new-password', - templateUrl: './set-new-password.component.html', - styleUrls: ['../login/login.component.scss'] + selector: 'sp-set-new-password', + templateUrl: './set-new-password.component.html', + styleUrls: ['../login/login.component.scss'], }) export class SetNewPasswordComponent implements OnInit { + parentForm: UntypedFormGroup; + registrationModel: RegistrationModel; + recoveryCode: string; - parentForm: UntypedFormGroup; - registrationModel: RegistrationModel; - recoveryCode: string; + resetPerformed = false; + resetInProgress = false; + resetSuccess = false; - resetPerformed = false; - resetInProgress = false; - resetSuccess = false; + constructor( + private fb: UntypedFormBuilder, + private restorePasswordService: RestorePasswordService, + private route: ActivatedRoute, + private router: Router, + ) {} - constructor(private fb: UntypedFormBuilder, - private restorePasswordService: RestorePasswordService, - private route: ActivatedRoute, - private router: Router) { - - } - - ngOnInit(): void { - this.route.queryParams.subscribe(params => { - this.recoveryCode = params['recoveryCode']; - if (this.recoveryCode) { - this.restorePasswordService.checkRecoveryCode(this.recoveryCode).subscribe(success => { - }, error => { - this.navigateToLoginPage(); + ngOnInit(): void { + this.route.queryParams.subscribe(params => { + this.recoveryCode = params['recoveryCode']; + if (this.recoveryCode) { + this.restorePasswordService + .checkRecoveryCode(this.recoveryCode) + .subscribe( + success => {}, + error => { + this.navigateToLoginPage(); + }, + ); + } else { + this.navigateToLoginPage(); + } }); - } else { - this.navigateToLoginPage(); - } - }); - this.parentForm = this.fb.group({}); - this.parentForm.addControl('password', new UntypedFormControl('', Validators.required)); - this.parentForm.addControl('repeatPassword', new UntypedFormControl('', Validators.required)); - this.parentForm.setValidators(checkPasswords); - - this.parentForm.valueChanges.subscribe(v => { - this.registrationModel = {username: '', password: v.password}; - }); - } + this.parentForm = this.fb.group({}); + this.parentForm.addControl( + 'password', + new UntypedFormControl('', Validators.required), + ); + this.parentForm.addControl( + 'repeatPassword', + new UntypedFormControl('', Validators.required), + ); + this.parentForm.setValidators(checkPasswords); - navigateToLoginPage() { - this.router.navigate(['/login']); - } - - setNewPassword() { - this.updateStatus(true, false, false); - this.restorePasswordService.restorePassword(this.recoveryCode, this.registrationModel).subscribe(result => { - this.updateStatus(false, true, true); - }, error => { - this.updateStatus(false, false, true); - }); - } + this.parentForm.valueChanges.subscribe(v => { + this.registrationModel = { username: '', password: v.password }; + }); + } - updateStatus(resetInProgress: boolean, - resetSuccess: boolean, - resetPerformed: boolean) { - this.resetInProgress = resetInProgress; - this.resetSuccess = resetSuccess; - this.resetPerformed = resetPerformed; - } + navigateToLoginPage() { + this.router.navigate(['/login']); + } + setNewPassword() { + this.updateStatus(true, false, false); + this.restorePasswordService + .restorePassword(this.recoveryCode, this.registrationModel) + .subscribe( + result => { + this.updateStatus(false, true, true); + }, + error => { + this.updateStatus(false, false, true); + }, + ); + } + updateStatus( + resetInProgress: boolean, + resetSuccess: boolean, + resetPerformed: boolean, + ) { + this.resetInProgress = resetInProgress; + this.resetSuccess = resetSuccess; + this.resetPerformed = resetPerformed; + } } diff --git a/ui/src/app/login/components/setup/setup.component.html b/ui/src/app/login/components/setup/setup.component.html index c72adf1d09..c9b51af4b2 100644 --- a/ui/src/app/login/components/setup/setup.component.html +++ b/ui/src/app/login/components/setup/setup.component.html @@ -16,72 +16,148 @@ ~ --> -
+