-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/login page #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mschwrdtnr
wants to merge
8
commits into
master
Choose a base branch
from
feat/login-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/login page #14
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0416e0c
init login module
mschwrdtnr bb48508
Remove src folder
f35ddf5
initial model, service, helper, guards
4608fe7
create components
mschwrdtnr 1c8d482
Merge branch 'feat/login-page' of https://github.com/devdaydresden/de…
e7d5f1a
Merge code and fix imports
2344c9f
rename username into email
mschwrdtnr 1339eb4
Merge branch 'master' into feat/login-page
artifactdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "git.ignoreLimitWarning": true | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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']); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { } |
1 change: 1 addition & 0 deletions
1
devday/src/app/modules/alert/components/alert/alert.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <div *ngIf="message" [ngClass]="message.cssClass">{{ message.text }}</div> |
Empty file.
25 changes: 25 additions & 0 deletions
25
devday/src/app/modules/alert/components/alert/alert.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
32
devday/src/app/modules/alert/components/alert/alert.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
34
devday/src/app/modules/login/components/login/login.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| <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.
25 changes: 25 additions & 0 deletions
25
devday/src/app/modules/login/components/login/login.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
68
devday/src/app/modules/login/components/login/login.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.