added login and registration components
This commit is contained in:
parent
ece01494f4
commit
56eaec8920
18
src/app/user/components/login/login.component.html
Normal file
18
src/app/user/components/login/login.component.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<div class="login-form-container d-flex justify-content-center">
|
||||||
|
<form [formGroup]="loginForm" class="login-form d-flex flex-column mt-5">
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Username</mat-label>
|
||||||
|
<input matInput formControlName="userName" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Password</mat-label>
|
||||||
|
<input matInput formControlName="password" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<button (click)="onLoginUser()" class="btn btn-primary">Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
0
src/app/user/components/login/login.component.scss
Normal file
0
src/app/user/components/login/login.component.scss
Normal file
25
src/app/user/components/login/login.component.spec.ts
Normal file
25
src/app/user/components/login/login.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LoginComponent } from './login.component';
|
||||||
|
|
||||||
|
describe('LoginComponent', () => {
|
||||||
|
let component: LoginComponent;
|
||||||
|
let fixture: ComponentFixture<LoginComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ LoginComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(LoginComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
36
src/app/user/components/login/login.component.ts
Normal file
36
src/app/user/components/login/login.component.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormGroup, FormControl, Validators } from '@angular/forms';
|
||||||
|
import { UserService } from '../../services/user.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-login',
|
||||||
|
templateUrl: './login.component.html',
|
||||||
|
styleUrls: ['./login.component.scss']
|
||||||
|
})
|
||||||
|
export class LoginComponent implements OnInit {
|
||||||
|
|
||||||
|
loginForm: FormGroup;
|
||||||
|
|
||||||
|
constructor(private userSerice: UserService) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.loginForm = this.createLoginForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
createLoginForm(): FormGroup {
|
||||||
|
return new FormGroup({
|
||||||
|
userName: new FormControl('', Validators.required),
|
||||||
|
fullName: new FormControl('', Validators.required),
|
||||||
|
password: new FormControl('', Validators.required),
|
||||||
|
repeatedPassword: new FormControl('', Validators.required)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onRegisterUser(): void {
|
||||||
|
this.userSerice.login(this.loginForm.value).subscribe(() => {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
src/app/user/components/register/register.component.html
Normal file
29
src/app/user/components/register/register.component.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<div class="register-form-container d-flex justify-content-center">
|
||||||
|
<form [formGroup]="registerForm" class="register-form d-flex flex-column mt-5">
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Username</mat-label>
|
||||||
|
<input matInput formControlName="userName" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Full name</mat-label>
|
||||||
|
<input matInput formControlName="fullName" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Password</mat-label>
|
||||||
|
<input matInput formControlName="password" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Repeated password</mat-label>
|
||||||
|
<input matInput formControlName="repeatedPassword" />
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<button (click)="onRegisterUser()" class="btn btn-primary">Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
25
src/app/user/components/register/register.component.spec.ts
Normal file
25
src/app/user/components/register/register.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { RegisterComponent } from './register.component';
|
||||||
|
|
||||||
|
describe('RegisterComponent', () => {
|
||||||
|
let component: RegisterComponent;
|
||||||
|
let fixture: ComponentFixture<RegisterComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ RegisterComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(RegisterComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
36
src/app/user/components/register/register.component.ts
Normal file
36
src/app/user/components/register/register.component.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { UserService } from './../../services/user.service';
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormGroup, FormControl, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-register',
|
||||||
|
templateUrl: './register.component.html',
|
||||||
|
styleUrls: ['./register.component.scss']
|
||||||
|
})
|
||||||
|
export class RegisterComponent implements OnInit {
|
||||||
|
|
||||||
|
registerForm: FormGroup;
|
||||||
|
|
||||||
|
constructor(private userSerice: UserService) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.registerForm = this.createRegisterForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
createRegisterForm(): FormGroup {
|
||||||
|
return new FormGroup({
|
||||||
|
userName: new FormControl('', Validators.required),
|
||||||
|
fullName: new FormControl('', Validators.required),
|
||||||
|
password: new FormControl('', Validators.required),
|
||||||
|
repeatedPassword: new FormControl('', Validators.required)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onRegisterUser(): void {
|
||||||
|
this.userSerice.register(this.registerForm.value).subscribe(() => {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
src/app/user/interfaces/user.interface.ts
Normal file
6
src/app/user/interfaces/user.interface.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface User {
|
||||||
|
id?: number;
|
||||||
|
userName: string;
|
||||||
|
fullName: string;
|
||||||
|
password?: string;
|
||||||
|
}
|
22
src/app/user/services/user.service.ts
Normal file
22
src/app/user/services/user.service.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { environment } from './../../../environments/environment';
|
||||||
|
import { User } from './../interfaces/user.interface';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class UserService {
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
register(user: User): Observable<void> {
|
||||||
|
return this.http.post<void>(environment.host + environment.apiEndpoints.users.register, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
login(user: User): Observable<void> {
|
||||||
|
return this.http.post<void>(environment.host + environment.apiEndpoints.users.login, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/app/user/user-routing.module.ts
Normal file
16
src/app/user/user-routing.module.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { Routes, RouterModule } from '@angular/router';
|
||||||
|
import { LoginComponent } from './components/login/login.component';
|
||||||
|
import { RegisterComponent } from './components/register/register.component';
|
||||||
|
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{ path: '', component: LoginComponent },
|
||||||
|
{ path: 'register', component: RegisterComponent }
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [RouterModule.forChild(routes)],
|
||||||
|
exports: [RouterModule],
|
||||||
|
})
|
||||||
|
export class SubjectRoutingModule { }
|
14
src/app/user/user.module.ts
Normal file
14
src/app/user/user.module.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { RegisterComponent } from './components/register/register.component';
|
||||||
|
import { LoginComponent } from './components/login/login.component';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [RegisterComponent, LoginComponent],
|
||||||
|
imports: [
|
||||||
|
CommonModule
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class UserModule { }
|
@ -8,6 +8,10 @@ export const environment = {
|
|||||||
addDeletionRequest: 'api/subjectDeleteRequests/addDeletionRequest',
|
addDeletionRequest: 'api/subjectDeleteRequests/addDeletionRequest',
|
||||||
approveDeletion: 'api/subjectDeleteRequests/approveDeletion',
|
approveDeletion: 'api/subjectDeleteRequests/approveDeletion',
|
||||||
cancelDeletion: 'api/subjectDeleteRequests/cancelDeletion',
|
cancelDeletion: 'api/subjectDeleteRequests/cancelDeletion',
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
register: 'api/users/register',
|
||||||
|
login: 'api/users/login'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user