From d320dc4ce53a9b6877c89285966b43aa8489c523 Mon Sep 17 00:00:00 2001 From: Diego Albitres Date: Fri, 6 May 2022 22:41:09 -0500 Subject: [PATCH] feat(auth): added initial auth service * No checks are done, logged in by default --- src/app/auth/model/user.ts | 9 ++++++ src/app/auth/services/auth.service.spec.ts | 16 ++++++++++ src/app/auth/services/auth.service.ts | 37 ++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/app/auth/model/user.ts create mode 100644 src/app/auth/services/auth.service.spec.ts create mode 100644 src/app/auth/services/auth.service.ts diff --git a/src/app/auth/model/user.ts b/src/app/auth/model/user.ts new file mode 100644 index 0000000..c1f32e6 --- /dev/null +++ b/src/app/auth/model/user.ts @@ -0,0 +1,9 @@ +export interface User { + preferredName: string; + fullName: string; + email: string; + location: string; + profileViews: number; + biography: string; + about: string; +} diff --git a/src/app/auth/services/auth.service.spec.ts b/src/app/auth/services/auth.service.spec.ts new file mode 100644 index 0000000..0a6cb89 --- /dev/null +++ b/src/app/auth/services/auth.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/auth/services/auth.service.ts b/src/app/auth/services/auth.service.ts new file mode 100644 index 0000000..3224b19 --- /dev/null +++ b/src/app/auth/services/auth.service.ts @@ -0,0 +1,37 @@ +import { User } from "../model/user"; +import { Injectable } from "@angular/core"; + +@Injectable({ + providedIn: "root", +}) +export class AuthService { + static user: User = { + preferredName: "John", + fullName: "John Doe", + email: "john.doe@gmail.com", + location: "Lima, Peru", + profileViews: 367, + biography: + "Freelance UX/UI designer, 80+ projects in Web, Mobile (Android & iOS) and creative projects. Open to offers.", + about: + "I'm more experienced in e-commerce web projects and mobile banking apps, but also like to work with creative projects, such as landing pages or unusual corporate websites.", + }; + static loggedIn: boolean = true; + + constructor() {} + + static login(): void { + this.loggedIn = true; + } + + static logout(): void { + this.loggedIn = false; + } + + static getCurrentUser(): User | null { + if (this.loggedIn) { + return this.user; + } + return null; + } +}