Skip to content

Commit

Permalink
add register
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdii909 committed Dec 8, 2022
1 parent 30259b8 commit dd51d62
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
34 changes: 5 additions & 29 deletions src/app/components/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
<div class="container-fluid">
<!-- Brand -->
<a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" routerLinkActive="active" [routerLink]="['/dashboard']">{{getTitle()}}</a>
<!-- Form -->
<form class="navbar-search navbar-search-dark form-inline mr-3 d-none d-md-flex ml-lg-auto">
<div class="form-group mb-0" [ngClass]="{ 'focused': focus === true }">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-search"></i></span>
</div>
<input class="form-control" placeholder="Search" type="text" (focus)="focus = true"
(blur)="focus = false">
</div>
</div>
</form>

<!-- User -->
<ul class="navbar-nav align-items-center d-none d-md-flex">
<li class="nav-item" ngbDropdown placement="bottom-right">
Expand All @@ -31,24 +20,11 @@
<div class=" dropdown-header noti-title">
<h6 class="text-overflow m-0">Welcome!</h6>
</div>
<a routerLinkActive="active" [routerLink]="['/user-profile']" class="dropdown-item">
<i class="ni ni-single-02"></i>
<span>My profile</span>
</a>
<a routerLinkActive="active" [routerLink]="['/user-profile']" class="dropdown-item">
<i class="ni ni-settings-gear-65"></i>
<span>Settings</span>
</a>
<a routerLinkActive="active" [routerLink]="['/user-profile']" class="dropdown-item">
<i class="ni ni-calendar-grid-58"></i>
<span>Activity</span>
</a>
<a routerLinkActive="active" [routerLink]="['/user-profile']" class="dropdown-item">
<i class="ni ni-support-16"></i>
<span>Support</span>
</a>



<div class="dropdown-divider"></div>
<a href="#!" class="dropdown-item">
<a routerLinkActive="active" [routerLink]="['/login']" class="dropdown-item">
<i class="ni ni-user-run"></i>
<span>Logout</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class NavbarComponent implements OnInit {
return this.listTitles[item].title;
}
}
return 'Dashboard';
return 'Login';
}

}
2 changes: 1 addition & 1 deletion src/app/pages/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="text-white">Bienvenue!</h1>
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-email-83"></i></span>
</div>
<input class="form-control" [(ngModel)]="form.email" name="email" placeholder="Email" type="text">
<input class="form-control" [(ngModel)]="form.email" name="email" placeholder="Email" type="email">
</div>
</div>
<div class="form-group">
Expand Down
8 changes: 4 additions & 4 deletions src/app/pages/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ <h1 class="text-white">Welcome!</h1>
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-hat-3"></i></span>
</div>
<input class="form-control" placeholder="Name" type="text">
<input class="form-control" [(ngModel)]="form.username" name="username" placeholder="Name" type="text">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-alternative mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-email-83"></i></span>
</div>
<input class="form-control" placeholder="Email" type="email">
<input class="form-control" placeholder="Email" [(ngModel)]="form.email" name="email" type="email">
</div>
</div>
<div class="form-group">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
</div>
<input class="form-control" placeholder="Password" type="password">
<input class="form-control" placeholder="Password" [(ngModel)]="form.password" name="password" type="password">
</div>
</div>
<div class="text-muted font-italic"><small>password strength: <span class="text-success font-weight-700">strong</span></small></div>
Expand All @@ -75,7 +75,7 @@ <h1 class="text-white">Welcome!</h1>
</div>
</div>
<div class="text-center">
<button type="button" class="btn btn-primary mt-4">Create account</button>
<button type="button" (click)="onSubmit()" class="btn btn-primary mt-4">Create account</button>
</div>
</form>
</div>
Expand Down
35 changes: 33 additions & 2 deletions src/app/pages/register/register.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from 'src/app/services/auth.service';

@Component({
selector: 'app-register',
Expand All @@ -7,9 +9,38 @@ import { Component, OnInit } from '@angular/core';
})
export class RegisterComponent implements OnInit {

constructor() { }
form: any = {
username: null,
email: null,
password: null
};
isSuccessful = false;
isSignUpFailed = false;
errorMessage = '';

ngOnInit() {
constructor(private authService: AuthService,private router:Router) { }

ngOnInit(): void {
}
onSubmit(): void {
const { username, email, password } = this.form;

this.authService.register(username, email, password).subscribe(
data => {
console.log(data);
this.isSuccessful = true;
this.isSignUpFailed = false;
console.log('ok');
this.router.navigate(['/login'] );
},
err => {
this.errorMessage = err.error.message;
this.isSignUpFailed = true;
}
);
}
}




2 changes: 2 additions & 0 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export class AuthService {
}

register(username: string, email: string, password: string): Observable<any> {
console.log(username,email,password);

return this.http.post(AUTH_API + 'register', {
username,
email,
Expand Down
5 changes: 4 additions & 1 deletion src/app/services/user.service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

const API_URL = 'http://localhost:8080/api/tsst/';
const API_URL = 'http://localhost:8080/api/auth/';

@Injectable({
providedIn: 'root'
Expand All @@ -17,6 +17,9 @@ export class UserService {
getUserBoard(): Observable<any> {
return this.http.get(API_URL + 'user', { responseType: 'text' });
}
getUser(): Observable<any> {
return this.http.get(API_URL + 'login', { responseType: 'text' });
}

getModeratorBoard(): Observable<any> {
return this.http.get(API_URL + 'mod', { responseType: 'text' });
Expand Down

0 comments on commit dd51d62

Please sign in to comment.