Skip to content
Snippets Groups Projects
Commit 4bd715d1 authored by Franz Raumschüssel's avatar Franz Raumschüssel
Browse files

login added

parent 8dc1c19a
No related branches found
No related tags found
2 merge requests!4Popup,!1Popup
<p>login works!</p>
<div>
<h2>{{'cLoginText'|translate}}</h2>
<form [formGroup]="loginForm" (ngSubmit)="login()">
<p [ngClass]="{ 'has-error': isSubmitted && formControls.email.errors }">
<input type="email" placeholder="E-Mail" formControlName="email">
</p>
<div *ngIf="isSubmitted && formControls.email.errors">
<div *ngIf="formControls.email.errors.required">E-Mail is required</div>
</div>
<p [ngClass]="{ 'has-error': isSubmitted && formControls.password.errors }">
<input type="password" placeholder="Password" formControlName="password">
</p>
<div *ngIf="isSubmitted && formControls.password.errors">
<div *ngIf="formControls.password.errors.required">Password is required</div>
</div>
<p>
<button mat-button type="submit" color="warn">LOGIN</button>
<!-- <input type="submit" value="Log in">-->
</p>
</form>
</div>
\ No newline at end of file
......@@ -2,15 +2,29 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginComponent } from './login.component';
import { RouterTestingModule } from '@angular/router/testing';
import { FormsModule } from '@angular/forms'
import { ReactiveFormsModule } from '@angular/forms';
import { TranslateModule, TranslateService, TranslateStore } from "@ngx-translate/core";
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent ]
declarations: [LoginComponent],
imports: [
RouterTestingModule,
TranslateModule.forRoot(),
ReactiveFormsModule,
FormsModule
],
//providers: [TranslateService, TranslateStore]
})
.compileComponents();
.compileComponents();
}));
beforeEach(() => {
......
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { JwtService } from '../jwt.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
constructor() { }
constructor(private jwtService: JwtService, private router: Router, private formBuilder: FormBuilder) { }
loginForm: FormGroup;
isSubmitted = false;
ngOnInit(): void {
this.loginForm = this.formBuilder.group({
email: ['', Validators.required],
password: ['', Validators.required]
});
}
get formControls() { return this.loginForm.controls; }
login() {
this.isSubmitted = true;
if (this.loginForm.invalid) {
return;
}
this.jwtService.login(this.loginForm.value);
this.router.navigateByUrl('/admin');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment