119 lines
3.2 KiB
TypeScript
119 lines
3.2 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import {AppConst} from '../../constants/app-const';
|
|
import {Router} from "@angular/router";
|
|
import {LoginService} from "../../services/login.service";
|
|
import {UserService} from "../../services/user.service";
|
|
import {User} from '../../models/user';
|
|
import {UserPayment} from '../../models/user-payment';
|
|
import {UserBilling} from '../../models/user-billing';
|
|
|
|
@Component({
|
|
selector: 'app-my-profile',
|
|
templateUrl: './my-profile.component.html',
|
|
styleUrls: ['./my-profile.component.css']
|
|
})
|
|
export class MyProfileComponent implements OnInit {
|
|
|
|
private serverPath = AppConst.serverPath;
|
|
private loginError:boolean = false;
|
|
private loggedIn = false;
|
|
private credential = {'username':'', 'password':''};
|
|
|
|
private emailSent:boolean = false;
|
|
private usernameExists:boolean = false;
|
|
private emailExists:boolean = false;
|
|
private username:string;
|
|
private email:string;
|
|
|
|
private emailNotExists: boolean = false;
|
|
private forgetPasswordEmailSent: boolean = false;
|
|
private recoverEmail:string;
|
|
|
|
private user: User = new User();
|
|
private userPayment: UserPayment = new UserPayment();
|
|
private userBilling: UserBilling = new UserBilling();
|
|
private userPaymentList: UserPayment[] = [];
|
|
private stateList: string[] = [];
|
|
|
|
constructor (private loginService: LoginService, private userService: UserService, private router: Router){
|
|
}
|
|
|
|
onLogin() {
|
|
this.loginService.sendCredential(this.credential.username, this.credential.password).subscribe(
|
|
res=>{
|
|
console.log(res);
|
|
localStorage.setItem("xAuthToken", res.json().token);
|
|
this.loggedIn=true;
|
|
location.reload();
|
|
this.router.navigate(['/home']);
|
|
},
|
|
error=>{
|
|
this.loggedIn=false;
|
|
}
|
|
);
|
|
}
|
|
|
|
onNewAccount() {
|
|
this.usernameExists=false;
|
|
this.emailExists=false;
|
|
this.emailSent = false;
|
|
|
|
this.userService.newUser(this.username, this.email).subscribe(
|
|
res => {
|
|
console.log(res);
|
|
this.emailSent = true;
|
|
},
|
|
error => {
|
|
console.log(error.text());
|
|
let errorMessage=error.text();
|
|
if (errorMessage==="usernameExists") this.usernameExists=true;
|
|
if (errorMessage==="emailExists") this.emailExists=true;
|
|
}
|
|
);
|
|
}
|
|
|
|
onForgetPassword() {
|
|
this.forgetPasswordEmailSent = false;
|
|
this.emailNotExists = false;
|
|
|
|
this.userService.retrievePassword(this.recoverEmail).subscribe(
|
|
res => {
|
|
console.log(res);
|
|
this.emailSent = true;
|
|
},
|
|
error => {
|
|
console.log(error.text());
|
|
let errorMessage=error.text();
|
|
if (errorMessage==="usernameExists") this.usernameExists=true;
|
|
if (errorMessage==="emailExists") this.emailExists=true;
|
|
}
|
|
);
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.loginService.checkSession().subscribe(
|
|
res => {
|
|
this.loggedIn=true;
|
|
},
|
|
error => {
|
|
this.loggedIn=false;
|
|
}
|
|
);
|
|
|
|
this.userService.getCurrentUser().subscribe(
|
|
res => {
|
|
console.log(res.json());
|
|
this.user=res.json();
|
|
this.userPaymentList = this.user.userPaymentList;
|
|
},
|
|
error => {
|
|
console.log(error);
|
|
}
|
|
);
|
|
|
|
for (let s in AppConst.usStates) {
|
|
this.stateList.push(s);
|
|
}
|
|
}
|
|
}
|