setup AuthComponent
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
import { KontorComponent } from './kontor/kontor.component';
|
import { KontorComponent } from './kontor/kontor.component';
|
||||||
import { Login } from './common/login/login';
|
import { Auth } from './common/auth/auth';
|
||||||
import { ComicSectionComponent } from './kontor/comic/comic-section/comic-section.component';
|
import { ComicSectionComponent } from './kontor/comic/comic-section/comic-section.component';
|
||||||
import { comicRoutes } from './kontor/comic/comic-section/comic-section.routes';
|
import { comicRoutes } from './kontor/comic/comic-section/comic-section.routes';
|
||||||
import { TyscSectionComponent } from './kontor/tysc/tysc-section/tysc-section.component';
|
import { TyscSectionComponent } from './kontor/tysc/tysc-section/tysc-section.component';
|
||||||
@@ -10,7 +10,7 @@ import { mediaRoutes } from './kontor/media/media-section/media-section.routes';
|
|||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{ path: '', component: KontorComponent, },
|
{ path: '', component: KontorComponent, },
|
||||||
{ path: 'login', component: Login, },
|
{ path: 'login', component: Auth, },
|
||||||
{
|
{
|
||||||
path: 'comic', component: ComicSectionComponent,
|
path: 'comic', component: ComicSectionComponent,
|
||||||
children: comicRoutes,
|
children: comicRoutes,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { AuthService } from './auth-service';
|
||||||
|
|
||||||
|
describe('AuthService', () => {
|
||||||
|
let service: AuthService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(AuthService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
|
||||||
|
interface AuthResponseData {
|
||||||
|
kind: string;
|
||||||
|
idToken: string;
|
||||||
|
email: string;
|
||||||
|
refreshToken: string;
|
||||||
|
expiresIn: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class AuthService {
|
||||||
|
constructor(private http: HttpClient) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
signup(email: string, password: string) {
|
||||||
|
return this.http.post<AuthResponseData>('http://localhost:8800/signup',
|
||||||
|
{
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
returnToken: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
button {
|
||||||
|
text-align: center;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-left: 14px;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div style="margin-top: 16px;">
|
||||||
|
<form (ngSubmit)="onSubmit(authForm)" #authForm="ngForm">
|
||||||
|
<div class="form-group" style="margin-bottom: 7px;">
|
||||||
|
<label for="email">E-Mail</label>
|
||||||
|
<input type="email" id="email" class="form-control" ngModel name="email" required email=""/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" style="margin-bottom: 7px;">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" id="password" class="form-control" ngModel name="password" required/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button class="btn btn-primary" type="submit" [disabled]="!authForm.valid">
|
||||||
|
{{ isLoginMode ? 'Login' : 'Sign Up' }}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary" (click)="onSwitchMode()" type="button">
|
||||||
|
Switch to {{ isLoginMode ? 'Sign Up' : 'Login' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+6
-6
@@ -1,18 +1,18 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
import { Login } from './login';
|
import { Auth } from './auth';
|
||||||
|
|
||||||
describe('Login', () => {
|
describe('Auth', () => {
|
||||||
let component: Login;
|
let component: Auth;
|
||||||
let fixture: ComponentFixture<Login>;
|
let fixture: ComponentFixture<Auth>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [Login]
|
imports: [Auth]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(Login);
|
fixture = TestBed.createComponent(Auth);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { NgForm } from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-auth',
|
||||||
|
imports: [FormsModule],
|
||||||
|
templateUrl: './auth.html',
|
||||||
|
styleUrl: './auth.css'
|
||||||
|
})
|
||||||
|
export class Auth {
|
||||||
|
isLoginMode = true;
|
||||||
|
|
||||||
|
onSwitchMode() {
|
||||||
|
this.isLoginMode =!this.isLoginMode;
|
||||||
|
}
|
||||||
|
onSubmit(form: NgForm) {
|
||||||
|
console.log(form.value);
|
||||||
|
form.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
<p>login works!</p>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { Component } from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-login',
|
|
||||||
imports: [],
|
|
||||||
templateUrl: './login.html',
|
|
||||||
styleUrl: './login.css'
|
|
||||||
})
|
|
||||||
export class Login {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<div class="topnav">
|
<div class="topnav">
|
||||||
<a routerLink="/" >Kontor</a>
|
<a routerLink="/" >Kontor</a>
|
||||||
<a routerLink="/comic" routerLinkActive="active">Comics</a>
|
<a routerLink="/comic" routerLinkActive="active">Comics</a>
|
||||||
<a routerLink="/tysc" routerLinkActive="active">TradeYourSportsCards</a>
|
<a routerLink="/tysc" routerLinkActive="active">TradeYourSportsCards</a>
|
||||||
<a routerLink="/media" routerLinkActive="active">Media</a>
|
<a routerLink="/media" routerLinkActive="active">Media</a>
|
||||||
|
<a routerLink="/login" routerLinkActive="active" class="float-right">Login</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ body {
|
|||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.topnav :last-child {
|
||||||
|
float: right;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
.subnav {
|
.subnav {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
|
|||||||
Reference in New Issue
Block a user