auth with cookies.

This commit is contained in:
Jegor 2021-06-15 10:38:54 +02:00
parent cf300cb1b7
commit b062e14c9a
6 changed files with 42 additions and 14 deletions

View File

@ -61,7 +61,7 @@ form{
} }
.btn_signin{ .btn_signin{
transition: all .5s ease; transition: all .5s ease;
width: 70%; width: 100%;
border-radius: 30px; border-radius: 30px;
color:#008080; color:#008080;
font-weight: 600; font-weight: 600;

View File

@ -32,7 +32,6 @@ export class RegistrationComponent implements OnInit {
get me() { return this.form.controls; } get me() { return this.form.controls; }
onSubmit() { onSubmit() {
console.log(this.form.value);
this.api.registerUser(this.form.value.username, this.form.value.password, this.form.value.email).subscribe(res=>console.log(res)); this.api.registerUser(this.form.value.username, this.form.value.password, this.form.value.email).subscribe(res=>console.log(res));
} }
} }

View File

@ -61,7 +61,7 @@ form{
} }
.btn_signin{ .btn_signin{
transition: all .5s ease; transition: all .5s ease;
width: 70%; width: 100%;
border-radius: 30px; border-radius: 30px;
color:#008080; color:#008080;
font-weight: 600; font-weight: 600;

View File

@ -9,7 +9,7 @@
<h2>Anmelden</h2> <h2>Anmelden</h2>
</div> </div>
<div class="row"> <div class="row">
<form [formGroup]="form" class="form-group" (ngSubmit)="onSubmit()"> <form [formGroup]="loginForm" class="form-group" (ngSubmit)="onSubmit()">
<div class="row"> <div class="row">
<input type="text" formControlName="username" name="username" id="username" class="form__input" placeholder="Username"> <input type="text" formControlName="username" name="username" id="username" class="form__input" placeholder="Username">
</div> </div>

View File

@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {FormBuilder, Validators} from "@angular/forms"; import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {ApiService} from "../../../services/api.service"; import {ApiService} from "../../../services/api.service";
import {Router} from "@angular/router";
@Component({ @Component({
selector: 'app-signin', selector: 'app-signin',
@ -10,22 +11,45 @@ import {ApiService} from "../../../services/api.service";
export class SigninComponent implements OnInit { export class SigninComponent implements OnInit {
form: any; loginForm: FormGroup;
loading = false;
submitted = false;
private isSuccessful: boolean;
private isSignUpFailed: boolean;
private errorMessage: '';
constructor( constructor(
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private api : ApiService private api: ApiService,
private router: Router
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.form = this.formBuilder.group({ this.loginForm = this.formBuilder.group({
email: ['', Validators.required], username: ['', Validators.required],
password: ['', Validators.required] password: ['', [Validators.required, Validators.minLength(8)]]
}); });
} }
onSubmit() { onSubmit() {
console.log(this.form.value);
this.api.loginUser(this.form.value.username, this.form.value.password); this.submitted = true;
if (this.loginForm.invalid) {
return;
}
this.api.loginUser(this.loginForm.value.username, this.loginForm.value.password)
.subscribe(
data => {
this.router.navigate(['']);
this.isSuccessful = true;
this.isSignUpFailed = false;
},
err => {
this.errorMessage = err.error.message;
this.isSignUpFailed = true;
})
} }
} }

View File

@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {ApiService} from "../../services/api.service";
@Component({ @Component({
selector: 'app-top-bar', selector: 'app-top-bar',
@ -9,9 +11,12 @@ export class TopBarComponent implements OnInit {
sidenav: any; sidenav: any;
constructor() { } constructor(
private api: ApiService
) { }
ngOnInit() { ngOnInit() {
}
this.api.getUserInfo().subscribe(data=>{console.log(data)});
}
} }