src/providers/auth-service.ts
Properties |
|
Methods |
constructor(config: Config, storage: Storage, userService: UserService)
|
||||||||||||||||
|
Defined in src/providers/auth-service.ts:28
|
||||||||||||||||
|
Parameters :
|
| delete |
delete()
|
|
Defined in src/providers/auth-service.ts:90
|
|
Returns :
void
|
| doLoginFirebase |
doLoginFirebase(email: string, password: string)
|
|
Defined in src/providers/auth-service.ts:69
|
|
Returns :
any
|
| getUser |
getUser()
|
|
Defined in src/providers/auth-service.ts:58
|
|
Returns :
firebase.User
|
| logoutUser |
logoutUser()
|
|
Defined in src/providers/auth-service.ts:106
|
|
Returns :
any
|
| register | ||||||||||||||||||||
register(email: string, password: string, firstname: string, lastname: string)
|
||||||||||||||||||||
|
Defined in src/providers/auth-service.ts:85
|
||||||||||||||||||||
|
Parameters :
Returns :
any
|
| resetPassword | ||||||||
resetPassword(email: string)
|
||||||||
|
Defined in src/providers/auth-service.ts:102
|
||||||||
|
Parameters :
Returns :
any
|
| Public fireAuth |
fireAuth:
|
Type : firebase.auth.Auth
|
|
Defined in src/providers/auth-service.ts:26
|
| tenant |
tenant:
|
Type : string
|
|
Defined in src/providers/auth-service.ts:24
|
| Public token |
token:
|
Type : any
|
|
Defined in src/providers/auth-service.ts:25
|
| Public urlNodeFirebase |
urlNodeFirebase:
|
Type : string
|
|
Defined in src/providers/auth-service.ts:28
|
| Public userProfile |
userProfile:
|
Type : firebase.database.Reference
|
|
Defined in src/providers/auth-service.ts:27
|
import { Injectable } from '@angular/core';
import { Config } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import 'rxjs/add/operator/map';
import * as firebase from 'firebase/app';
// singlenton
import { UserService } from '../providers/user/user';
/*
Generated class for the AuthService provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
/**
* DESC PROVIDER
*/
export class AuthService {
tenant: string;
public token: any;
public fireAuth: firebase.auth.Auth;
public userProfile: firebase.database.Reference;
public urlNodeFirebase: string;
constructor(
//private afAuth: AngularFireAuth,
private config: Config,
private storage: Storage,
private userService:UserService
) {
console.log('Hello AuthService Provider');
// recupero tenant
// console.log('ionViewDidLoad First');
// this.userProvider.log(); // log First singleton data
// this.userProvider.set("First singleton data")
let appConfig = config.get("appConfig");
this.tenant = appConfig.tenant;
this.fireAuth = firebase.auth();
this.urlNodeFirebase = '/apps/'+this.tenant+'/contacts/';
this.userProfile = firebase.database().ref(this.urlNodeFirebase);
//this.afAuth.authState.subscribe();
// this.afAuth.authState.subscribe((user: firebase.User) => {
// this.currentUser = user;
// });
}
//Start Firebase Auth//
// GetUser
getUser(): firebase.User {
return this.fireAuth.currentUser;
}
// Create User Anonymous
// createAnonymousUser(): firebase.Promise<any> {
// return this.fireAuth.signInAnonymously();
// }
// Login with Email
doLoginFirebase(email: string, password: string): any {
return this.fireAuth.signInWithEmailAndPassword(email, password)
// .then(res => {
// console.log("signInWithEmailAndPassword::: ",res);
// });
}
// Signin with Facebook
// signInWithFacebook(): any {
// return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider())
// .then(res => console.log(res));
// }
// Register User with Email
register(email: string, password: string, firstname: string, lastname: string): any {
return this.fireAuth.createUserWithEmailAndPassword(email, password);
}
// delete account
delete(){
var user = firebase.auth().currentUser;
user.delete().then(function() {
// User deleted.
console.log("delete OK ");
}).catch(function(error) {
// An error happened.
console.log("delete with error: ",error);
});
}
// Reset Password
resetPassword(email: string): any {
return this.fireAuth.sendPasswordResetEmail(email);
}
logoutUser() {
return firebase.auth().signOut()
//return this.afAuth.auth.signOut();
// .then((res) => {
// console.log("logout1",res);
// console.log("logout2", this.getUser());
// })
// .catch(function(error) {
// console.log("logout failed: " + error.message)
// });
}
//End Firebase Auth//
}