added login and registration components

This commit is contained in:
JakubWalkowiak 2020-12-16 21:40:37 +01:00
parent ece01494f4
commit 56eaec8920
13 changed files with 231 additions and 0 deletions

View 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>

View 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();
});
});

View 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(() => {
});
}
}

View 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>

View 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();
});
});

View 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(() => {
});
}
}

View File

@ -0,0 +1,6 @@
export interface User {
id?: number;
userName: string;
fullName: string;
password?: string;
}

View 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);
}
}

View 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 { }

View 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 { }

View File

@ -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'
} }
} }
}; };