Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 76eb842a

Přidáno uživatelem Jakub Danek před více než 5 roky(ů)

re #29 crude login page

Zobrazit rozdíly:

webapp/src/app/app-routing.module.ts
5 5
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
6 6
import {EmployeeComponentGuard} from './auth/employee-component.guard';
7 7
import {DashboardComponentGuard} from './auth/dashboard-component.guard';
8
import {LoginComponent} from "./login/login.component";
8 9

  
9 10
const routes: Routes = [
10 11
  { path: 'employees', component: EmployeesListComponent, canActivate: [EmployeeComponentGuard], runGuardsAndResolvers: 'always'},
11 12
  { path: 'dashboard', component: DashboardComponent, canActivate: [DashboardComponentGuard], runGuardsAndResolvers: 'always'},
13
  {path: 'login', component: LoginComponent},
12 14
  { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
13 15
  { path: '**', component: PageNotFoundComponent }
14 16
];
webapp/src/app/app.module.ts
16 16
import {CommonModule} from '@angular/common';
17 17

  
18 18
import {BasicAuthInterceptor} from "./auth/basic-auth.interceptor";
19
import {LoginComponent} from "./login/login.component";
19 20

  
20 21
@NgModule({
21 22
  declarations: [
22 23
    AppComponent,
23 24
    MenuComponent,
24 25
    HeaderComponent,
25
    PageNotFoundComponent
26
    PageNotFoundComponent,
27
    LoginComponent
26 28
  ],
27 29
  imports: [
28 30
    BrowserModule,
webapp/src/app/auth/basic-auth.interceptor.ts
2 2
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
3 3
import {Observable} from 'rxjs';
4 4

  
5
import {ProfileService} from '../services/util/profile.service';
6

  
7 5
/**
8 6
 * Adds authentication token to each request.
9 7
 */
10 8
@Injectable()
11 9
export class BasicAuthInterceptor implements HttpInterceptor {
12
  constructor(private profileService: ProfileService) {
10
  constructor() {
13 11
  }
14 12

  
15 13
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
16
    // add authorization header with basic auth credentials if available
17
    const currentUser = window.btoa(this.profileService.currentUserValue + ":");
18
    if (currentUser) {
19
      request = request.clone({
20
        withCredentials: true,
21
        setHeaders: {
22
          authorization: `Basic ${currentUser}`
23
        }
24
      });
25
    }
14
    request = request.clone({
15
      withCredentials: true,
16
    });
26 17

  
27 18
    return next.handle(request);
28 19
  }
webapp/src/app/login/login.component.html
1
<div id="notfound">
2
  <div class="notfound">
3
    <h1>Sign-in</h1>
4

  
5
    <p>Please sign-in using one of the following methods: </p>
6
    <a href="http://localhost:9080/api/signin/google?target=http://localhost">Login with Google</a>
7
  </div>
8
</div>
9

  
webapp/src/app/login/login.component.ts
1
import {Component, OnInit} from '@angular/core';
2

  
3
@Component({
4
  selector: 'app-page-not-found',
5
  templateUrl: './login.component.html',
6
  styleUrls: ['./login.component.sass']
7
})
8
export class LoginComponent implements OnInit {
9

  
10
  constructor() {
11
  }
12

  
13
  ngOnInit() {
14
  }
15

  
16
}

Také k dispozici: Unified diff