Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/login confirm pass #41

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ static/
__pycache__/
env/
node_modules/

# for theme viewing
themes/

# downloads
download/
8 changes: 7 additions & 1 deletion assets/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h4 class="mb-5">
</div>
<div class="modal-body">
<form [(formGroup)]="usersForm" (ngSubmit)="login()" id="form-login" class="form" method="post">

<div class="form-group mb-5">
<label>Email</label>
<input formControlName="email" type="email" class="form-control" placeholder="[email protected]">
Expand All @@ -52,8 +53,13 @@ <h4 class="mb-5">
<p>Try to check your password by clicking the uncover icon</p>
</div>
</div>

</div>
<div class="d-flex align-items-left justify-content-between">
<div class="form-check">
<a href="{{forgetPasswordUrl}}">Forget password?</a>
</div>
</div>

<div class="d-flex align-items-center justify-content-between">
<div class="form-check">
<input type="checkbox" [checked]="rememberMe" (change)="rememberMe = !rememberMe" name="" class="form-check-input" id="rememberUser">
Expand Down
17 changes: 14 additions & 3 deletions assets/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, HostListener } from '@angular/core';
import { AuthService} from './commons/services/auth/auth.service';
import { FormControl, FormBuilder, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { Title } from '@angular/platform-browser';
import { domain_url } from './commons/constants/global.constants';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [AuthService]
})

export class AppComponent implements OnInit {
@HostListener("window:beforeunload",["$event"])
clearLocalStorage(event){
if(JSON.parse(localStorage.getItem('remember')) === false){
localStorage.clear();
}
}

usersForm;
errors;
rememberMe:boolean = false;
forgetPasswordUrl = "http://"+domain_url+":8000/user/password_reset/";

constructor(
private authService: AuthService,
Expand All @@ -29,11 +39,12 @@ export class AppComponent implements OnInit {
email : new FormControl('', [Validators.required, Validators.email]),
password : new FormControl('', Validators.required)
});
console.log(JSON.parse(localStorage.getItem('remember')));

}

