Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
11 changes: 0 additions & 11 deletions devday/src/app/app-routing.module.ts

This file was deleted.

38 changes: 18 additions & 20 deletions devday/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
</li>
</ul>
<!-- nav -->
<nav class="navbar navbar-expand navbar-dark bg-dark" *ngIf="currentUser">
<div class="navbar-nav">
<a class="nav-item nav-link" routerLink="/">Home</a>
<a class="nav-item nav-link" (click)="logout()">Logout</a>
</div>
</nav>

<router-outlet></router-outlet>
<!-- main app container -->
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-sm-6 offset-sm-3">
<alert></alert>
<router-outlet></router-outlet>
</div>
</div>
</div>
</div>
22 changes: 16 additions & 6 deletions devday/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { User } from './models/user';
import { AuthenticationService } from './services/authentication.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})


@Component({ selector: 'app', templateUrl: 'app.component.html' })
export class AppComponent {
title = 'devday';
currentUser: User;

constructor(private router: Router, private authenticationService: AuthenticationService) {
this.authenticationService.currentUser.subscribe(x => (this.currentUser = x));
}

logout() {
this.authenticationService.logout();
this.router.navigate(['/login']);
}
}
39 changes: 26 additions & 13 deletions devday/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';

// used to create fake backend
import { fakeBackendProvider } from './shared/helper/fake-backend';

import { JwtInterceptor } from './shared/helper/jwt.interceptor';
import { ErrorInterceptor } from './shared/helper/error.interceptor';

import { appRoutingModule } from './routing/app.routing';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { HomeComponent } from './pages/home/home.component';
import { LoginComponent } from './modules/login/components/login/login.component';
import { RegisterComponent } from './pages/register/register.component';
import { AlertComponent } from './modules/alert/components/alert/alert.component';



@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
imports: [BrowserModule, ReactiveFormsModule, HttpClientModule, appRoutingModule],
declarations: [AppComponent, HomeComponent, LoginComponent, RegisterComponent, AlertComponent],
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },

// provider used to create fake backend
fakeBackendProvider
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {}
6 changes: 6 additions & 0 deletions devday/src/app/models/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class User {
id: number;
email: string;
password: string;
token: string;
}
13 changes: 13 additions & 0 deletions devday/src/app/modules/alert/alert.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AlertComponent } from './components/alert/alert.component';



@NgModule({
declarations: [AlertComponent],
imports: [
CommonModule
]
})
export class AlertModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div *ngIf="message" [ngClass]="message.cssClass">{{ message.text }}</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { AlertComponent } from './alert.component';

describe('AlertComponent', () => {
let component: AlertComponent;
let fixture: ComponentFixture<AlertComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AlertComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AlertComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
32 changes: 32 additions & 0 deletions devday/src/app/modules/alert/components/alert/alert.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { AlertService } from 'src/app/services/alert.service';


@Component({ selector: 'alert', templateUrl: 'alert.component.html' })
export class AlertComponent implements OnInit, OnDestroy {
private subscription: Subscription;
message: any;

constructor(private alertService: AlertService) { }

ngOnInit() {
this.subscription = this.alertService.getAlert()
.subscribe(message => {
switch (message && message.type) {
case 'success':
message.cssClass = 'alert alert-success';
break;
case 'error':
message.cssClass = 'alert alert-danger';
break;
}

this.message = message;
});
}

ngOnDestroy() {
this.subscription.unsubscribe();
}
}
34 changes: 34 additions & 0 deletions devday/src/app/modules/login/components/login/login.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<h2>Anmelden</h2>
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="email">E-Mail</label>
<input
type="text"
formControlName="email"
class="form-control"
[ngClass]="{ 'is-invalid': submitted && f.email.errors }"
/>
<div *ngIf="submitted && f.email.errors" class="invalid-feedback">
<div *ngIf="f.email.errors.required">E-Mail ist erforderlich</div>
</div>
</div>
<div class="form-group">
<label for="password">Passwort</label>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generate components for inputs where label is only shown when a label is given by input. Input type, state (readonly ...) should be configurable too.

<input
type="password"
formControlName="password"
class="form-control"
[ngClass]="{ 'is-invalid': submitted && f.password.errors }"
/>
<div *ngIf="submitted && f.password.errors" class="invalid-feedback">
<div *ngIf="f.password.errors.required">Passwort ist erforderlich</div>
</div>
</div>
<div class="form-group">
<button [disabled]="loading" class="btn btn-primary">
<span *ngIf="loading" class="spinner-border spinner-border-sm mr-1"></span>
Anmelden
</button>
<a routerLink="/register" class="btn btn-link">Registrieren</a>
</div>
</form>
Empty file.
Original file line number Diff line number Diff line change
@@ -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();
});
});
68 changes: 68 additions & 0 deletions devday/src/app/modules/login/components/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { first } from 'rxjs/operators';
import { AuthenticationService } from 'src/app/services/authentication.service';
import { AlertService } from 'src/app/services/alert.service';

@Component({ templateUrl: 'login.component.html' })
export class LoginComponent implements OnInit {
loginForm: FormGroup;
loading = false;
submitted = false;
returnUrl: string;

constructor(
private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private authenticationService: AuthenticationService,
private alertService: AlertService
) {
// redirect to home if already logged in
if (this.authenticationService.currentUserValue) {
this.router.navigate(['/']);
}
}

ngOnInit() {
this.loginForm = this.formBuilder.group({
email: ['', Validators.required],
password: ['', Validators.required]
});

// get return url from route parameters or default to '/'
this.returnUrl = this.route.snapshot.queryParams.returnUrl || '/';
}

// convenience getter for easy access to form fields
get f() {
return this.loginForm.controls;
}

onSubmit() {
this.submitted = true;

// reset alerts on submit
this.alertService.clear();

// stop here if form is invalid
if (this.loginForm.invalid) {
return;
}

this.loading = true;
this.authenticationService
.login(this.f.email.value, this.f.password.value)
.pipe(first())
.subscribe(
data => {
this.router.navigate([this.returnUrl]);
},
error => {
this.alertService.error(error);
this.loading = false;
}
);
}
}
13 changes: 13 additions & 0 deletions devday/src/app/modules/login/login.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LoginComponent } from './components/login/login.component';



@NgModule({
declarations: [LoginComponent],
imports: [
CommonModule
]
})
export class LoginModule { }
9 changes: 9 additions & 0 deletions devday/src/app/pages/home/home.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>Hallo {{ currentUser.email }}!</h1>
<p>Sie sind eingeloggt</p>
<h3>Alle registrierten Benutzer:</h3>
<ul>
<li *ngFor="let user of users">
{{ user.email }} ({{ user.email }} {{ user.lastName }}) -
<a (click)="deleteUser(user.id)" class="text-danger">Löschen</a>
</li>
</ul>
Empty file.
25 changes: 25 additions & 0 deletions devday/src/app/pages/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { HomeComponent } from './home.component';

describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading