From 387d686b03d5701725d729eb742c3a5f6fea405b Mon Sep 17 00:00:00 2001
From: Sanjith Sivapuram <59279@hexaware.com>
Date: Tue, 21 Sep 2021 18:11:13 +0530
Subject: [PATCH] Login Spring Security
---
.../src/main/resources/application.properties | 4 +-
ShopifyUI/proxy.conf.json | 6 +-
ShopifyUI/src/app/app-routing.module.ts | 4 +-
.../src/app/auth/login/login.component.ts | 22 ++++---
.../app/auth/sign-up/sign-up.component.css | 4 +-
.../app/auth/sign-up/sign-up.component.html | 35 +++++++++++
.../src/app/auth/sign-up/sign-up.component.ts | 36 ++++++++---
.../app/components/admin/admin.component.css | 18 ++++++
.../app/components/admin/admin.component.html | 39 +++++++++++-
.../app/components/cart/cart.component.html | 49 ++++++++++-----
.../src/app/components/cart/cart.component.ts | 17 ++++-
.../app/components/home/home.component.css | 3 -
.../app/components/home/home.component.html | 23 ++++++-
.../src/app/components/home/home.component.ts | 17 ++++-
.../payments/payments.component.html | 49 ++++++++++-----
.../components/payments/payments.component.ts | 16 ++++-
.../product-detail.component.css | 37 +++++++++++
.../product-detail.component.html | 62 +++++++++++++++++--
.../product-detail.component.ts | 61 +++++++++++++++++-
.../products/products.component.html | 23 ++++++-
.../components/products/products.component.ts | 18 +++++-
ShopifyUI/src/app/model/review.model.ts | 14 +++--
ShopifyUI/src/app/model/reviewDto.model.ts | 8 +++
ShopifyUI/src/app/service/cart.service.ts | 4 +-
ShopifyUI/src/app/service/review.service.ts | 13 +++-
ShopifyUI/src/app/service/user.service.ts | 31 +++++++++-
ShopifyUI/src/styles.css | 9 +++
27 files changed, 534 insertions(+), 88 deletions(-)
create mode 100644 ShopifyUI/src/app/model/reviewDto.model.ts
diff --git a/Shopify-Cart/src/main/resources/application.properties b/Shopify-Cart/src/main/resources/application.properties
index 44b3588..9304483 100644
--- a/Shopify-Cart/src/main/resources/application.properties
+++ b/Shopify-Cart/src/main/resources/application.properties
@@ -1,7 +1,7 @@
server.port=8002
-spring.datasource.url=jdbc:mysql://10.3.117.26:3306/Shopify_DB?createDatabaseIfNotExist=true
-spring.datasource.username=testuser
+spring.datasource.url=jdbc:mysql://10.3.117.23:3306/Shopify_DB?createDatabaseIfNotExist=true
+spring.datasource.username=testuser1
spring.datasource.password=PASSWORD123
server.servlet.context-path=/api2
diff --git a/ShopifyUI/proxy.conf.json b/ShopifyUI/proxy.conf.json
index b722973..c5e5576 100644
--- a/ShopifyUI/proxy.conf.json
+++ b/ShopifyUI/proxy.conf.json
@@ -1,14 +1,14 @@
{
"/api1": {
- "target": "http://10.3.117.26:8001",
+ "target": "http://10.3.117.23:8001",
"secure": false
},
"/api2": {
- "target": "http://10.3.117.26:8002",
+ "target": "http://10.3.117.23:8002",
"secure": false
},
"/api3": {
- "target": "http://10.3.117.26:8003",
+ "target": "http://10.3.117.23:8003",
"secure": false
}
}
\ No newline at end of file
diff --git a/ShopifyUI/src/app/app-routing.module.ts b/ShopifyUI/src/app/app-routing.module.ts
index 4b229cc..a42caa0 100644
--- a/ShopifyUI/src/app/app-routing.module.ts
+++ b/ShopifyUI/src/app/app-routing.module.ts
@@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './auth/login/login.component';
import { SignUpComponent } from './auth/sign-up/sign-up.component';
+import { AdminComponent } from './components/admin/admin.component';
import { CartComponent } from './components/cart/cart.component';
import { HomeComponent } from './components/home/home.component';
import { PaymentsComponent } from './components/payments/payments.component';
@@ -16,7 +17,8 @@ const routes: Routes = [
{ path: 'cart/:user_id', component: CartComponent},
{ path: 'payment', component: PaymentsComponent},
{ path: 'login', component: LoginComponent},
- { path: 'signup', component: SignUpComponent}
+ { path: 'signup', component: SignUpComponent},
+ { path: 'admin', component: AdminComponent},
];
@NgModule({
diff --git a/ShopifyUI/src/app/auth/login/login.component.ts b/ShopifyUI/src/app/auth/login/login.component.ts
index 4d211ba..5142888 100644
--- a/ShopifyUI/src/app/auth/login/login.component.ts
+++ b/ShopifyUI/src/app/auth/login/login.component.ts
@@ -33,14 +33,18 @@ export class LoginComponent implements OnInit {
username: this.loginForm.value.username,
password: this.loginForm.value.password
}
- // this.userService.loginUser(user).subscribe(data => {
- // window.sessionStorage.setItem("username", user.username);
- // window.sessionStorage.setItem("authcode", btoa(user.username + ":" + user.password));
- // window.sessionStorage.setItem("isLoggedIn", "true");
- // this.route.navigateByUrl("/");
- // },
- // (err: any) => {
- // this.msg = "Invalid Credentials"
- // })
+ this.userService.loginUser(user).subscribe(data => {
+ console.log(data)
+ this.userService.getUserByName(user.username).subscribe(data1 => {
+ window.sessionStorage.setItem("username", user.username);
+ window.sessionStorage.setItem("user_id", String(data1.id));
+ window.sessionStorage.setItem("authcode", btoa(user.username + ":" + user.password));
+ window.sessionStorage.setItem("isLoggedIn", "true");
+ this.route.navigateByUrl("/");
+ })
+ },
+ (err: any) => {
+ this.msg = "Invalid Credentials"
+ })
}
}
diff --git a/ShopifyUI/src/app/auth/sign-up/sign-up.component.css b/ShopifyUI/src/app/auth/sign-up/sign-up.component.css
index b070a5a..2cbc823 100644
--- a/ShopifyUI/src/app/auth/sign-up/sign-up.component.css
+++ b/ShopifyUI/src/app/auth/sign-up/sign-up.component.css
@@ -3,6 +3,7 @@
border: none;
padding: 16px;
height: 570px;
+ overflow-y: scroll;
box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-webkit-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
-moz-box-shadow: 2px 4px 14px 0px rgba(0, 0, 0, 0.74);
@@ -29,5 +30,4 @@
.login_form p {
color: #E74C3C;
-}
-
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/ShopifyUI/src/app/auth/sign-up/sign-up.component.html b/ShopifyUI/src/app/auth/sign-up/sign-up.component.html
index f6a4244..6a85182 100644
--- a/ShopifyUI/src/app/auth/sign-up/sign-up.component.html
+++ b/ShopifyUI/src/app/auth/sign-up/sign-up.component.html
@@ -29,6 +29,41 @@
Invalid Password
+
+
+
Invalid Mobile Number
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Sign Up
diff --git a/ShopifyUI/src/app/auth/sign-up/sign-up.component.ts b/ShopifyUI/src/app/auth/sign-up/sign-up.component.ts
index 5616eec..5d63892 100644
--- a/ShopifyUI/src/app/auth/sign-up/sign-up.component.ts
+++ b/ShopifyUI/src/app/auth/sign-up/sign-up.component.ts
@@ -19,6 +19,13 @@ export class SignUpComponent implements OnInit {
name: new FormControl(''),
username: new FormControl(''),
password: new FormControl(''),
+ mobileNumber: new FormControl(''),
+ emailId: new FormControl(''),
+ address: new FormControl(''),
+ city: new FormControl(''),
+ state: new FormControl(''),
+ country: new FormControl(''),
+ pinCode: new FormControl('')
})
}
@@ -26,7 +33,14 @@ export class SignUpComponent implements OnInit {
this.signUpForm = new FormGroup({
name: new FormControl('', Validators.required),
username: new FormControl('', Validators.required),
- password: new FormControl('', Validators.required)
+ password: new FormControl('', Validators.required),
+ mobileNumber: new FormControl('',Validators.required),
+ emailId: new FormControl('',Validators.required),
+ address: new FormControl('',Validators.required),
+ city: new FormControl('',Validators.required),
+ state: new FormControl('',Validators.required),
+ country: new FormControl('',Validators.required),
+ pinCode: new FormControl('',Validators.required)
})
}
@@ -35,13 +49,21 @@ export class SignUpComponent implements OnInit {
name: this.signUpForm.value.name,
username: this.signUpForm.value.username,
password: this.signUpForm.value.password,
+ mobileNumber: this.signUpForm.value.mobileNumber,
+ emailId: this.signUpForm.value.emailId,
+ address: this.signUpForm.value.address,
+ city: this.signUpForm.value.city,
+ state: this.signUpForm.value.state,
+ country: this.signUpForm.value.country,
+ pinCode: this.signUpForm.value.pinCode,
+
}
- // this.userService.postUser(user).subscribe(data => {
- // this.route.navigateByUrl("/login?msg=sign-up%20success");
- // },
- // (err: any) => {
- // this.msg = "Could Not Sign In";
- // })
+ this.userService.postUser(user).subscribe(data => {
+ this.route.navigateByUrl("/login?msg=sign-up%20success");
+ },
+ (err: any) => {
+ this.msg = "Could Not Sign In";
+ })
}
}
diff --git a/ShopifyUI/src/app/components/admin/admin.component.css b/ShopifyUI/src/app/components/admin/admin.component.css
index e69de29..05e567b 100644
--- a/ShopifyUI/src/app/components/admin/admin.component.css
+++ b/ShopifyUI/src/app/components/admin/admin.component.css
@@ -0,0 +1,18 @@
+.admin-heading {
+ font-size: 5em;
+ font-weight: 700;
+ color: #1B4F72;
+}
+
+.card-heading {
+ /* font-size: 5em; */
+ font-weight: 500;
+ background-color: #1B4F72;
+ padding: 12px 16px;
+ height: 250px;
+ border-radius: 20px;
+}
+
+.card-heading h3 {
+ vertical-align: middle;
+}
\ No newline at end of file
diff --git a/ShopifyUI/src/app/components/admin/admin.component.html b/ShopifyUI/src/app/components/admin/admin.component.html
index 49659db..0e74394 100644
--- a/ShopifyUI/src/app/components/admin/admin.component.html
+++ b/ShopifyUI/src/app/components/admin/admin.component.html
@@ -1 +1,38 @@
-admin works!
+
+
+
+
+
+
+
+
+
+
+
View All Orders
+
+
+
+
+
+
View All Products
+
+
+
+
+
+
View User Requests
+
+
+
\ No newline at end of file
diff --git a/ShopifyUI/src/app/components/cart/cart.component.html b/ShopifyUI/src/app/components/cart/cart.component.html
index bd442c0..8e3f2dd 100644
--- a/ShopifyUI/src/app/components/cart/cart.component.html
+++ b/ShopifyUI/src/app/components/cart/cart.component.html
@@ -1,19 +1,36 @@
-
-
-
Shopify
-
-
-
-
-
+
+
+
+
Shopify
+
+
+
+
+
+
+
+
+
+
+ Hello {{username}}
+
+ Personal details
+ Orders
+ Logout
+
+
+
+
+ Login
+
+
+
diff --git a/ShopifyUI/src/app/components/cart/cart.component.ts b/ShopifyUI/src/app/components/cart/cart.component.ts
index 71c077f..2a453ed 100644
--- a/ShopifyUI/src/app/components/cart/cart.component.ts
+++ b/ShopifyUI/src/app/components/cart/cart.component.ts
@@ -11,11 +11,15 @@ export class CartComponent implements OnInit {
cartNo:number = 0;
cartItems:Cart[];
- uid:string = "1";
+ uid:number = 1;
totalPrice:number = 0;
+ username:any='';
+ authcode:any='';
constructor(private cartService:CartService) { }
ngOnInit(): void {
+ this.username = window.sessionStorage.getItem("username");
+ this.authcode = window.sessionStorage.getItem("authcode")
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
this.cartItems=data1;
@@ -91,4 +95,15 @@ export class CartComponent implements OnInit {
})
}
+ onLogout() {
+ if (this.authcode != null) {
+ this.authcode = null;
+ this.username = null;
+ window.sessionStorage.removeItem("username");
+ window.sessionStorage.removeItem("user_id");
+ window.sessionStorage.removeItem("authcode");
+ window.sessionStorage.removeItem("isLoggedIn");
+ }
+ }
+
}
diff --git a/ShopifyUI/src/app/components/home/home.component.css b/ShopifyUI/src/app/components/home/home.component.css
index ea44c56..01f14b0 100644
--- a/ShopifyUI/src/app/components/home/home.component.css
+++ b/ShopifyUI/src/app/components/home/home.component.css
@@ -10,9 +10,6 @@
.home-heading {
font-size: 7em;
font-weight: 700;
- /* background-repeat: no-repeat;
- background-size: contain;
- background-position: center; */
}
.product {
diff --git a/ShopifyUI/src/app/components/home/home.component.html b/ShopifyUI/src/app/components/home/home.component.html
index ea82ac0..646573c 100644
--- a/ShopifyUI/src/app/components/home/home.component.html
+++ b/ShopifyUI/src/app/components/home/home.component.html
@@ -1,5 +1,6 @@
-
-
+
+
+
Shopify
-
Login
+
+
+
+
+
+ Hello {{username}}
+
+ Personal details
+ Orders
+ Logout
+
+
+
+
+ Login
+
+
diff --git a/ShopifyUI/src/app/components/home/home.component.ts b/ShopifyUI/src/app/components/home/home.component.ts
index 988c0c6..3f2e2cb 100644
--- a/ShopifyUI/src/app/components/home/home.component.ts
+++ b/ShopifyUI/src/app/components/home/home.component.ts
@@ -11,12 +11,16 @@ import { ProductService } from 'src/app/service/product.service';
export class HomeComponent implements OnInit {
cartNo:number = 0;
- uid:string = "1";
+ uid:number = 1;
+ username:any = '';
+ authcode:any = '';
searchValue: string = '';
products:Product[];
constructor(private cartService: CartService,private productService: ProductService) { }
ngOnInit(): void {
+ this.username = window.sessionStorage.getItem("username");
+ this.authcode = window.sessionStorage.getItem("authcode");
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
})
@@ -28,4 +32,15 @@ export class HomeComponent implements OnInit {
onSearchEnter(value: string) {
this.searchValue = value;
}
+
+ onLogout() {
+ if (this.authcode != null) {
+ this.authcode = null;
+ this.username = null;
+ window.sessionStorage.removeItem("username");
+ window.sessionStorage.removeItem("user_id");
+ window.sessionStorage.removeItem("authcode");
+ window.sessionStorage.removeItem("isLoggedIn");
+ }
+ }
}
diff --git a/ShopifyUI/src/app/components/payments/payments.component.html b/ShopifyUI/src/app/components/payments/payments.component.html
index 9b0754b..9589c85 100644
--- a/ShopifyUI/src/app/components/payments/payments.component.html
+++ b/ShopifyUI/src/app/components/payments/payments.component.html
@@ -1,19 +1,36 @@
-
-
-
Shopify
-
-
-
-
-
+
+
+
+
Shopify
+
+
+
+
+
+
+
+
+
+
+ Hello {{username}}
+
+ Personal details
+ Orders
+ Logout
+
+
+
+
+ Login
+
+
+
diff --git a/ShopifyUI/src/app/components/payments/payments.component.ts b/ShopifyUI/src/app/components/payments/payments.component.ts
index 302798e..6836d88 100644
--- a/ShopifyUI/src/app/components/payments/payments.component.ts
+++ b/ShopifyUI/src/app/components/payments/payments.component.ts
@@ -9,13 +9,17 @@ import { CartService } from 'src/app/service/cart.service';
})
export class PaymentsComponent implements OnInit {
- uid:string = "1";
+ uid:number = 1;
cartNo: number = 0;
cartItems: Cart[] = [];
totalPrice: number = 0;
+ username:any = '';
+ authcode:any = '';
constructor(private cartService: CartService) { }
ngOnInit(): void {
+ this.username = window.sessionStorage.getItem("username");
+ this.authcode = window.sessionStorage.getItem("authcode");
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
this.cartItems=data1;
@@ -26,4 +30,14 @@ export class PaymentsComponent implements OnInit {
})
}
+ onLogout() {
+ if (this.authcode != null) {
+ this.authcode = null;
+ this.username = null;
+ window.sessionStorage.removeItem("username");
+ window.sessionStorage.removeItem("user_id");
+ window.sessionStorage.removeItem("authcode");
+ window.sessionStorage.removeItem("isLoggedIn");
+ }
+ }
}
diff --git a/ShopifyUI/src/app/components/product-detail/product-detail.component.css b/ShopifyUI/src/app/components/product-detail/product-detail.component.css
index 500b290..b738955 100644
--- a/ShopifyUI/src/app/components/product-detail/product-detail.component.css
+++ b/ShopifyUI/src/app/components/product-detail/product-detail.component.css
@@ -17,4 +17,41 @@
.username {
font-weight: 700;
+}
+
+.reviewInput input {
+ width: 100%;
+ padding: 10px;
+}
+
+.deleteBtn button {
+ background-color: transparent;
+ border: 1px solid #E74C3C;
+ border-radius: 20px;
+ color: #E74C3C;
+ padding: 12px 16px;
+ transition: 0.2s all linear;
+}
+
+.deleteBtn button:hover {
+ background-color: #E74C3C;
+ color: white;
+}
+.review_Form input {
+ width: 100%;
+ padding: 12px;
+}
+
+.review_Form select {
+ width: 100%;
+ padding: 14px;
+}
+
+.review_Form button {
+ background-color: #2E86C1;
+ color: white;
+ border: 1px solid transparent;
+ border-radius: 20px;
+ padding: 12px 14px;
+ width: 100%;
}
\ No newline at end of file
diff --git a/ShopifyUI/src/app/components/product-detail/product-detail.component.html b/ShopifyUI/src/app/components/product-detail/product-detail.component.html
index f7d45fd..3ca9492 100644
--- a/ShopifyUI/src/app/components/product-detail/product-detail.component.html
+++ b/ShopifyUI/src/app/components/product-detail/product-detail.component.html
@@ -1,19 +1,36 @@
-
-
+
+
+
Shopify
-
+
-
+
-
Login
+
+
+
+
+
+ Hello {{username}}
+
+ Personal details
+ Orders
+ Logout
+
+
+
+
+ Login
+
+
@@ -58,12 +75,15 @@
-
+
+
Submit Your Review
+
+
+
diff --git a/ShopifyUI/src/app/components/product-detail/product-detail.component.ts b/ShopifyUI/src/app/components/product-detail/product-detail.component.ts
index 70e7922..fc649ab 100644
--- a/ShopifyUI/src/app/components/product-detail/product-detail.component.ts
+++ b/ShopifyUI/src/app/components/product-detail/product-detail.component.ts
@@ -1,8 +1,10 @@
import { Component, OnInit } from '@angular/core';
+import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { Cart } from 'src/app/model/cart.model';
import { Product } from 'src/app/model/product.model';
-import { ReviewDto } from 'src/app/model/review.model';
+import { Review } from 'src/app/model/review.model';
+import { ReviewDto } from 'src/app/model/reviewDto.model';
import { CartService } from 'src/app/service/cart.service';
import { ProductService } from 'src/app/service/product.service';
import { ReviewService } from 'src/app/service/review.service';
@@ -14,16 +16,31 @@ import { ReviewService } from 'src/app/service/review.service';
})
export class ProductDetailComponent implements OnInit {
pid:any;
- uid:string = "1";
+ uid:any = 1;
product:Product;
currentRating:any = [];
rating:any = [];
quantity:number = 1;
cartNo:number = 0;
reviewDtos: ReviewDto[] = [];
- constructor(private actRouter:ActivatedRoute, private productService:ProductService, private cartService:CartService,private reviewService:ReviewService) { }
+ reviewForm: FormGroup;
+ username:any='';
+ authcode:any='';
+ constructor(private actRouter:ActivatedRoute, private productService:ProductService, private cartService:CartService,private reviewService:ReviewService) {
+ this.reviewForm = new FormGroup({
+ reviewText : new FormControl(''),
+ rating : new FormControl(''),
+ })
+ }
ngOnInit(): void {
+ this.username = window.sessionStorage.getItem("username");
+ this.authcode = window.sessionStorage.getItem("authcode");
+ this.uid = window.sessionStorage.getItem("user_id");
+ this.reviewForm = new FormGroup({
+ reviewText : new FormControl('', Validators.required),
+ rating : new FormControl('', Validators.required),
+ })
this.cartService.getCartByUser(this.uid).subscribe(data1 => {
this.cartNo = data1.length;
})
@@ -42,6 +59,7 @@ export class ProductDetailComponent implements OnInit {
})
this.reviewService.getReviewsByProduct(this.pid).subscribe(data => {
this.reviewDtos = data;
+ console.log(this.reviewDtos)
})
}
@@ -63,4 +81,41 @@ export class ProductDetailComponent implements OnInit {
})
}
+ onReviewFormSubmit() {
+ let review : Review = {
+ reviewText: this.reviewForm.value.reviewText,
+ rating: this.reviewForm.value.rating,
+ }
+ this.reviewService.postReview(this.uid,this.pid,review).subscribe(data => {
+ this.reviewForm = new FormGroup({
+ reviewText : new FormControl('', Validators.required),
+ rating : new FormControl('', Validators.required),
+ })
+ this.reviewService.getReviewsByProduct(this.pid).subscribe(data => {
+ this.reviewDtos = data;
+ console.log(this.reviewDtos)
+ })
+ })
+ }
+
+ onReviewDelete(rid:number) {
+ this.reviewService.deleteReview(rid).subscribe(data => {
+ this.reviewDtos.forEach((i, index) => {
+ if (i.id == rid) {
+ this.reviewDtos.splice(index, 1);
+ }
+ })
+ })
+ }
+
+ onLogout() {
+ if (this.authcode != null) {
+ this.authcode = null;
+ this.username = null;
+ window.sessionStorage.removeItem("username");
+ window.sessionStorage.removeItem("user_id");
+ window.sessionStorage.removeItem("authcode");
+ window.sessionStorage.removeItem("isLoggedIn");
+ }
+ }
}
diff --git a/ShopifyUI/src/app/components/products/products.component.html b/ShopifyUI/src/app/components/products/products.component.html
index 7154203..17ca418 100644
--- a/ShopifyUI/src/app/components/products/products.component.html
+++ b/ShopifyUI/src/app/components/products/products.component.html
@@ -1,5 +1,6 @@
-
-
+
+
+
Shopify
-
Login
+
+
+
+
+
+ Hello {{username}}
+
+ Personal details
+ Orders
+ Logout
+
+
+
+
+ Login
+
+
diff --git a/ShopifyUI/src/app/components/products/products.component.ts b/ShopifyUI/src/app/components/products/products.component.ts
index 11d1c5a..ec08a59 100644
--- a/ShopifyUI/src/app/components/products/products.component.ts
+++ b/ShopifyUI/src/app/components/products/products.component.ts
@@ -17,7 +17,9 @@ export class ProductsComponent implements OnInit {
products: Product[] = [];
searchForm: FormGroup;
prodName:string;
- uid:string = "1";
+ uid:number = 1;
+ username:any='';
+ authcode:any='';
constructor(private productService: ProductService,private cartService: CartService) {
this.searchForm = new FormGroup({
prodName: new FormControl('')
@@ -25,6 +27,8 @@ export class ProductsComponent implements OnInit {
}
ngOnInit(): void {
+ this.username = window.sessionStorage.getItem("username");
+ this.authcode = window.sessionStorage.getItem("authcode");
console.log("In Product Component");
this.searchForm = new FormGroup({
prodName: new FormControl('', Validators.required)
@@ -57,4 +61,16 @@ export class ProductsComponent implements OnInit {
})
})
}
+
+ onLogout() {
+ if (this.authcode != null) {
+ this.authcode = null;
+ this.username = null;
+ window.sessionStorage.removeItem("username");
+ window.sessionStorage.removeItem("user_id");
+ window.sessionStorage.removeItem("authcode");
+ window.sessionStorage.removeItem("isLoggedIn");
+ }
+ }
+
}
diff --git a/ShopifyUI/src/app/model/review.model.ts b/ShopifyUI/src/app/model/review.model.ts
index ebe86c0..9b151cc 100644
--- a/ShopifyUI/src/app/model/review.model.ts
+++ b/ShopifyUI/src/app/model/review.model.ts
@@ -1,6 +1,10 @@
-export class ReviewDto {
- reviewText:string;
- rating:number;
- username:string;
- product_name:string;
+import { Product } from "./product.model";
+import { User } from "./user.model";
+
+export class Review {
+ id?:number;
+ reviewText:string = '';
+ rating:number = 0;
+ user?: User
+ product?: Product;
}
\ No newline at end of file
diff --git a/ShopifyUI/src/app/model/reviewDto.model.ts b/ShopifyUI/src/app/model/reviewDto.model.ts
new file mode 100644
index 0000000..7db2e3e
--- /dev/null
+++ b/ShopifyUI/src/app/model/reviewDto.model.ts
@@ -0,0 +1,8 @@
+export class ReviewDto {
+ id?: number;
+ reviewText:string;
+ rating:number;
+ userId?:number;
+ username:string;
+ productName:string;
+}
\ No newline at end of file
diff --git a/ShopifyUI/src/app/service/cart.service.ts b/ShopifyUI/src/app/service/cart.service.ts
index c6cd52f..b01a5fa 100644
--- a/ShopifyUI/src/app/service/cart.service.ts
+++ b/ShopifyUI/src/app/service/cart.service.ts
@@ -12,12 +12,12 @@ export class CartService {
constructor(private httpClent:HttpClient) { }
- public postCart(cart:Cart,uid:string,pid:number): Observable {
+ public postCart(cart:Cart,uid:number,pid:number): Observable {
let cart_post_api = this.path + "/cart/" + uid + "/" + pid;
return this.httpClent.post(cart_post_api,cart);
}
- public getCartByUser(uid:string): Observable {
+ public getCartByUser(uid:number): Observable {
let cart_get_api = this.path + "/cart/" + uid;
return this.httpClent.get(cart_get_api);
}
diff --git a/ShopifyUI/src/app/service/review.service.ts b/ShopifyUI/src/app/service/review.service.ts
index 3bbd46e..cc1fb08 100644
--- a/ShopifyUI/src/app/service/review.service.ts
+++ b/ShopifyUI/src/app/service/review.service.ts
@@ -1,7 +1,8 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
-import { ReviewDto } from '../model/review.model';
+import { Review } from '../model/review.model';
+import { ReviewDto } from '../model/reviewDto.model';
@Injectable({
providedIn: 'root'
@@ -12,8 +13,18 @@ export class ReviewService {
constructor(private httpClient:HttpClient) { }
+ public postReview(uid:number,pid:number,review:Review): Observable {
+ let review_post_api = this.path + "/review/" + pid + "/" + uid;
+ return this.httpClient.post(review_post_api,review);
+ }
+
public getReviewsByProduct(pid:string): Observable {
let review_get_api = this.path + "/review/product?pid=" + pid;
return this.httpClient.get(review_get_api);
}
+
+ public deleteReview(rid:number) {
+ let review_delete_api = this.path + "/review/" + rid;
+ return this.httpClient.delete(review_delete_api);
+ }
}
diff --git a/ShopifyUI/src/app/service/user.service.ts b/ShopifyUI/src/app/service/user.service.ts
index 3569db9..d27130d 100644
--- a/ShopifyUI/src/app/service/user.service.ts
+++ b/ShopifyUI/src/app/service/user.service.ts
@@ -1,9 +1,38 @@
+import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
+import { Observable } from 'rxjs';
+import { User } from '../model/user.model';
@Injectable({
providedIn: 'root'
})
export class UserService {
- constructor() { }
+ path:string = "http://localhost:59279/api1";
+
+ constructor(private httpClient:HttpClient) { }
+
+ public postUser(user:User): Observable {
+ let user_post_api = this.path + '/sign-up';
+ let authcode = btoa(user.username + ":" + user.password)
+ user.username = authcode;
+ user.password = "";
+ return this.httpClient.post(user_post_api,user);
+ }
+
+ public loginUser(user: User) {
+ let httpOptions = {
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Basic ' + btoa(user.username + ":" + user.password)
+ })
+ }
+ let user_login_api = this.path + "/login"
+ return this.httpClient.get(user_login_api, httpOptions);
+ }
+
+ public getUserByName(username:string): Observable {
+ let user_getName_api = this.path + "/user/name/" + username;
+ return this.httpClient.get(user_getName_api);
+ }
}
diff --git a/ShopifyUI/src/styles.css b/ShopifyUI/src/styles.css
index 5e0c58e..acfa071 100644
--- a/ShopifyUI/src/styles.css
+++ b/ShopifyUI/src/styles.css
@@ -31,6 +31,15 @@ body {
color: white;
}
+.dropBtn {
+ color: white;
+ font-size: 25px;
+}
+
+.dropBtn:hover {
+ color: white;
+}
+
.active a {
border-bottom: 1px solid white;
}