get username(){
return this.usersForm.get('username');
get email(){
return this.usersForm.get('email');
}

get password(){
Expand Down
12 changes: 12 additions & 0 deletions assets/src/app/commons/constants/global.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const domain_url = 'localhost';

// home urls
export const home_theme = '/home/theme/';
export const home_category = '/home/theme/category/';
export const home_subscribe = '/home/theme/subscribe/';

// categories
export const categories = ['Angular JS','E-Commerce','General','Bootstrap 4'];

//user
export let user_object:any;
34 changes: 9 additions & 25 deletions assets/src/app/commons/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { domain_url } from '../../constants/global.constants';

@Injectable({
providedIn: 'root'
Expand All @@ -8,13 +9,14 @@ export class AuthService {
rememberMe:boolean;
token;
user;

constructor(private http: HttpClient) { }

// Generate token upon login
loginAuth(user,remember){
this.rememberMe = remember;
this.user = user;
return this.http.post<any>("http://localhost:8000/user/login/", user)
localStorage['remember'] = JSON.stringify(remember);
localStorage['user'] = JSON.stringify(user);
return this.http.post<any>("http://"+domain_url+":8000/user/login/", user)
.toPromise()
.then(
response => {
Expand All @@ -31,7 +33,7 @@ export class AuthService {

// Generate token upon register
registerAuth(user){
return this.http.post<any>("http://localhost:8000/user/register/", user)
return this.http.post<any>("http://"+domain_url+":8000/user/register/", user)
.toPromise()
.then(
response => {
Expand All @@ -44,7 +46,7 @@ export class AuthService {
}

refreshToken(user){
return this.http.get<any>("http://localhost:8000/user/refresh/", user)
return this.http.get<any>("http://"+domain_url+":8000/user/refresh/", user)
.toPromise()
.then(
response => {
Expand All @@ -60,34 +62,16 @@ export class AuthService {

setToken(token){
this.token = token;
if(this.rememberMe == true){
localStorage['token'] = JSON.stringify(token);
}
else{
sessionStorage['token'] = JSON.stringify(token);
}
localStorage['token'] = JSON.stringify(token);
}

getToken(){
if(this.rememberMe == true){
let token = localStorage.getItem('token');
return JSON.parse(token);
}
this.getSessionToken();
}

getSessionToken(){
if(sessionStorage['token'] == null ||
sessionStorage['token'] == undefined){
return JSON.parse(null);
}
this.token = this.refreshToken(this.user);
sessionStorage['token'] = JSON.stringify(this.token);

let token = sessionStorage.getItem('token');
return JSON.parse(token);
}


removeToken(){
localStorage.removeItem('token');
}
Expand Down
52 changes: 51 additions & 1 deletion assets/src/app/commons/services/cart/cart.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { domain_url } from '../../constants/global.constants';

@Injectable({
providedIn: 'root'
})
export class CartService {

httpHeaders = new HttpHeaders({'Content-type':'application/json'});
edit;

constructor(
private http: HttpClient) { }

getThemeCart(id){
return this.http.get<any>('http://localhost:8000/home/theme/cart/'+id+'/', {headers: this.httpHeaders})
return this.http.get<any>('http://'+domain_url+':8000/home/theme/cart/'+id+'/', {headers: this.httpHeaders})
.toPromise()
.then(
response => {
Expand All @@ -24,4 +27,51 @@ export class CartService {
}
)
}

buyThemeService(id){
return this.http.get<any>('http://'+domain_url+':8000/details/download/'+id+'/', {headers: this.httpHeaders})
.toPromise()
.then(
response => {
return response;
}
)
.catch(
error => {
return error;
}
)

}

editLicenseService(id,license_id){
this.edit = {'id': id, 'license_id': license_id}
return this.http.post<any>('http://'+domain_url+':8000/home/theme/edit_license/', this.edit)
.toPromise()
.then(
response => {
return response;
}
)
.catch(
error => {
return error;
}
)
}

incrementDownloadService(id){
return this.http.get<any>('http://'+domain_url+':8000/details/download/'+id+'/')
.toPromise()
.then(
response => {
return response;
}
)
.catch(
error => {
return error;
}
)
}
}
20 changes: 18 additions & 2 deletions assets/src/app/commons/services/details/details.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { domain_url } from '../../constants/global.constants';

@Injectable({
providedIn: 'root'
Expand All @@ -11,7 +12,7 @@ export class DetailsService {
private http: HttpClient) { }

getThemeDetailsService(id){
return this.http.get<any>('http://localhost:8000/home/theme/details/'+id+'/', {headers: this.httpHeaders})
return this.http.get<any>('http://'+domain_url+':8000/home/theme/details/'+id+'/', {headers: this.httpHeaders})
.toPromise()
.then(
response =>{
Expand All @@ -26,7 +27,7 @@ export class DetailsService {
}

createReviewService(comment){
return this.http.post<any>("http://localhost:8000/details/createReview/",comment)
return this.http.post<any>("http://"+domain_url+":8000/details/createReview/",comment)
.toPromise()
.then(
response => {
Expand All @@ -39,4 +40,19 @@ export class DetailsService {
}
);
}

subscribeService(data){
return this.http.post<any>("http://"+domain_url+":8000/home/theme/subscribe/",data)
.toPromise()
.then(
response => {
return response;
}
)
.catch(
error => {
return error;
}
)
}
}
27 changes: 21 additions & 6 deletions assets/src/app/commons/services/home/home.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { domain_url, home_theme, home_category, home_subscribe} from '../../constants/global.constants';

@Injectable({
providedIn: 'root'
Expand All @@ -9,12 +10,10 @@ export class HomeService {

httpHeaders = new HttpHeaders({'Content-type': 'application/json'});
public categories;
constructor(private http: HttpClient) {
this.categories = this.getCategory();
}
constructor(private http: HttpClient) {}

getThemes(){
return this.http.get<any>("http://localhost:8000/home/theme/", {headers: this.httpHeaders})
getThemes(auth){
return this.http.get<any>("http://"+domain_url+":8000"+home_theme+auth+"/", {headers: this.httpHeaders})
.toPromise()
.then(
response => {
Expand All @@ -29,7 +28,23 @@ export class HomeService {
}

getCategory(){
return this.http.get<any>("http://localhost:8000/home/theme/category/", {headers: this.httpHeaders})
return this.http.get<any>("http://"+domain_url+":8000"+home_category, {headers: this.httpHeaders})
.toPromise()
.then(
response => {
return response;
}
)
.catch(
error => {
return error;
}
)
}

subscribeService(data){
console.log('clicked');
return this.http.post<any>("http://"+domain_url+":8000"+home_subscribe, data)
.toPromise()
.then(
response => {
Expand Down
1 change: 0 additions & 1 deletion assets/src/app/components/account/account.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ <h4 class="mb-5">
</div>
</div>
</div>

<span id="email-error" class="error-msg">{{ registrationForm.value.success }}</span>
<div class="col-md-4 offset-md-4">
<button class="btn btn-primary form-control mb-5" (click)="register()">Sign up</button>
Expand Down
Loading