-
-
-
An email has been sent to email address you just registered. Please validate your email address and update your password info.
-
-
-
Incorrect username or password.
-
diff --git a/store-front/src/app/components/my-account/my-account.component.ts b/store-front/src/app/components/my-account/my-account.component.ts
index 7a75aac..25ca601 100644
--- a/store-front/src/app/components/my-account/my-account.component.ts
+++ b/store-front/src/app/components/my-account/my-account.component.ts
@@ -2,6 +2,7 @@ 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";
@Component({
selector: 'app-my-account',
@@ -15,10 +16,20 @@ export class MyAccountComponent implements OnInit {
private loggedIn = false;
private credential = {'username':'', 'password':''};
- constructor (private loginService: LoginService, private router: Router){
+ 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;
+
+ constructor (private loginService: LoginService, private userService: UserService, private router: Router){
}
- onSubmit() {
+ onLogin() {
this.loginService.sendCredential(this.credential.username, this.credential.password).subscribe(
res=>{
console.log(res);
@@ -33,6 +44,43 @@ export class MyAccountComponent implements OnInit {
);
}
+ 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 => {
diff --git a/store-front/src/app/components/my-profile/my-profile.component.css b/store-front/src/app/components/my-profile/my-profile.component.css
new file mode 100644
index 0000000..e69de29
diff --git a/store-front/src/app/components/my-profile/my-profile.component.html b/store-front/src/app/components/my-profile/my-profile.component.html
new file mode 100644
index 0000000..7782815
--- /dev/null
+++ b/store-front/src/app/components/my-profile/my-profile.component.html
@@ -0,0 +1,3 @@
+
+ my-profile works!
+
diff --git a/store-front/src/app/components/my-profile/my-profile.component.spec.ts b/store-front/src/app/components/my-profile/my-profile.component.spec.ts
new file mode 100644
index 0000000..6c60227
--- /dev/null
+++ b/store-front/src/app/components/my-profile/my-profile.component.spec.ts
@@ -0,0 +1,28 @@
+/* tslint:disable:no-unused-variable */
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { DebugElement } from '@angular/core';
+
+import { MyProfileComponent } from './my-profile.component';
+
+describe('MyProfileComponent', () => {
+ let component: MyProfileComponent;
+ let fixture: ComponentFixture
;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ MyProfileComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(MyProfileComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/store-front/src/app/components/my-profile/my-profile.component.ts b/store-front/src/app/components/my-profile/my-profile.component.ts
new file mode 100644
index 0000000..b7e8b06
--- /dev/null
+++ b/store-front/src/app/components/my-profile/my-profile.component.ts
@@ -0,0 +1,94 @@
+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";
+
+@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;
+
+ 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;
+ }
+ );
+
+}
diff --git a/store-front/src/app/components/nav-bar/nav-bar.component.html b/store-front/src/app/components/nav-bar/nav-bar.component.html
index 55d86eb..1020847 100644
--- a/store-front/src/app/components/nav-bar/nav-bar.component.html
+++ b/store-front/src/app/components/nav-bar/nav-bar.component.html
@@ -20,7 +20,8 @@
- MY ACCOUNT
+ MY ACCOUNT
+ LOGOUT
diff --git a/store-front/src/app/services/user.service.spec.ts b/store-front/src/app/services/user.service.spec.ts
new file mode 100644
index 0000000..857b499
--- /dev/null
+++ b/store-front/src/app/services/user.service.spec.ts
@@ -0,0 +1,16 @@
+/* tslint:disable:no-unused-variable */
+
+import { TestBed, async, inject } from '@angular/core/testing';
+import { UserService } from './user.service';
+
+describe('UserService', () => {
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ providers: [UserService]
+ });
+ });
+
+ it('should ...', inject([UserService], (service: UserService) => {
+ expect(service).toBeTruthy();
+ }));
+});
diff --git a/store-front/src/app/services/user.service.ts b/store-front/src/app/services/user.service.ts
new file mode 100644
index 0000000..e8b89a5
--- /dev/null
+++ b/store-front/src/app/services/user.service.ts
@@ -0,0 +1,35 @@
+import { Injectable } from '@angular/core';
+import {AppConst} from '../constants/app-const';
+import {Http, Headers} from '@angular/http';
+
+@Injectable()
+export class UserService {
+ private serverPath:string = AppConst.serverPath;
+
+ constructor(private http:Http) { }
+
+ newUser(username:string, email:string) {
+ let url = this.serverPath+"/user/newUser";
+ let userInfo = {
+ "username" : username,
+ "email" : email
+ };
+ let tokenHeader = new Headers ({
+ 'Content-Type': 'application/json',
+ 'x-auth-token' : localStorage.getItem("xAuthToken")
+ });
+ return this.http.post(url, JSON.stringify(userInfo), {headers : tokenHeader});
+ }
+
+ retrievePassword(email:string) {
+ let url = this.serverPath+"/user/forgetPassword";
+ let userInfo = {
+ "email" : email
+ };
+ let tokenHeader = new Headers ({
+ 'Content-Type': 'application/json',
+ 'x-auth-token' : localStorage.getItem("xAuthToken")
+ });
+ return this.http.post(url, JSON.stringify(userInfo), {headers : tokenHeader});
+ }
+}