Skip to content

Commit

Permalink
Fix login and registration errrors
Browse files Browse the repository at this point in the history
  • Loading branch information
runette committed Sep 20, 2024
1 parent ba7c19e commit feda4b9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
17 changes: 16 additions & 1 deletion bcp/src/app/bcp-login/bcp-login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
</mat-card-header>
<mat-card-content>
<p>
@if (error) {Login Failed!}
@if (error) {
{{errorText}}
}
</p>
<p>
<mat-form-field>
Expand Down Expand Up @@ -78,6 +80,19 @@
<span style="display: none;">Sign in with Email</span>
</div>
</button>
<button class="gsi-material-button" (click)="resetLogin()">
<div class="gsi-material-button-state">
</div>
<div class="gsi-material-button-content-wrapper">
<div class="gsi-material-button-icon">
<i class="material-icons" >
restart_alt
</i>
</div>
<span class="gsi-material-button-contents">Password Reset</span>
<span style="display: none;">Password Reset</span>
</div>
</button>
</mat-card-actions>
</mat-card>
} @else {
Expand Down
57 changes: 51 additions & 6 deletions bcp/src/app/bcp-login/bcp-login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { Auth,
signInWithEmailAndPassword,
createUserWithEmailAndPassword,
sendEmailVerification,
sendPasswordResetEmail
sendPasswordResetEmail,
ActionCodeSettings
} from '@angular/fire/auth';
import { Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
Expand All @@ -26,6 +27,7 @@ export class BcpLoginComponent implements OnInit, OnDestroy {
email: string | undefined;
password: string | undefined;
error: boolean = false;
errorText: string = "Login Failed!"
hide: boolean = true;

loggedOut: boolean = true;
Expand Down Expand Up @@ -71,28 +73,71 @@ export class BcpLoginComponent implements OnInit, OnDestroy {
}

async loginEmail() {
if ( this.email == undefined || this.password == undefined) return;
if ( this.email == "" || this.password == "") {
this.errorText = "You must provide email and password";
this.error = true
return;
}
try {
this.error = false;
await signInWithEmailAndPassword(this.auth, this.email, this.password);
if (! this.auth.currentUser.emailVerified){
await signOut(this.auth);
this.errorText = "Verification email sent - check your Inbox";
this.error = true;
}
} catch (e) {
this.errorText = e.message;
this.error = true;
}
}


async resetLogin() {
if ( this.email == "" ) {
this.errorText = "You must give the email address";
this.error = true;
return;
}
try {
this.error = false;
await sendPasswordResetEmail(this.auth, this.email, {
url: "https://www.bigcannonproject.org/login"
} );
this.errorText = "Email sent - check your Inbox";
this.error = true;
} catch (e) {
this.errorText = e.message;
this.error = true;
}
}

async logout() {
await signOut(this.auth);
}

async register() {
if ( this.email == undefined ||
this.password == undefined ||
this.auth == undefined) return;
if ( this.email == "" ||
this.password == "" ||
this.auth == undefined) {
this.errorText = "You must provide email and password";
this.error = true;
return;
}
try {
this.error = false;
await createUserWithEmailAndPassword(this.auth, this.email, this.password);
if ( this.auth.currentUser ) await sendEmailVerification(this.auth.currentUser)
if ( this.auth.currentUser )
{
await sendEmailVerification(this.auth.currentUser);
if (! this.auth.currentUser.emailVerified){
await signOut(this.auth);
this.errorText = "Verification email sent - check your Inbox";
this.error = true;
}
}
} catch (e) {
this.errorText = e.message;
this.error = true
}
}
Expand Down

0 comments on commit feda4b9

Please sign in to comment.