latest
This commit is contained in:
131
bookstore-api/.idea/workspace.xml
generated
131
bookstore-api/.idea/workspace.xml
generated
@@ -16,11 +16,31 @@
|
||||
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
|
||||
<component name="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file leaf-file-name="BookResource.java" pinned="false" current-in-tab="true">
|
||||
<file leaf-file-name="UserResource.java" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/UserResource.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="697">
|
||||
<caret line="172" column="45" lean-forward="false" selection-start-line="172" selection-start-column="45" selection-end-line="172" selection-end-column="45" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="MailConstructor.java" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/utility/MailConstructor.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="345">
|
||||
<caret line="37" column="176" lean-forward="false" selection-start-line="37" selection-start-column="176" selection-end-line="37" selection-end-column="176" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="BookResource.java" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/BookResource.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="52" column="27" lean-forward="true" selection-start-line="52" selection-start-column="27" selection-end-line="52" selection-end-column="27" />
|
||||
<state relative-caret-position="787">
|
||||
<caret line="124" column="5" lean-forward="true" selection-start-line="124" selection-start-column="5" selection-end-line="124" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
@@ -29,7 +49,7 @@
|
||||
<file leaf-file-name="BookServiceImpl.java" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/service/impl/BookServiceImpl.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="525">
|
||||
<state relative-caret-position="697">
|
||||
<caret line="73" column="5" lean-forward="false" selection-start-line="73" selection-start-column="5" selection-end-line="73" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
@@ -99,11 +119,11 @@
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/config/RequestFilter.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/resources/application.properties" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/config/SecurityConfig.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/resource/UserResource.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/utility/MailConstructor.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/service/impl/BookServiceImpl.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/service/BookService.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/resource/BookResource.java" />
|
||||
<option value="$PROJECT_DIR$/src/main/java/com/bookstore/resource/UserResource.java" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@@ -121,10 +141,9 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds">
|
||||
<option name="x" value="71" />
|
||||
<option name="y" value="38" />
|
||||
<option name="width" value="1663" />
|
||||
<option name="height" value="961" />
|
||||
<option name="y" value="23" />
|
||||
<option name="width" value="1280" />
|
||||
<option name="height" value="797" />
|
||||
</component>
|
||||
<component name="ProjectView">
|
||||
<navigator currentView="ProjectPane" proportions="" version="1">
|
||||
@@ -272,6 +291,36 @@
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
</PATH>
|
||||
<PATH>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="bookstore-api" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="bookstore-api" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="src" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="main" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="java" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="bookstore" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="utility" />
|
||||
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
||||
</PATH_ELEMENT>
|
||||
</PATH>
|
||||
<PATH>
|
||||
<PATH_ELEMENT>
|
||||
<option name="myItemId" value="bookstore-api" />
|
||||
@@ -841,15 +890,15 @@
|
||||
<workItem from="1486538831944" duration="450000" />
|
||||
<workItem from="1488378219247" duration="650000" />
|
||||
<workItem from="1488461561430" duration="18419000" />
|
||||
<workItem from="1488731165185" duration="9523000" />
|
||||
<workItem from="1488731165185" duration="11348000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="71535000" />
|
||||
<option name="totallyTimeSpent" value="73360000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="71" y="38" width="1663" height="961" extended-state="0" />
|
||||
<frame x="0" y="23" width="1280" height="797" extended-state="0" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||
@@ -869,11 +918,11 @@
|
||||
<window_info id="Palette	" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32907802" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32796317" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Spring" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32907802" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24244294" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.31744748" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
<window_info id="Bean Validation" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Theme Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
|
||||
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="true" content_ui="tabs" />
|
||||
@@ -1185,24 +1234,6 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/UserResource.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="0">
|
||||
<caret line="57" column="53" lean-forward="false" selection-start-line="57" selection-start-column="39" selection-end-line="57" selection-end-column="53" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/utility/MailConstructor.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="330">
|
||||
<caret line="37" column="176" lean-forward="false" selection-start-line="37" selection-start-column="176" selection-end-line="37" selection-end-column="176" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="false" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/BookstoreApplication.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="270">
|
||||
@@ -1239,14 +1270,6 @@
|
||||
<state />
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/service/impl/BookServiceImpl.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="525">
|
||||
<caret line="73" column="5" lean-forward="false" selection-start-line="73" selection-start-column="5" selection-end-line="73" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/service/BookService.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="285">
|
||||
@@ -1255,10 +1278,34 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/service/impl/BookServiceImpl.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="697">
|
||||
<caret line="73" column="5" lean-forward="false" selection-start-line="73" selection-start-column="5" selection-end-line="73" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/utility/MailConstructor.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="345">
|
||||
<caret line="37" column="176" lean-forward="false" selection-start-line="37" selection-start-column="176" selection-end-line="37" selection-end-column="176" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/BookResource.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="315">
|
||||
<caret line="52" column="27" lean-forward="true" selection-start-line="52" selection-start-column="27" selection-end-line="52" selection-end-column="27" />
|
||||
<state relative-caret-position="787">
|
||||
<caret line="124" column="5" lean-forward="true" selection-start-line="124" selection-start-column="5" selection-end-line="124" selection-end-column="5" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/main/java/com/bookstore/resource/UserResource.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="697">
|
||||
<caret line="172" column="45" lean-forward="false" selection-start-line="172" selection-start-column="45" selection-end-line="172" selection-end-column="45" />
|
||||
<folding />
|
||||
</state>
|
||||
</provider>
|
||||
|
||||
@@ -133,4 +133,44 @@ public class UserResource {
|
||||
|
||||
return new ResponseEntity("User Added Successfully!", HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping("/forgetPassword")
|
||||
public ResponseEntity forgetPassword(@RequestBody String email,
|
||||
HttpServletRequest request,
|
||||
Model model) {
|
||||
model.addAttribute("classActiveForgetPassword", "true");
|
||||
|
||||
User user = userService.findByEmail(email);
|
||||
|
||||
if (user == null) {
|
||||
model.addAttribute("emailNotExists", true);
|
||||
return new ResponseEntity("Email not found!", HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
|
||||
String password = SecurityUtility.randomPassword();
|
||||
|
||||
String encryptedPassword = SecurityUtility.passwordEncoder().encode(password);
|
||||
user.setPassword(encryptedPassword);
|
||||
|
||||
userService.save(user);
|
||||
|
||||
String token = UUID.randomUUID().toString();
|
||||
userService.createPasswordResetTokenForUser(user, token);
|
||||
|
||||
String appUrl =
|
||||
"http://" + request.getServerName() +
|
||||
":" + request.getServerPort() +
|
||||
request.getContextPath();
|
||||
|
||||
SimpleMailMessage newEmail =
|
||||
mailConstructor.constructResetTokenEmail(appUrl, request.getLocale(), token, user, password);
|
||||
|
||||
mailSender.send(newEmail);
|
||||
|
||||
model.addAttribute("forgetPasswordEmailSent", true);
|
||||
|
||||
return new ResponseEntity("Email sent!", HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,17 @@ import { HomeComponent } from './components/home/home.component';
|
||||
import { NavBarComponent } from './components/nav-bar/nav-bar.component';
|
||||
|
||||
import { LoginService } from './services/login.service';
|
||||
import { UserService } from './services/user.service';
|
||||
import { MyAccountComponent } from './components/my-account/my-account.component';
|
||||
import { MyProfileComponent } from './components/my-profile/my-profile.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent,
|
||||
HomeComponent,
|
||||
NavBarComponent,
|
||||
MyAccountComponent
|
||||
MyAccountComponent,
|
||||
MyProfileComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
@@ -29,7 +32,8 @@ import { MyAccountComponent } from './components/my-account/my-account.component
|
||||
MaterialModule
|
||||
],
|
||||
providers: [
|
||||
LoginService
|
||||
LoginService,
|
||||
UserService
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
|
||||
@@ -16,29 +16,10 @@
|
||||
<div class="panel panel-default panel-faq" style="border: none;">
|
||||
<div class="panel-body" style="background-color: #ededed; margin-top: 20px;">
|
||||
<md-tab-group>
|
||||
<md-tab label="New Account">
|
||||
<div style="margin-top:20px;">
|
||||
<div class="alert alert-info" *ngIf="emailSent">An email has been sent to email address you just registered. Please validate your email address and update your password info.</div>
|
||||
<form (ngSubmit)="onSubmit()">
|
||||
<div class="form-group">
|
||||
<label for="newUsername">Username *</label> <span *ngIf="usernameExists" style="color:red;">Username already exists. Choose a different one.</span>
|
||||
<input required="required" type="text" class="form-control" id="newUsername" name="username" [(ngModel)]="username" />
|
||||
<p style="color: #828282;"> Enter your username, special charaters are not allowed.
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email address *</label> <span *ngIf="emailExists" style="color:red;">Email already exists. Choose a different one.</span>
|
||||
<input required="required" type="email" class="form-control" id="email" name="email" [(ngModel)]="email" />
|
||||
<p style="color: #828282;"> A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.</p>
|
||||
</div>
|
||||
<button md-raised-button type="submit" class="mat-primary">Create new account</button>
|
||||
</form>
|
||||
</div>
|
||||
</md-tab>
|
||||
<md-tab label="Login">
|
||||
<div style="margin-top:20px;">
|
||||
<div *ngIf="loginError" style="color:red;">Incorrect username or password.</div>
|
||||
<form (ngSubmit)="onSubmit()">
|
||||
<form (ngSubmit)="onLogin()">
|
||||
<div class="form-group">
|
||||
<label for="username">Username *</label>
|
||||
<input type="text" class="form-control" id="username" name="username" [(ngModel)]="credential.username" required="required" autofocus="autofocus" />
|
||||
@@ -54,7 +35,39 @@
|
||||
</form>
|
||||
</div>
|
||||
</md-tab>
|
||||
<md-tab label="Forget Password">Content 2</md-tab>
|
||||
<md-tab label="New Account">
|
||||
<div style="margin-top:20px;">
|
||||
<div class="alert alert-info" *ngIf="emailSent">An email has been sent to email address you just registered. Please validate your email address and update your password info.</div>
|
||||
<form (ngSubmit)="onNewAccount()">
|
||||
<div class="form-group">
|
||||
<label for="newUsername">Username *</label> <span *ngIf="usernameExists" style="color:red;">Username already exists. Choose a different one.</span>
|
||||
<input required="required" type="text" class="form-control" id="newUsername" name="username" [(ngModel)]="username" />
|
||||
<p style="color: #828282;"> Enter your username, special charaters are not allowed.
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email address *</label> <span *ngIf="emailExists" style="color:red;">Email already exists. Choose a different one.</span>
|
||||
<input required="required" type="email" class="form-control" id="email" name="email" [(ngModel)]="email" />
|
||||
<p style="color: #828282;"> A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.</p>
|
||||
</div>
|
||||
<button md-raised-button type="submit" class="mat-primary">Create new account</button>
|
||||
</form>
|
||||
</div>
|
||||
</md-tab>
|
||||
<md-tab label="Forget Password">
|
||||
<div style="margin-top:20px;">
|
||||
<div *ngIf="emailNotExists" class="alert alert-danger">Email doesn't exists.</div>
|
||||
<div *ngIf="forgetPasswordEmailSent" class="alert alert-success">Email sent.</div>
|
||||
<form (ngSubmit)="onForgetPassword()" method="post">
|
||||
<div class="form-group">
|
||||
<label for="recoverEmail">Your Email *</label>
|
||||
<input type="text" class="form-control" id="recoverEmail" name="email" />
|
||||
<p style="color: #828282;"> Enter your registered email address.</p>
|
||||
</div>
|
||||
<button md-raised-button type="submit" class="mat-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</md-tab>
|
||||
</md-tab-group>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<p>
|
||||
my-profile works!
|
||||
</p>
|
||||
@@ -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<MyProfileComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ MyProfileComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MyProfileComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
@@ -20,7 +20,8 @@
|
||||
<li>
|
||||
|
||||
</li>
|
||||
<li ><a md-button routerLink="/myAccount" routerLinkActive="active">MY ACCOUNT</a></li>
|
||||
<li *ngIf="!loggedIn" ><a md-button routerLink="/myAccount" routerLinkActive="active">MY ACCOUNT</a></li>
|
||||
<li *ngIf="loggedIn"><a md-button (click)="logout()">LOGOUT</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<!--/.nav-collapse -->
|
||||
|
||||
16
store-front/src/app/services/user.service.spec.ts
Normal file
16
store-front/src/app/services/user.service.spec.ts
Normal file
@@ -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();
|
||||
}));
|
||||
});
|
||||
35
store-front/src/app/services/user.service.ts
Normal file
35
store-front/src/app/services/user.service.ts
Normal file
@@ -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});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user