diff options
Diffstat (limited to 'frontend')
14 files changed, 308 insertions, 339 deletions
diff --git a/frontend/angular.json b/frontend/angular.json index bbbe3eaa..14028ae5 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -31,7 +31,7 @@ "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css" ], - "scripts": ["node_modules/bootstrap/dist/js/bootstrap.min.js"] + "scripts": ["node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"] }, "configurations": { "production": { diff --git a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts index 843a5709..cde3e8b1 100644 --- a/frontend/src/app/_elements/dataset-load/dataset-load.component.ts +++ b/frontend/src/app/_elements/dataset-load/dataset-load.component.ts @@ -38,7 +38,7 @@ export class DatasetLoadComponent { this.ngxCsvParser.parse(this.files[0], { header: false, delimiter: (this.delimiter == "razmak") ? " " : (this.delimiter == "") ? "," : this.delimiter}) .pipe().subscribe((result) => { - //console.log('Result', result); + console.log('Result', result); if (result.constructor === Array) { this.csvRecords = result; if (this.hasHeader) diff --git a/frontend/src/app/_modals/login-modal/login-modal.component.html b/frontend/src/app/_modals/login-modal/login-modal.component.html index 22f50de2..eb6f0c53 100644 --- a/frontend/src/app/_modals/login-modal/login-modal.component.html +++ b/frontend/src/app/_modals/login-modal/login-modal.component.html @@ -1,14 +1,9 @@ -<!-- Button trigger modal, OVO JE U STVARI DUGME U NAVBARU --> -<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalForLogin" (click)="openModal()"> - Otvori login modal -</button> - <!-- Modal --> <div class="modal fade" id="modalForLogin" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered"> <div class="modal-content"> <div class="modal-header bg-info"> - <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" (click)="resetData()"></button> </div> <div class="modal-body px-5" style="color:#003459"> <h1 class="text-center mt-2 mb-4">Prijavite se</h1> @@ -33,17 +28,15 @@ </form> <div class="col-md-12 d-flex justify-content-center"> <button type="button" class="btn btn-lg btn-info" style="color:white; border-color: #00a8e8; margin-right: 10px;" (click)="doLogin()">Prijavite se</button> - <button type="button" class="btn btn-lg btn-outline-secondary" data-bs-dismiss="modal">Odustanite</button> + <button type="button" class="btn btn-lg btn-outline-secondary" data-bs-dismiss="modal" (click)="resetData()">Odustanite</button> </div> <br> </div> <div class="modal-footer justify-content-center"> <p class="small fw-bold">Još uvek nemate nalog? - <a routerLink="/register" class="link-danger">Registrujte se</a> + <a data-bs-toggle="modal" data-bs-target="#modalForRegister" class="link-danger">Registrujte se</a> </p> </div> </div> </div> -</div> - - +</div>
\ No newline at end of file diff --git a/frontend/src/app/_modals/login-modal/login-modal.component.ts b/frontend/src/app/_modals/login-modal/login-modal.component.ts index 3a6fd8f1..3ee2c7fe 100644 --- a/frontend/src/app/_modals/login-modal/login-modal.component.ts +++ b/frontend/src/app/_modals/login-modal/login-modal.component.ts @@ -1,11 +1,7 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { CookieService } from 'ngx-cookie-service'; import { AuthService } from 'src/app/_services/auth.service'; -import { ElementRef } from '@angular/core'; - -declare var window: any; @Component({ selector: 'app-login-modal', @@ -27,25 +23,21 @@ export class LoginModalComponent implements OnInit { ) { } ngOnInit(): void { - this.loginModal = new window.bootstrap.Modal( - document.getElementById("modalForLogin") - ); } - openModal() { - this.loginModal.show(); - //console.log("ok"); - //(<HTMLInputElement>document.getElementById("exampleModal")).style.display = "block"; - } doLogin() { this.authService.login(this.username, this.password).subscribe((response) => { //ako nisu ok podaci, ne ide hide nego mora opet da ukucava!!!!podesi console.log(response); this.cookie.set('token', response); + this.resetData(); //dodato this.loginModal.hide(); //dodato this.router.navigate(['add-model']); + }, error => { + console.warn(error); //NETACNI PODACI }); } - sendToRegister() { - + resetData() { + this.username = ''; + this.password = ''; } } diff --git a/frontend/src/app/_modals/register-modal/register-modal.component.css b/frontend/src/app/_modals/register-modal/register-modal.component.css new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/frontend/src/app/_modals/register-modal/register-modal.component.css diff --git a/frontend/src/app/_modals/register-modal/register-modal.component.html b/frontend/src/app/_modals/register-modal/register-modal.component.html new file mode 100644 index 00000000..d20b199f --- /dev/null +++ b/frontend/src/app/_modals/register-modal/register-modal.component.html @@ -0,0 +1,85 @@ +<!-- Modal --> +<div class="modal fade" id="modalForRegister" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> +<div class="modal-dialog modal-dialog-centered modal-dialog modal-lg"> + <div class="modal-content"> + <div class="modal-header bg-info"> + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" (click)="resetData()"></button> + </div> + <div class="modal-body" style="color:#003459"> + <h1 class="text-center mt-2 mb-4">Registracija</h1> + + <form class="mx-5"> + <!--Ime--> + <div class="row"> + <div class="col-6 px-3 py-3"> + <label class="form-label" for="firstName">Ime</label> + <input type="text" id="firstName" class="form-control" [(ngModel)]="firstName" name="firstName" placeholder="Unesite ime..."> + <p *ngIf="wrongFirstNameBool" class="small fw-bold text-danger">Unesite ispravno ime. (minimum 1, maksimum 30 karaktera)</p> + <!--<small *ngIf="wrongFirstNameBool" class="form-text text-muted">Unesite ispravno ime</small> + <small class="form-text text-muted" [ngClass]="{wrongFirstNameBool} ? 'notCorrect' : 'correct'">Ispravno uneto ime</small>--> + </div> + <!--Prezime--> + <div class="col-6 px-3 py-3"> + <label class="form-label" for="lastName">Prezime</label> + <input type="text" id="lastName" class="form-control" [(ngModel)]="lastName" name="lastName" placeholder="Unesite prezime..."/> + <p *ngIf="wrongLastNameBool" class="small fw-bold text-danger">Unesite ispravno prezime. (minimum 1, maksimum 30 karaktera)</p> + </div> + </div> + <div class="row"> + <!--Korisnicko ime--> + <div class="col-12 px-3 py-3"> + <label class="form-label" for="username">Korisničko ime</label> + <input type="text" id="username" class="form-control" [(ngModel)]="username" name="username" placeholder="Unesite korisničko ime..."/> + <p *ngIf="wrongUsernameBool" class="small fw-bold text-danger">Unesite ispravno korisničko ime.</p> + </div> + </div> + <div class="row"> + <!--Email--> + <div class="col-12 px-3 py-3"> + <label class="form-label" for="email">E-mail adresa</label> + <input type="email" id="email" class="form-control" [(ngModel)]="email" name="email" placeholder="Unesite email adresu..."/> + <p *ngIf="wrongEmailBool" class="small fw-bold text-danger">Unesite ispravnu e-mail adresu.</p> + </div> + </div> + <div class="row"> + <!-- Lozinka 1. --> + <div class="col-6 px-3 py-3"> + <label class="form-label" for="pass1">Lozinka</label> + <input type="password" id="pass1" class="form-control" [(ngModel)]="pass1" name="pass1" placeholder="Unesite lozinku..."/> + <p *ngIf="wrongPass1Bool" class="small fw-bold text-danger">Lozinka se mora sastojati od najmanje 6 karaktera.</p> + </div> + <!-- Lozinka 2. --> + <div class="col-6 px-3 py-3"> + <label class="form-label" for="pass2">Potvrdite lozinku</label> + <input type="password" id="pass2" class="form-control" [(ngModel)]="pass2" name="pass2" placeholder="Ponovite lozinku..."/> + <p *ngIf="wrongPass2Bool" class="small fw-bold text-danger">Lozinke se ne podudaraju.</p> + </div> + </div> + </form> + <div class="col-md-12 d-flex justify-content-center mt-5"> + <button type="button" class="btn btn-lg btn-info" style="color:white; border-color: #00a8e8; margin-right: 10px;" (click)="doRegister()">Registracija</button> + <button type="button" class="btn btn-lg btn-outline-secondary" style="margin-left: 15px;" data-bs-dismiss="modal" (click)="resetData()">Odustanite</button> + </div> + <br> + </div> + <div class="modal-footer justify-content-center"> + <p class="small fw-bold">Već imate kreiran nalog? + <a data-bs-toggle="modal" data-bs-target="#modalForLogin" class="link-danger">Prijavite se</a> + </p> + </div> + </div> +</div> +</div> + +<style> +.correct { + content: "✔️"; + margin: 5px; + color: green; +} +.notCorrect { + content: "✕"; + margin: 5px; + color: red; +} +</style>
\ No newline at end of file diff --git a/frontend/src/app/_modals/register-modal/register-modal.component.spec.ts b/frontend/src/app/_modals/register-modal/register-modal.component.spec.ts new file mode 100644 index 00000000..e371b3d8 --- /dev/null +++ b/frontend/src/app/_modals/register-modal/register-modal.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RegisterModalComponent } from './register-modal.component'; + +describe('RegisterModalComponent', () => { + let component: RegisterModalComponent; + let fixture: ComponentFixture<RegisterModalComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ RegisterModalComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(RegisterModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/_modals/register-modal/register-modal.component.ts b/frontend/src/app/_modals/register-modal/register-modal.component.ts new file mode 100644 index 00000000..d86345b5 --- /dev/null +++ b/frontend/src/app/_modals/register-modal/register-modal.component.ts @@ -0,0 +1,166 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { AuthService } from 'src/app/_services/auth.service'; + +declare var window: any; + +@Component({ + selector: 'app-register-modal', + templateUrl: './register-modal.component.html', + styleUrls: ['./register-modal.component.css'] +}) +export class RegisterModalComponent implements OnInit { + + registerModal: any; + + firstName: string = ''; + lastName: string = ''; + username: string = ''; + email: string = ''; + pass1: string = ''; + pass2: string = ''; + + wrongFirstNameBool: boolean = false; + wrongLastNameBool: boolean = false; + wrongUsernameBool: boolean = false; + wrongEmailBool: boolean = false; + wrongPass1Bool: boolean = false; + wrongPass2Bool: boolean = false; + + pattName: RegExp = /^[a-zA-ZšŠđĐčČćĆžŽ]+([ \-][a-zA-ZšŠđĐčČćĆžŽ]+)*$/; + pattUsername: RegExp = /^[a-zA-Z0-9](_(?!(\.|_))|\.(?!(_|\.))|[a-zA-Z0-9]){6,18}[a-zA-Z0-9]$/; + pattTwoSpaces: RegExp = / /; + pattEmail: RegExp = /^[a-zA-Z0-9]+([\.\-\+][a-zA-Z0-9]+)*\@([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}$/; + pattPassword: RegExp = /.{6,30}$/; + + constructor( + private router: Router, + private authService: AuthService + ) { } + + ngOnInit(): void { + this.registerModal = new window.bootstrap.Modal( + document.getElementById("modalForRegister") + ); + } + + openModal() { + this.registerModal.show(); + } + doRegister() { + this.validation(); + } + resetData() { + this.firstName = this.lastName = this.username = this.email = this.pass1 = this.pass2 = ''; + this.wrongFirstNameBool = this.wrongLastNameBool = this.wrongUsernameBool = this.wrongEmailBool = this.wrongPass1Bool = this.wrongPass2Bool = false; + } + + isCorrectName(element: string): boolean { + if (this.pattName.test(element) && !(this.pattTwoSpaces.test(element)) && (element.length >= 1 && element.length <= 30)) + return true; + return false; + } + isCorrectUsername(element: string) : boolean { + if (this.pattUsername.test(element) && !(this.pattTwoSpaces.test(element)) && (element.length >= 1 && element.length <= 30)) + return true; + return false; + } + isCorrectEmail(element: string): boolean { + if (this.pattEmail.test(element.toLowerCase()) && element.length <= 320) + return true; + return false; + } + isCorrectPassword(element: string): boolean { + if (this.pattPassword.test(element)) + return true; + return false; + } + + firstNameValidation() { + if (this.isCorrectName(this.firstName) == true) { + this.wrongFirstNameBool = false; + return; + } + (<HTMLSelectElement>document.getElementById('firstName')).focus(); + this.wrongFirstNameBool = true; + } + lastNameValidation() { + if (this.isCorrectName(this.lastName) == true) { + this.wrongLastNameBool = false; + return; + } + (<HTMLSelectElement>document.getElementById('lastName')).focus(); + this.wrongLastNameBool = true; + } + usernameValidation() { + if (this.isCorrectUsername(this.username) == true) { + this.wrongUsernameBool = false; + return; + } + (<HTMLSelectElement>document.getElementById('username')).focus(); + this.wrongUsernameBool = true; + } + emailValidation() { + if (this.isCorrectEmail(this.email) == true) { + this.wrongEmailBool = false; + return; + } + (<HTMLSelectElement>document.getElementById('email')).focus(); + this.wrongEmailBool = true; + } + passwordValidation() { + if (this.isCorrectPassword(this.pass1) && this.isCorrectPassword(this.pass2) && this.pass1 == this.pass2) { + this.wrongPass1Bool = false; + this.wrongPass2Bool = false; + return; + } + this.pass1 = ''; //brisi obe ukucane lozinke + this.pass2 = ''; + (<HTMLSelectElement>document.getElementById('pass1')).focus(); + this.wrongPass1Bool = true; + this.wrongPass2Bool = true; + } + + validation() { + this.firstName = this.firstName.trim(); + this.lastName = this.lastName.trim(); + this.username = this.username.trim(); + this.email = this.email.trim(); + + this.firstNameValidation(); + this.lastNameValidation(); + this.usernameValidation(); + this.emailValidation(); + this.passwordValidation(); + + if (!(this.wrongFirstNameBool || this.wrongLastNameBool || this.wrongUsernameBool || + this.wrongEmailBool || this.wrongPass1Bool || this.wrongPass2Bool)) { //sve ok, registruj ga + + let user = { + firstName: this.firstName, + lastName: this.lastName, + username: this.username, + password: this.pass1, + email: this.email + } + + this.authService.register(user) + .subscribe( + (response) => { + console.log(response); + if (response === 'User added') { + this.resetData(); //DODATO + this.registerModal.hide(); //dodato + this.router.navigate(['/login']); //registracija uspesna, idi na LOGIN MODAL, SREDITI + } + else if (response === 'Email Already Exists') + alert('Nalog sa unetim email-om već postoji!'); + else if (response === 'Username Already Exists') + alert('Nalog sa unetim korisnićkim imenom već postoji!'); + } + ); + } + } + + +} diff --git a/frontend/src/app/_pages/login-page/login-page.component.html b/frontend/src/app/_pages/login-page/login-page.component.html index 8deb5290..3a4244fc 100644 --- a/frontend/src/app/_pages/login-page/login-page.component.html +++ b/frontend/src/app/_pages/login-page/login-page.component.html @@ -1,55 +1,13 @@ -<!--<script> - $(document).ready(function(){ - $(".btn").click(function(){ - $("#exampleModal").modal('show'); - }); - - $('#exampleModal').modal({ - backdrop: 'static', - keyboard: false - }); - }); -</script>--> - -<!-- Button trigger modal --> -<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalForLogin" (click)="openModal()"> - Open Modal - </button> - -<!-- -<div style="min-height: 100vh; position: relative;"> - - <div class="container p-5 rounded-3 shadow-sm border" style="max-width: 50em; margin-top: 50px;"> - <h3 class="text-center pb-5">Prijavite se</h3> - <form> - <div class="form-outline mb-4"> - <label class="form-label" for="username">Korisničko ime</label> - <input [(ngModel)]="username" name="username" type="text" id="username" - class="form-control form-control-lg" placeholder="Unesite korisničko ime..." /> - </div> - - <div class="form-outline mb-3"> - <label class="form-label" for="password">Lozinka</label> - <input [(ngModel)]="password" name="password" type="password" id="password" - class="form-control form-control-lg" placeholder="Unesite lozinku..." /> - </div> - - <div class="text-center text-lg-start mt-4 pt-2"> - <p *ngIf="wrongCreds" class="small fw-bold mt-2 pt-1 mb-0 text-danger">Lozinka ili e-mail su pogrešni - </p> - <br> - - <button type="button" class="btn btn-primary btn-lg" - style="padding-left: 2.5rem; padding-right: 2.5rem;" (click)="onSubmit()">Prijava - </button> - - <br> - <p class="small fw-bold mt-2 pt-1 mb-0">Još uvek nemate nalog? - <a routerLink="/register" class="link-danger">Registrujte se</a> - </p> - </div> - </form> - </div> - -</div> --->
\ No newline at end of file +<!-- Button trigger modal, OVO JE U STVARI DUGME U NAVBARU --> +<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalForLogin"> + Otvori login modal +</button> + +<!-- Button trigger modal, OVO JE U STVARI DUGME U NAVBARU --> +<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalForRegister"> + Otvori register modal +</button> + + +<app-login-modal></app-login-modal> +<app-register-modal></app-register-modal> diff --git a/frontend/src/app/_pages/login-page/login-page.component.ts b/frontend/src/app/_pages/login-page/login-page.component.ts index e5366283..23ce4df0 100644 --- a/frontend/src/app/_pages/login-page/login-page.component.ts +++ b/frontend/src/app/_pages/login-page/login-page.component.ts @@ -1,10 +1,5 @@ -import { Component, OnInit } from '@angular/core'; -import { Router } from '@angular/router'; -import { CookieService } from 'ngx-cookie-service'; -import { AuthService } from 'src/app/_services/auth.service'; +import { Component } from '@angular/core'; -import { LoginModalComponent } from 'src/app/_modals/login-modal/login-modal.component'; -import { MDBModalRef, MDBModalService } from 'ng-uikit-pro-standard'; declare var window: any; @@ -17,47 +12,4 @@ declare var window: any; }) export class LoginPageComponent{ - modalRef?: MDBModalRef; - - //email: string = ''; - username: string = ''; - password: string = ''; - - public wrongCreds: boolean = false; //RAZMOTRITI - //public notApproved: boolean = false; //RAZMOTRITI - - formModal: any; - - constructor( - private authService: AuthService, - private cookie: CookieService, - private router: Router, - private modalService: MDBModalService - ) { } - - openModal() { - //this.modalRef = this.modalService.show(LoginModalComponent); - } - /* - ngOnInit(): void { - this.formModal = new window.bootstrap.Modal( - document.getElementById("exampleModal") - ); - } - - openModal() { - this.formModal.show(); - //console.log("ok"); - //(<HTMLInputElement>document.getElementById("exampleModal")).style.display = "block"; - } - - onSubmit() { - - this.authService.login(this.username, this.password).subscribe((response) => { - console.log(response); - this.cookie.set('token', response); - this.router.navigate(['add-model']); - }); - } -*/ } diff --git a/frontend/src/app/_pages/register-page/register-page.component.html b/frontend/src/app/_pages/register-page/register-page.component.html index f8ae046e..e69de29b 100644 --- a/frontend/src/app/_pages/register-page/register-page.component.html +++ b/frontend/src/app/_pages/register-page/register-page.component.html @@ -1,80 +0,0 @@ -<div style="min-height: 100vh; position: relative;"> - - <!-- TODO <app-navbar [activeNav]="'register'"></app-navbar>--> - - <div class="container" style="margin-top: 50px;"> - <div class="text-black"> - <div class="row justify-content-center"> - <div class="col-8 bg-white border rounded-3 shadow-sm p-5"> - <p class="text-center h2 fw-bold mb-5 mx-1 mx-md-4">Registracija</p> - - <form class="mx-1 mx-md-4"> - <!--Ime--> - <div class="row"> - <div class="col-6 p-2"> - <label class="form-label" for="firstName">Ime</label> - <input type="text" id="firstName" class="form-control" [(ngModel)]="firstName" name="firstName"> - <p *ngIf="wrongFirstNameBool" class="small fw-bold text-danger">Unesite ispravno ime. (minimum 1, maksimum 30 karaktera)</p> - </div> - <!--Prezime--> - <div class="col-6 p-2"> - <label class="form-label" for="lastName">Prezime</label> - <input type="text" id="lastName" class="form-control" [(ngModel)]="lastName" name="lastName" /> - <p *ngIf="wrongLastNameBool" class="small fw-bold text-danger">Unesite ispravno prezime. (minimum 1, maksimum 30 karaktera)</p> - </div> - </div> - <br> - - <div class="row"> - <!--Korisnicko ime--> - <div class="col-6 p-2"> - <label class="form-label" for="nickName">Korisničko ime</label> - <input type="text" id="nickName" class="form-control" [(ngModel)]="nickName" name="nickName" /> - <p *ngIf="wrongNickNameBool" class="small fw-bold text-danger">Unesite ispravno korisničko ime.</p> - </div> - <!--Email--> - <div class="col-6 p-2"> - <label class="form-label" for="email">E-mail adresa</label> - <input type="email" id="email" class="form-control" [(ngModel)]="email" name="email" /> - <p *ngIf="wrongEmailBool" class="small fw-bold text-danger">Unesite ispravnu e-mail adresu.</p> - </div> - </div> - <br> - - <div class="row"> - <!-- Lozinka 1. --> - <div class="col-6 p-2"> - <label class="form-label" for="pass1">Lozinka</label> - <input type="password" id="pass1" class="form-control" [(ngModel)]="pass1" name="pass1" /> - <p *ngIf="wrongPass1Bool" class="small fw-bold text-danger">Lozinka se mora sastojati od najmanje 6 karaktera.</p> - </div> - - <!-- Lozinka 2. --> - <div class="col-6 p-2"> - <label class="form-label" for="pass2">Potvrdite lozinku</label> - <input type="password" id="pass2" class="form-control" [(ngModel)]="pass2" name="pass2" /> - <p *ngIf="wrongPass2Bool" class="small fw-bold text-danger">Lozinke se ne podudaraju.</p> - </div> - </div> - - <br><br><br> - <!--Dugme Registruj se--> - <div class="d-flex justify-content-center mx-4 mb-3 mb-lg-4"> - <button type="button" class="btn btn-primary btn-lg" (click)="validation()">Registrujte se</button> - </div> - - <div class="form-check d-flex justify-content-center mb-5"> - <label class="form-check-label" class="small fw-bold mt-2 pt-1 mb-0" for="form2Example3"> - Već imate kreiran nalog? - <a routerLink="/login" class="link-danger">Prijavite se</a> - </label> - </div> - </form> - </div> - </div> - </div> - </div> - - <!-- TODO <app-footer></app-footer> --> - -</div>
\ No newline at end of file diff --git a/frontend/src/app/_pages/register-page/register-page.component.ts b/frontend/src/app/_pages/register-page/register-page.component.ts index 712fc55e..3add63a4 100644 --- a/frontend/src/app/_pages/register-page/register-page.component.ts +++ b/frontend/src/app/_pages/register-page/register-page.component.ts @@ -8,133 +8,7 @@ import { AuthService } from 'src/app/_services/auth.service'; styleUrls: ['./register-page.component.css'] }) export class RegisterPageComponent implements OnInit { - firstName: string = ''; - lastName: string = ''; - nickName: string = ''; - email: string = ''; - pass1: string = ''; - pass2: string = ''; - - wrongFirstNameBool: boolean = false; - wrongLastNameBool: boolean = false; - wrongNickNameBool: boolean = false; - wrongEmailBool: boolean = false; - wrongPass1Bool: boolean = false; - wrongPass2Bool: boolean = false; - - pattName: RegExp = /^[a-zA-ZšŠđĐčČćĆžŽ]+([ \-][a-zA-ZšŠđĐčČćĆžŽ]+)*$/; - pattTwoSpaces: RegExp = / /; - pattEmail: RegExp = /^[a-zA-Z0-9]+([\.\-\+][a-zA-Z0-9]+)*\@([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}$/; - pattPassword: RegExp = /.{6,30}$/; - - constructor( - private router: Router, - private authService: AuthService, - ) { } ngOnInit(): void { } - - isCorrectName(element: string): boolean { - if (this.pattName.test(element) && !(this.pattTwoSpaces.test(element)) && (element.length >= 1 && element.length <= 30)) - return true; - return false; - } - isCorrectEmail(element: string): boolean { - if (this.pattEmail.test(element.toLowerCase()) && element.length <= 320) - return true; - return false; - } - isCorrectPassword(element: string): boolean { - if (this.pattPassword.test(element)) - return true; - return false; - } - - firstNameValidation() { - if (this.isCorrectName(this.firstName) == true) { - this.wrongFirstNameBool = false; - return; - } - (<HTMLSelectElement>document.getElementById('firstName')).focus(); - this.wrongFirstNameBool = true; - } - lastNameValidation() { - if (this.isCorrectName(this.lastName) == true) { - this.wrongLastNameBool = false; - return; - } - (<HTMLSelectElement>document.getElementById('lastName')).focus(); - this.wrongLastNameBool = true; - } - nickNameValidation() { - if (this.isCorrectName(this.nickName) == true) { - this.wrongNickNameBool = false; - return; - } - (<HTMLSelectElement>document.getElementById('nickName')).focus(); - this.wrongNickNameBool = true; - } - emailValidation() { - if (this.isCorrectEmail(this.email) == true) { - this.wrongEmailBool = false; - return; - } - (<HTMLSelectElement>document.getElementById('email')).focus(); - this.wrongEmailBool = true; - } - passwordValidation() { - if (this.isCorrectPassword(this.pass1) && this.isCorrectPassword(this.pass2) && this.pass1 == this.pass2) { - this.wrongPass1Bool = false; - this.wrongPass2Bool = false; - return; - } - this.pass1 = ''; //brisi obe ukucane lozinke - this.pass2 = ''; - (<HTMLSelectElement>document.getElementById('pass1')).focus(); - this.wrongPass1Bool = true; - this.wrongPass2Bool = true; - } - - validation() { - this.firstName = this.firstName.trim(); - this.lastName = this.lastName.trim(); - this.nickName = this.nickName.trim(); - this.email = this.email.trim(); - - this.firstNameValidation(); - this.lastNameValidation(); - //this.nickNameValidation(); - this.emailValidation(); - this.passwordValidation(); - - if (!(this.wrongFirstNameBool || this.wrongLastNameBool || this.wrongNickNameBool || - this.wrongEmailBool || this.wrongPass1Bool || this.wrongPass2Bool)) { //sve ok, registruj ga - - let user = { - firstName: this.firstName, - lastName: this.lastName, - username: this.nickName, - password: this.pass1, - email: this.email - } - - this.authService.register(user) - .subscribe( - (response) => { - console.log(response); - if (response === 'User added') - this.router.navigate(['/login']); //registracija uspesna, idi na login - else if (response === 'Email Already Exists') - alert('Nalog sa unetim email-om već postoji!'); - else if (response === 'Username Already Exists') - alert('Nalog sa unetim korisnićkim imenom već postoji!'); - } - ); - } - } - - - - } diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index cd86ef5c..d053a9a5 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -7,6 +7,7 @@ import { OnlyAuthorizedComponent } from './_pages/only-authorized/only-authorize import { RegisterPageComponent } from './_pages/register-page/register-page.component'; import { AddModelComponent } from './_pages/add-model/add-model.component'; import { LoginModalComponent } from './_modals/login-modal/login-modal.component'; +import { RegisterModalComponent } from './_modals/register-modal/register-modal.component'; const routes: Routes = [ { path: '', redirectTo: '/login', pathMatch: 'full' }, @@ -14,7 +15,8 @@ const routes: Routes = [ { path: 'register', component: RegisterPageComponent }, { path: 'only-authorized', component: OnlyAuthorizedComponent, canActivate: [AuthGuardService] }, { path: 'add-model', component: AddModelComponent }, - { path: 'login-modal-test', component: LoginModalComponent } + { path: 'login-modal-test', component: LoginModalComponent }, + { path: 'register-modal-test', component: RegisterModalComponent } ]; @NgModule({ diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index d95252ad..553ff513 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -13,6 +13,7 @@ import { DatasetLoadComponent } from './_elements/dataset-load/dataset-load.comp import { AddModelComponent } from './_pages/add-model/add-model.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { LoginModalComponent } from './_modals/login-modal/login-modal.component'; +import { RegisterModalComponent } from './_modals/register-modal/register-modal.component'; import { MaterialModule } from './material.module'; import { ReactiveFormsModule } from '@angular/forms'; @@ -25,7 +26,8 @@ import { ReactiveFormsModule } from '@angular/forms'; OnlyAuthorizedComponent, DatasetLoadComponent, AddModelComponent, - LoginModalComponent + LoginModalComponent, + RegisterModalComponent ], imports: [ BrowserModule, |