Skip to content

Commit

Permalink
feat update code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Jan 14, 2024
1 parent 084861a commit ce466ce
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 83 deletions.
17 changes: 9 additions & 8 deletions src/app/pages/auth/login/login.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class LoginPage implements OnInit {
}

ngOnInit() {
this.menuCtrl.enable(true, "menu");
this.menuCtrl.enable(false, "menu");
this.user = {
email: "",
password: "",
Expand All @@ -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);

Expand All @@ -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: [
{
Expand Down
104 changes: 60 additions & 44 deletions src/app/pages/auth/reset-password/reset-password.page.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<void> {
if (!authForm.get('email').valid) {
async submitCredentials(authForm: UntypedFormGroup): Promise<void> {
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();
}
);
Expand Down
44 changes: 25 additions & 19 deletions src/app/pages/auth/signup/signup.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -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();
Expand All @@ -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")),
Expand All @@ -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: [
{
Expand All @@ -157,8 +165,6 @@ export class SignupPage implements OnInit {
}*/

async signupUser(credentials: UserCredentialLogin, userData: any) {


return this.authService.signup(
credentials.email,
credentials.password,
Expand Down
15 changes: 3 additions & 12 deletions src/app/pages/club/club.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
</ion-header>

<ion-list [inset]="true">

<ion-item>
<ion-thumbnail slot="start">
<img alt="{{club.name}}" src="{{club.logo}}" />
Expand Down Expand Up @@ -75,11 +74,8 @@
<ion-label> Administratoren </ion-label>
<ion-badge>3</ion-badge>
</ion-item>


</ion-list>


<ion-list lines="full" [inset]="true">
<ion-list-header>
<ion-label> {{ "common.others" | translate}} </ion-label>
Expand All @@ -88,26 +84,21 @@
<ion-item detail="true" (click)="openAdminList()">
<ion-icon name="help-buoy-outline" slot="start"></ion-icon>
<ion-label> Helferpunkte </ion-label>
<ion-badge>3</ion-badge>
</ion-item>
</ion-list>


<ion-list lines="full" [inset]="true">
<ion-list-header>
<ion-label> {{ "common.settings" | translate}} </ion-label>
</ion-list-header>
<ion-item >

<ion-item>
<ion-icon name="hammer-outline" slot="start"></ion-icon>
<ion-label> API KEY </ion-label>

</ion-item>
</ion-list>



<!--
<!--
<ion-list [inset]="true" *ngIf="club['clubRequests'].length > 0">
<ion-list-header>
Expand Down

0 comments on commit ce466ce

Please sign in to comment.