Skip to content

Commit

Permalink
Merge pull request #80 from speedyman08/trim-whitespace-register-form
Browse files Browse the repository at this point in the history
Trim whitespaces in register form inputs
  • Loading branch information
jvyden authored May 23, 2024
2 parents 102e761 + 7ab7a80 commit 9bcf5b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/app/helpers/FormHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class FormHandler {
cleanUpFormInputs(...formInputs: string[]): string[] {
return formInputs.map((formInput) => {
return formInput.trim()
})
}
}
13 changes: 9 additions & 4 deletions src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ import {sha512Async} from 'src/app/hash';
import {PasswordVerificationService} from "../../services/password-verification.service";
import {faEnvelope, faKey, faSignIn, faUserPlus} from "@fortawesome/free-solid-svg-icons";
import {AuthService} from "../../api/auth.service";
import {FormHandler} from "../../helpers/FormHandler";

@Component({
selector: 'app-login',
templateUrl: './login.component.html'
})
export class LoginComponent {
export class LoginComponent extends FormHandler {
email: string = "";
password: string = "";

constructor(private authService: AuthService, private passwordVerifier: PasswordVerificationService) {
super();
}

login() {
if (!this.passwordVerifier.verifyPassword(this.email, this.password)) {
const formInputs = this.cleanUpFormInputs(this.email, this.password);
const [email, password] = formInputs;

if (!this.passwordVerifier.verifyPassword(email, password)) {
return;
}

sha512Async(this.password).then((hash) => {
this.authService.LogIn(this.email, hash)
sha512Async(password).then((hash) => {
this.authService.LogIn(email, hash)
});
}

Expand Down
14 changes: 9 additions & 5 deletions src/app/pages/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,34 @@ import {
faUserPlus
} from "@fortawesome/free-solid-svg-icons";
import {AuthService} from "../../api/auth.service";
import {FormHandler} from "../../helpers/FormHandler";

@Component({
selector: 'app-register',
templateUrl: './register.component.html'
})
export class RegisterComponent {
export class RegisterComponent extends FormHandler {
username: string = "";
email: string = "";
password: string = "";
confirmPassword: string = "";

constructor(private authService: AuthService, private passwordVerifier: PasswordVerificationService) {
super();
}

register() {
if (!this.passwordVerifier.verifyPassword(this.username, this.password, this.username, this.confirmPassword)) {
const formInputs = this.cleanUpFormInputs(this.username, this.email, this.password, this.confirmPassword);
const [username, email, password, confirmPassword] = formInputs;

if (!this.passwordVerifier.verifyPassword(username, password, username, confirmPassword)) {
return;
}

sha512Async(this.password).then((hash) => {
this.authService.Register(this.username, this.email, hash)
sha512Async(password).then((hash) => {
this.authService.Register(username, email, hash)
});
}

protected readonly faEnvelope = faEnvelope;
protected readonly faTriangleExclamation = faTriangleExclamation;
protected readonly faSignIn = faSignIn;
Expand Down

0 comments on commit 9bcf5b1

Please sign in to comment.