am new to this angular, but somehow i played around a months in angular. I have developed a web app containing login, signup form. I can signup and signin easily. Am using firebase to store data and for authentication.
If a new user uses my page they should signup first then to login, this is a usual process.
Now am facing a situation, 600 employees they already have emailid and password but not registered with my app. Those 600 employees have to directly to login without signup in my app . How to do this.?
Is there any way to implement to import those 600 users name and password to firebase or any idea to implement this.?
login-page.component.html
<div class="col-md-12">
<form [formGroup]="signin" (ngSubmit)=signInNewtt()>
<div class="form-group">
<label class="center-block">Email:
<input class="form-control" formControlName="email" >
</label>
</div>
<div class="form-group">
<label class="center-block">Password:
<input type="password" class="form-control" formControlName="password" >
</label>
</div>
<button type="submit" class="btn" [disabled]="!signin.valid">submit</button>
</form>
{{signin.value | json}}
{{signin.status | json}}
</div>
login-page.component.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, AbstractControl } from '@angular/forms';
import * as firebase from 'firebase';
import * as admin from "firebase-admin";
@Component({
selector: 'app-login-page',
templateUrl: './login-page.component.html',
styleUrls: ['./login-page.component.css']
})
export class LoginPageComponent implements OnInit {
signin:FormGroup;
constructor(private fb: FormBuilder) {
this.signin = fb.group({
email : [null, Validators.compose([Validators.required, this.nospaceValidator])],
password : [null, Validators.required]
});
}
ngOnInit() {
}
signUp(){
let values = this.signin.value;
console.log(values.name,values.email)
firebase.auth().createUserWithEmailAndPassword(values.name,values.email)
.then(
function(user){
if(user && user.emailVerified === false){
user.sendEmailVerification()
.then(function(){
console.log("email verification sent to user");
});
}
}
)
.catch(
function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorMessage)
});
}
signIn(){
firebase.auth().onAuthStateChanged(
function(user) {
if (user.emailVerified) {
console.log('Email is verified');
}
else {
console.log('Email is not verified');
}
});
}
signInNewtt(){
let values = this.signin.value;
//Problem here
admin.auth().createUser({
email: values.email,
password: values.password
})
.then(function(userRecord) {
See the UserRecord reference doc for the contents of userRecord.
console.log("Successfully created new user:", userRecord.uid);
})
.catch(function(error) {
console.log("Error creating new user:", error);
});
}
nospaceValidator(control: AbstractControl): { [s: string]: boolean } {
let re = / /;
if (control.value && control.value.match(re)) {
return { nospace: true };
}
}
}