From ce466cea5eb4d948ea36d3c0c06ed146ca78ecec Mon Sep 17 00:00:00 2001 From: Sandro Scalco Date: Sun, 14 Jan 2024 17:34:02 +0100 Subject: [PATCH] feat update code a bit --- src/app/pages/auth/login/login.page.ts | 17 +-- .../reset-password/reset-password.page.ts | 104 ++++++++++-------- src/app/pages/auth/signup/signup.page.ts | 44 ++++---- src/app/pages/club/club.page.html | 15 +-- 4 files changed, 97 insertions(+), 83 deletions(-) diff --git a/src/app/pages/auth/login/login.page.ts b/src/app/pages/auth/login/login.page.ts index 137edada..be2011fe 100644 --- a/src/app/pages/auth/login/login.page.ts +++ b/src/app/pages/auth/login/login.page.ts @@ -39,7 +39,7 @@ export class LoginPage implements OnInit { } ngOnInit() { - this.menuCtrl.enable(true, "menu"); + this.menuCtrl.enable(false, "menu"); this.user = { email: "", password: "", @@ -58,9 +58,13 @@ export class LoginPage implements OnInit { this.router.navigateByUrl(""); }); } catch (err) { - let message = (await lastValueFrom( - this.translate.get("common.general__error_occurred") - )) + " " + err.code + " / " + + let message = + (await lastValueFrom( + this.translate.get("common.general__error_occurred") + )) + + " " + + err.code + + " / " + err.message; console.error(err.code); @@ -80,15 +84,12 @@ export class LoginPage implements OnInit { message = await lastValueFrom( this.translate.get("login.error__invalid-login-credentials") ); - } else { console.log("Error"); } const alert = await this.alertCtrl.create({ - header: await lastValueFrom( - this.translate.get("login.mistake") - ), + header: await lastValueFrom(this.translate.get("login.mistake")), message: message, buttons: [ { diff --git a/src/app/pages/auth/reset-password/reset-password.page.ts b/src/app/pages/auth/reset-password/reset-password.page.ts index 933f3186..a705c033 100644 --- a/src/app/pages/auth/reset-password/reset-password.page.ts +++ b/src/app/pages/auth/reset-password/reset-password.page.ts @@ -1,29 +1,29 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit } from "@angular/core"; import { UntypedFormBuilder, UntypedFormGroup, - Validators -} from '@angular/forms'; -import { Router } from '@angular/router'; + Validators, +} from "@angular/forms"; +import { Router } from "@angular/router"; import { AlertController, LoadingController, - MenuController -} from '@ionic/angular'; -import { TranslateService } from '@ngx-translate/core'; -import { lastValueFrom } from 'rxjs'; -import { UserCredentialLogin } from 'src/app/models/user'; -import { AuthService } from 'src/app/services/auth.service'; + MenuController, +} from "@ionic/angular"; +import { TranslateService } from "@ngx-translate/core"; +import { lastValueFrom } from "rxjs"; +import { UserCredentialLogin } from "src/app/models/user"; +import { AuthService } from "src/app/services/auth.service"; @Component({ - selector: 'app-reset-password', - templateUrl: './reset-password.page.html', - styleUrls: ['./reset-password.page.scss'], + selector: "app-reset-password", + templateUrl: "./reset-password.page.html", + styleUrls: ["./reset-password.page.scss"], }) export class ResetPasswordPage implements OnInit { public user: UserCredentialLogin; public authForm: UntypedFormGroup; - constructor ( + constructor( public menuCtrl: MenuController, private readonly authService: AuthService, private readonly alertCtrl: AlertController, @@ -32,77 +32,93 @@ export class ResetPasswordPage implements OnInit { private readonly loadingCtrl: LoadingController, private translate: TranslateService ) { - this.menuCtrl.enable(false, 'menu'); + this.menuCtrl.enable(false, "menu"); this.authForm = this.formBuilder.group({ - email: ['', Validators.compose([Validators.required, Validators.email])], - password: [''], + email: ["", Validators.compose([Validators.required, Validators.email])], + password: [""], }); } - ngOnInit () { - this.menuCtrl.enable(false, 'menu'); + ngOnInit() { + this.menuCtrl.enable(false, "menu"); this.user = { - email: '', - password: '', + email: "", + password: "", }; } - async submitCredentials (authForm: UntypedFormGroup): Promise { - if (!authForm.get('email').valid) { + async submitCredentials(authForm: UntypedFormGroup): Promise { + if (!authForm.get("email").valid) { // console.log('Form is not valid yet, current value:', authForm.value); this.alertCtrl .create({ - message: await lastValueFrom(this.translate.get("common.error__invalid_form")), - buttons: [{ text: await lastValueFrom(this.translate.get("common.ok")), role: 'cancel' }] + message: await lastValueFrom( + this.translate.get("common.error__invalid_form") + ), + buttons: [ + { + text: await lastValueFrom(this.translate.get("common.ok")), + role: "cancel", + }, + ], }) .then((alert) => { alert.present(); - }) + }); } else { this.presentLoading(); const credentials: UserCredentialLogin = { email: authForm.value.email, - password: authForm.value.password - } + password: authForm.value.password, + }; this.resetPassword(credentials); } } - async presentLoading () { + async presentLoading() { const loading = await this.loadingCtrl.create({ - cssClass: 'my-custom-class', - message: await lastValueFrom(this.translate.get("common.please__wait"))+'...', - duration: 2000 - }) + cssClass: "my-custom-class", + message: + (await lastValueFrom(this.translate.get("common.please__wait"))) + + "...", + duration: 2000, + }); await loading.present(); const { role, data } = await loading.onDidDismiss(); - console.log('Loading dismissed!'); + console.log("Loading dismissed!"); } - resetPassword (credentials: UserCredentialLogin): void { + resetPassword(credentials: UserCredentialLogin): void { this.authService.resetPassword(credentials.email).then( async () => { const alert = await this.alertCtrl.create({ - message: await lastValueFrom(this.translate.get("reset-password.check__email_for_reset_link")), + message: await lastValueFrom( + this.translate.get("reset-password.check__email_for_reset_link") + ), buttons: [ { text: await lastValueFrom(this.translate.get("common.ok")), - role: 'cancel', + role: "cancel", handler: () => { - this.router.navigateByUrl('login'); - } - } - ] - }) + this.router.navigateByUrl("login"); + }, + }, + ], + }); await alert.present(); }, async (error) => { const errorAlert = await this.alertCtrl.create({ message: error.message, - buttons: [{ text: await lastValueFrom(this.translate.get("common.ok")), role: 'cancel' }] - }) + buttons: [ + { + text: await lastValueFrom(this.translate.get("common.ok")), + role: "cancel", + }, + ], + }); await errorAlert.present(); } ); diff --git a/src/app/pages/auth/signup/signup.page.ts b/src/app/pages/auth/signup/signup.page.ts index 42dd21fc..6ba464b1 100644 --- a/src/app/pages/auth/signup/signup.page.ts +++ b/src/app/pages/auth/signup/signup.page.ts @@ -44,12 +44,11 @@ export class SignupPage implements OnInit { } ngOnInit() { + this.menuCtrl.enable(false, "menu"); this.user = { email: "", password: "", }; - - this.menuCtrl.enable(false, "menu"); } async submitCredentials(authForm: UntypedFormGroup): Promise { @@ -73,7 +72,8 @@ export class SignupPage implements OnInit { const loading = await this.loadingCtrl.create({ cssClass: "my-custom-class", message: - (await lastValueFrom(this.translate.get("common.please__wait"))) + "...", + (await lastValueFrom(this.translate.get("common.please__wait"))) + + "...", // duration: 10000, }); await loading.present(); @@ -84,22 +84,26 @@ export class SignupPage implements OnInit { }; try { - const signupUserResponse: UserCredential = await this.signupUser(credentials, { - firstName: authForm.value.firstName, - lastName: authForm.value.lastName, - }); + const signupUserResponse: UserCredential = await this.signupUser( + credentials, + { + firstName: authForm.value.firstName, + lastName: authForm.value.lastName, + } + ); - if (signupUserResponse.operationType !== "signIn"){ + if (signupUserResponse.operationType !== "signIn") { console.log(signupUserResponse.operationType); } - + /*await this.authService.logout(); await this.router.navigateByUrl("login");*/ - + const alert = await this.alertCtrl.create({ - header: await lastValueFrom(this.translate.get("signup.account__created")), - message: - "signup.account__created_description", + header: await lastValueFrom( + this.translate.get("signup.account__created") + ), + message: "signup.account__created_description", buttons: [ { text: await lastValueFrom(this.translate.get("common.ok")), @@ -114,23 +118,27 @@ export class SignupPage implements OnInit { } this.authService.login(credentials.email, credentials.password); // await this.router.navigateByUrl(""); // --> this should trigger appcomponent? - } catch (err) { let message = - await lastValueFrom(this.translate.get("common.general__error_occurred")) + ": " + + (await lastValueFrom( + this.translate.get("common.general__error_occurred") + )) + + ": " + err.code + " / " + err.message; console.error(err.code); if (err.code == "auth/email-already-in-use") { - message = await lastValueFrom(this.translate.get("signup.email__already_in_use")); + message = await lastValueFrom( + this.translate.get("signup.email__already_in_use") + ); } else { console.log("Error"); } await loading.dismiss(); const alert = await this.alertCtrl.create({ - header: (await lastValueFrom(this.translate.get("common.mistake"))), + header: await lastValueFrom(this.translate.get("common.mistake")), message: message, buttons: [ { @@ -157,8 +165,6 @@ export class SignupPage implements OnInit { }*/ async signupUser(credentials: UserCredentialLogin, userData: any) { - - return this.authService.signup( credentials.email, credentials.password, diff --git a/src/app/pages/club/club.page.html b/src/app/pages/club/club.page.html index b65274b1..01c458ff 100644 --- a/src/app/pages/club/club.page.html +++ b/src/app/pages/club/club.page.html @@ -26,7 +26,6 @@ - {{club.name}} @@ -75,11 +74,8 @@ Administratoren 3 - - - {{ "common.others" | translate}} @@ -88,26 +84,21 @@ Helferpunkte - 3 - {{ "common.settings" | translate}} - - + + API KEY - - - -