This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doRegister(value){ | |
return new Promise<any>((resolve, reject) => { | |
firebase.auth().createUserWithEmailAndPassword(value.email, value.password) | |
.then(res => { | |
resolve(res); | |
}, err => reject(err)) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tryRegister(value){ | |
this.authService.doRegister(value) | |
.then(res => { | |
console.log(res); | |
this.errorMessage = ""; | |
this.successMessage = "Your account has been created"; | |
}, err => { | |
console.log(err); | |
this.errorMessage = err.message; | |
this.successMessage = ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form [formGroup]="registerForm"> | |
<div class="form-group"> | |
<label>Email address</label> | |
<input type="email" formControlName="email" class="form-control" required> | |
</div> | |
<div class="form-group"> | |
<label>Password</label> | |
<input type="password" class="form-control" formControlName="password" required> | |
<label class="error">{{errorMessage}}</label> | |
<label class="success">{{successMessage}}</label> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doGoogleLogin(){ | |
return new Promise<any>((resolve, reject) => { | |
let provider = new firebase.auth.GoogleAuthProvider(); | |
provider.addScope('profile'); | |
provider.addScope('email'); | |
this.afAuth.auth | |
.signInWithPopup(provider) | |
.then(res => { | |
resolve(res); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doFacebookLogin(){ | |
return new Promise<any>((resolve, reject) => { | |
let provider = new firebase.auth.FacebookAuthProvider(); | |
this.afAuth.auth | |
.signInWithPopup(provider) | |
.then(res => { | |
resolve(res); | |
}, err => { | |
console.log(err); | |
reject(err); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const rootRouterConfig: Routes = [ | |
{ path: '', redirectTo: 'login', pathMatch: 'full' }, | |
{ path: 'login', component: LoginComponent, canActivate: [AuthGuard] }, | |
{ path: 'register', component: RegisterComponent, canActivate: [AuthGuard] }, | |
{ path: 'user', component: UserComponent, resolve: { data: UserResolver}} | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// other imports | |
import { AngularFireModule } from 'angularfire2'; | |
import { AngularFirestoreModule } from 'angularfire2/firestore'; | |
import { AngularFireAuthModule } from 'angularfire2/auth'; | |
import { environment } from '../environments/environment'; | |
@NgModule({ | |
declarations: [ | |
// your declarations | |
], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const environment = { | |
firebase: { | |
apiKey: "YOUR_API_KEY", | |
authDomain: "YOUR_AUTH_DOMAIN", | |
databaseURL: "YOUR_DATABASE_URL", | |
projectId: "YOUR_PROJECT_ID", | |
storageBucket: "YOUR_STORAGE_BUCKET", | |
messagingSenderId: "YOUR_SENDER_ID" | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { UsernameValidator } from '../../validators/username.validator'; | |
this.validations_form = this.formBuilder.group({ | |
username: new FormControl('', Validators.compose([ | |
UsernameValidator.validUsername, | |
Validators.maxLength(25), | |
Validators.minLength(5), | |
Validators.pattern('^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]+$'), | |
Validators.required | |
])), | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormControl } from '@angular/forms'; | |
export class UsernameValidator { | |
static validUsername(fc: FormControl){ | |
if(fc.value.toLowerCase() === "abc123" || fc.value.toLowerCase() === "123abc"){ | |
return ({validUsername: true}); | |
} else { | |
return (null); | |
} | |
} | |
} |