diff --git a/src/app/components/login/register/register.component.html b/src/app/components/login/register/register.component.html index d6dbea7..c0a0679 100644 --- a/src/app/components/login/register/register.component.html +++ b/src/app/components/login/register/register.component.html @@ -83,14 +83,16 @@
@if (!password.valid && password.touched) {

You must enter a password.

- } + } @else { @if (registerData.password.length < 6 && password.touched) { +

The password must consist of at least 6 characters

+ } }
@if (!passwordConfirm.valid && passwordConfirm.touched) {

You must enter a password.

+ } @if (registerData.password !== registerData.passwordConfirm && + registerData.password !== "" && registerData.passwordConfirm !== "") { +

The passwords don't match!

} @@ -121,6 +126,8 @@ password.invalid || !registerData.password || sharedService.isBtnDisabled || + registerData.password.length < 6 || + registerData.password !== registerData.passwordConfirm || !checkIfUserEmailIsValid(registerData.mail) " > diff --git a/src/app/components/login/register/register.component.ts b/src/app/components/login/register/register.component.ts index 9f6b57a..2146fc5 100644 --- a/src/app/components/login/register/register.component.ts +++ b/src/app/components/login/register/register.component.ts @@ -28,6 +28,8 @@ export class RegisterComponent { name: '', mail: '', password: '', + color: '', + initials: '', passwordConfirm: '', }; @@ -41,6 +43,7 @@ export class RegisterComponent { this.sharedService.isBtnDisabled = true; if (ngForm.submitted && ngForm.form.valid) { //this.loginSerivce.register(this.registerData); + console.log(this.registerData); } } diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts index 87ac3ff..46acc99 100644 --- a/src/app/services/login.service.ts +++ b/src/app/services/login.service.ts @@ -4,6 +4,7 @@ import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, + Auth, } from 'firebase/auth'; import { FirebaseService } from './firebase.service'; import { @@ -48,6 +49,39 @@ export class LoginService { }); } + register(registerData: { + name: string; + mail: string; + password: string; + initials: string; + color: string; + }) { + signInWithEmailAndPassword( + getAuth(), + registerData.mail, + registerData.password + ) + .then((userCredential) => { + const user = userCredential.user; + + const userDataToSave: User = { + uId: user.uid, + email: user.email || '', + firstName: registerData.name || '', + lastName: registerData.name || '', + status: true, + phone: '', + initials: registerData.initials, + color: registerData.color, + lastLogin: new Date().getTime(), + }; + this.createUserInFirestore(userDataToSave); + }) + .catch((error) => { + console.error(error); + }); + } + googleLogin() { const auth = getAuth(); const provider = new GoogleAuthProvider(); @@ -129,3 +163,6 @@ export class LoginService { localStorage.setItem('currentUserJOIN', JSON.stringify(userId)); } } +function createUserWithEmailAndPassword(auth: Auth, email: any, password: any) { + throw new Error('Function not implemented.'); +}