refs #365 added interceptor
parent
c42a61bf3d
commit
eb19de4c4f
|
@ -10,7 +10,8 @@ import { HeaderComponent } from './components/layout/header/header.component';
|
|||
import { SidebarComponent } from './components/layout/sidebar/sidebar.component';
|
||||
import { LoginComponent } from './components/login/login.component';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
|
||||
import { CustomInterceptor } from './services/custom.interceptor';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -29,7 +30,13 @@ import { HttpClientModule } from '@angular/common/http';
|
|||
FormsModule,
|
||||
HttpClientModule
|
||||
],
|
||||
providers: [],
|
||||
providers: [
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: CustomInterceptor,
|
||||
multi:true
|
||||
}
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
:host{
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-areas:
|
||||
"sidebar header"
|
||||
"sidebar content"
|
||||
"sidebar footer";
|
||||
grid-template-columns: 120px 1fr;
|
||||
height: 100%;
|
||||
}
|
||||
.content-wrapper{
|
||||
display: block;
|
||||
background-color: gold;
|
||||
grid-area: content;
|
||||
}
|
|
@ -1 +1,7 @@
|
|||
<p>main-layout works!</p>
|
||||
<app-sidebar></app-sidebar>
|
||||
<app-header></app-header>
|
||||
<app-footer></app-footer>
|
||||
<div class="content-wrapper">
|
||||
<div class="content">
|
||||
<router-outlet />
|
||||
</div>
|
|
@ -3,11 +3,11 @@
|
|||
<form>
|
||||
<div>
|
||||
<label for="username">Username:</label>
|
||||
<input [(ngModel)]="loginObj.EmailId" type="text" id="username" name="EmailId" required>
|
||||
<input [(ngModel)]="loginObj.username" type="text" id="username" name="username" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="password">Password:</label>
|
||||
<input (ngModel)="loginObj.Password" type="password" id="password" name="Password" required>
|
||||
<input [(ngModel)]="loginObj.password" type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<button (click)="onLogin()">Login</button>
|
||||
</form>
|
||||
|
|
|
@ -11,11 +11,21 @@ import { Router } from '@angular/router';
|
|||
})
|
||||
export class LoginComponent {
|
||||
loginObj: any = {
|
||||
"EmailId": "",
|
||||
"Password": ""
|
||||
"username": "",
|
||||
"password": ""
|
||||
};
|
||||
constructor(private http: HttpClient) { }
|
||||
constructor(private http: HttpClient, private router: Router) { }
|
||||
|
||||
onLogin() {
|
||||
this.http.post('https://freeapi.gerasim.in/api/User/Login', this.loginObj).subscribe((res: any) => {})
|
||||
this.http.post('http://127.0.0.1:8080/auth/login', this.loginObj).subscribe((res: any) => {
|
||||
if(res.token){
|
||||
localStorage.setItem('loginToken', res.token);
|
||||
localStorage.setItem('refreshToken', res.refreshToken);
|
||||
this.router.navigateByUrl('/dashboard');
|
||||
}
|
||||
else(
|
||||
alert("invalid credentials")
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue