New changes
This commit is contained in:
@@ -3,6 +3,8 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
|||||||
import { User } from '../_models';
|
import { User } from '../_models';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -22,4 +24,24 @@ export class AuthService {
|
|||||||
public get userValue(): User {
|
public get userValue(): User {
|
||||||
return this.userSubject.value;
|
return this.userSubject.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// API's
|
||||||
|
|
||||||
|
login(adminData: any) {
|
||||||
|
return this.http
|
||||||
|
.post<any>(`${environment.apiUrl}authorize/web-login/`, adminData)
|
||||||
|
.pipe(
|
||||||
|
map((user) => {
|
||||||
|
localStorage.removeItem('currentUser');
|
||||||
|
if (user && user.token) {
|
||||||
|
localStorage.setItem('currentUser', JSON.stringify(user));
|
||||||
|
localStorage.setItem('token', user.token.access);
|
||||||
|
this.userSubject.next(user);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { AuthService } from 'src/app/_services';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
@@ -10,7 +12,7 @@ export class LoginComponent implements OnInit {
|
|||||||
public loginForm!: FormGroup
|
public loginForm!: FormGroup
|
||||||
public submited: boolean = false
|
public submited: boolean = false
|
||||||
|
|
||||||
constructor(private formBuilder: FormBuilder) { }
|
constructor(private formBuilder: FormBuilder,private auth:AuthService, private router: Router) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.loginForm = this.formBuilder.group(
|
this.loginForm = this.formBuilder.group(
|
||||||
@@ -35,7 +37,22 @@ export class LoginComponent implements OnInit {
|
|||||||
this.submited = true;
|
this.submited = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const reqObj = {
|
||||||
|
userName: this.loginForm.value.username,
|
||||||
|
password: this.loginForm.value.password,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.auth.login(reqObj).subscribe(
|
||||||
|
(data: any) => {
|
||||||
|
this.router.navigateByUrl('/admin/dashboard');
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
localStorage.clear();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
import { ConfirmPasswordValidator } from 'src/app/_helper/matchpassword.validators';
|
import { ConfirmPasswordValidator } from 'src/app/_helper/matchpassword.validators';
|
||||||
|
import { AuthService } from 'src/app/_services';
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-sign-up',
|
selector: 'app-sign-up',
|
||||||
templateUrl: './sign-up.component.html',
|
templateUrl: './sign-up.component.html',
|
||||||
@@ -9,14 +11,13 @@ import { ConfirmPasswordValidator } from 'src/app/_helper/matchpassword.validato
|
|||||||
export class SignUpComponent implements OnInit {
|
export class SignUpComponent implements OnInit {
|
||||||
public signupForm!: FormGroup;
|
public signupForm!: FormGroup;
|
||||||
public submitted: boolean = false;
|
public submitted: boolean = false;
|
||||||
constructor(private formBuilder: FormBuilder) {}
|
constructor(private formBuilder: FormBuilder, private router: Router, private auth: AuthService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.signupForm = this.formBuilder.group(
|
this.signupForm = this.formBuilder.group(
|
||||||
{
|
{
|
||||||
fullname: ['', Validators.required],
|
fullname: ['', Validators.required],
|
||||||
imei: ['', Validators.required],
|
imei: ['', Validators.required],
|
||||||
email: ['', [Validators.required, Validators.email]],
|
|
||||||
password: [
|
password: [
|
||||||
'',
|
'',
|
||||||
[
|
[
|
||||||
@@ -42,5 +43,19 @@ export class SignUpComponent implements OnInit {
|
|||||||
this.submitted = true;
|
this.submitted = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const reqObj = {
|
||||||
|
fullName: this.signupForm.value.fullname,
|
||||||
|
imei: this.signupForm.value.imei,
|
||||||
|
password: this.signupForm.value.password,
|
||||||
|
confirmPassword : this.signupForm.value.confirmPassword,
|
||||||
|
};
|
||||||
|
this.auth.login(reqObj).subscribe(
|
||||||
|
(data: any) => {
|
||||||
|
this.router.navigateByUrl('/login');
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
localStorage.clear();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user