Skip to content

Commit

Permalink
Merge branch 'release/0.3.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ju4n97 committed Nov 15, 2020
2 parents f3cf8bd + ed7051f commit 2f9ab3b
Show file tree
Hide file tree
Showing 75 changed files with 109 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { RouterModule, Routes } from '@angular/router';
import { Path } from '@app/@core/enums';
import { ForgotPasswordEmailSentPage } from './pages/forgot-password-email-sent/forgot-password-email-sent.page';
import { ForgotPasswordPage } from './pages/forgot-password/forgot-password.page';
import { LOGIN_ROUTE } from './pages/login/login.page.route';
import { PasswordResetFailedPage } from './pages/password-reset-failed/password-reset-failed.page';
import { PasswordResetSucceededPage } from './pages/password-reset-succeeded/password-reset-succeeded.page';
import { PasswordResetPage } from './pages/password-reset/password-reset.page';
import { SIGN_IN_ROUTE } from './pages/sign-in/sign-in.page.route';
import { SignUpPage } from './pages/sign-up/sign-up.page';

const routes: Routes = [
LOGIN_ROUTE,
SIGN_IN_ROUTE,
{
path: Path.SignUp,
component: SignUpPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,31 @@ import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { AuthRoutingModule } from './auth-routing.module';
import { ForgotPasswordFormComponent } from './components/forgot-password-form/forgot-password-form.component';
import { LoginFormComponent } from './components/login-form/login-form.component';
import { PasswordResetFormComponent } from './components/password-reset-form/password-reset-form.component';
import { SignInFormComponent } from './components/sign-in-form/sign-in-form.component';
import { SignUpFormComponent } from './components/sign-up-form/sign-up-form.component';
import { ForgotPasswordEmailSentPage } from './pages/forgot-password-email-sent/forgot-password-email-sent.page';
import { ForgotPasswordPage } from './pages/forgot-password/forgot-password.page';
import { LoginPage } from './pages/login/login.page';
import { PasswordResetFailedPage } from './pages/password-reset-failed/password-reset-failed.page';
import { PasswordResetSucceededPage } from './pages/password-reset-succeeded/password-reset-succeeded.page';
import { PasswordResetPage } from './pages/password-reset/password-reset.page';
import { SignInPage } from './pages/sign-in/sign-in.page';
import { SignUpPage } from './pages/sign-up/sign-up.page';

@NgModule({
declarations: [
LoginPage,
SignInPage,
SignUpPage,
ForgotPasswordPage,
ForgotPasswordEmailSentPage,
PasswordResetPage,
PasswordResetSucceededPage,
PasswordResetFailedPage,
LoginFormComponent,
SignInFormComponent,
SignUpFormComponent,
ForgotPasswordFormComponent,
PasswordResetFormComponent,
SignInFormComponent,
],
imports: [CommonModule, AuthRoutingModule],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- card -->

<div
class="z-10 flex flex-col justify-center w-full p-6 bg-transparent rounded-none sm:rounded sm:h-auto sm:bg-accent md:shadow-2xl"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SignInFormComponent } from './sign-in-form.component';

describe('SignInFormComponent', () => {
let component: SignInFormComponent;
let fixture: ComponentFixture<SignInFormComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SignInFormComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SignInFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { Path } from '@app/@core/enums';
import { User } from '@app/@core/shared/user';

@Component({
selector: 'app-login-form',
templateUrl: './login-form.component.html',
styleUrls: ['./login-form.component.scss'],
selector: 'app-sign-in-form',
templateUrl: './sign-in-form.component.html',
styleUrls: ['./sign-in-form.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LoginFormComponent implements OnInit {
export class SignInFormComponent implements OnInit {
@Input() errorMessage: string;
@Input() loading: boolean;

Expand All @@ -29,8 +29,8 @@ export class LoginFormComponent implements OnInit {

onClickSignIn() {
const user: Partial<User> = {
username: 'juanmesa2097',
password: 'televition',
username: '',
password: '',
};
this.signIn.emit(user);
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
<div class="container relative px-0 my-0 sm:my-auto">
<!-- row -->
<div class="max-w-full mx-auto sm:max-w-md">
<!-- login form -->
<app-login-form
<!-- sign in form -->
<app-sign-in-form
[errorMessage]="errorMessage"
[loading]="loading"
(signIn)="onSignIn($event)"
></app-login-form>
<!-- login form end -->
></app-sign-in-form>
<!-- sign in form end -->
</div>
<!-- row end -->
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Route } from '@angular/router';
import { Path } from '@app/@core/enums';
import { LoginPage } from './login.page';
import { SignInPage } from './sign-in.page';

export const LOGIN_ROUTE: Route = {
path: Path.Login,
component: LoginPage,
export const SIGN_IN_ROUTE: Route = {
path: Path.SignIn,
component: SignInPage,
data: {
title: 'Login on Angular Boilerplate',
title: 'Sign into Angular Boilerplate',
description:
'Start writing your business logic without any concern on architecture matters.',
robots: 'index, follow',
Expand Down
25 changes: 25 additions & 0 deletions src/app/+auth/pages/sign-in/sign-in.page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SignInPage } from './sign-in.page';

describe('SignInPage', () => {
let component: SignInPage;
let fixture: ComponentFixture<SignInPage>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SignInPage ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SignInPage);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthService } from '@app/+auth';
import { Path } from '@app/@core/enums';
import { User } from '@app/@core/shared/user';
import { AuthService } from '../../shared/services/auth.service';

@Component({
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
templateUrl: './sign-in.page.html',
styleUrls: ['./sign-in.page.scss'],
})
export class LoginPage implements OnInit {
export class SignInPage implements OnInit {
returnUrl: string;
errorMessage: string;
loading = false;
Expand All @@ -28,7 +28,7 @@ export class LoginPage implements OnInit {
async onSignIn(user: User) {
this.loading = true;
try {
await this.authService.login(user).toPromise();
await this.authService.signIn(user).toPromise();
this.router.navigate([this.returnUrl]);
} catch (err) {
const message = [401, 403].includes(err.status)
Expand Down
Empty file.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/app/+auth/shared/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { SignInResult } from './sign-in-result.interface';
export { Token } from './token.interface';
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from '@core/shared/user';
import { Token } from '.';

export interface LoginResult {
export interface SignInResult {
user: User;
token: Token;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { User } from '@core/shared/user';
import { environment } from '@environments/environment';
import { BehaviorSubject, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { LoginResult, Token } from '../interfaces';
import { SignInResult, Token } from '../interfaces';

@Injectable({
providedIn: 'root',
})
export class AuthService extends GenericHttpService<User | LoginResult> {
export class AuthService extends GenericHttpService<User | SignInResult> {
private readonly USER_ITEM = '_user';
private readonly TOKEN_ITEM = '_token';

Expand All @@ -37,9 +37,9 @@ export class AuthService extends GenericHttpService<User | LoginResult> {
return !!(user && token);
}

login({ username, password }: User): Observable<LoginResult> {
return super.post({ username, password }, 'login').pipe(
map((result: LoginResult) => {
signIn({ username, password }: User): Observable<SignInResult> {
return super.post({ username, password }, 'sign-in').pipe(
map((result: SignInResult) => {
const { user, token } = result;
this._saveUser(user);
this._saveToken(token);
Expand All @@ -49,8 +49,8 @@ export class AuthService extends GenericHttpService<User | LoginResult> {
);
}

register(user: User): Observable<User> {
return super.post(user, 'register') as Observable<User>;
signUp(user: User): Observable<User> {
return super.post(user, 'sign-up') as Observable<User>;
}

beginPasswordReset(email: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/@core/enums/path.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum Path {

// Auth
Auth = '',
Login = 'login',
SignIn = 'sign-in',
SignUp = 'sign-up',
ForgotPassword = 'forgot-password',
ForgotPasswordEmailSent = 'forgot-password-email-sent',
Expand Down
6 changes: 3 additions & 3 deletions src/app/@core/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RouterStateSnapshot,
UrlTree,
} from '@angular/router';
import { AuthService } from '@app/features/_auth';
import { AuthService } from '@app/+auth';
import { Observable } from 'rxjs';
import { Path } from '../enums';

Expand All @@ -30,8 +30,8 @@ export class AuthGuard implements CanActivate {
return true;
}

// if not logged in redirects to login page with the return url
this.router.navigate([`/${Path.Login}`], {
// if not logged in redirects to sign-in page with the return url
this.router.navigate([`/${Path.SignIn}`], {
queryParams: { returnUrl: state.url },
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/@core/guards/no-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RouterStateSnapshot,
UrlTree,
} from '@angular/router';
import { AuthService } from '@app/features/_auth';
import { AuthService } from '@app/+auth';
import { Observable } from 'rxjs';
import { Path } from '../enums';

Expand Down
2 changes: 1 addition & 1 deletion src/app/@core/guards/role.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RouterStateSnapshot,
UrlTree,
} from '@angular/router';
import { AuthService } from '@app/features/_auth';
import { AuthService } from '@app/+auth';
import { Observable } from 'rxjs';
import { RoleList } from '../shared/role';

Expand Down
2 changes: 1 addition & 1 deletion src/app/@core/interceptors/jwt.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
HttpRequest,
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AuthService } from '@app/features/_auth';
import { AuthService } from '@app/+auth';
import { environment } from '@environments/environment';
import { Observable } from 'rxjs';

Expand Down
4 changes: 2 additions & 2 deletions src/app/@core/interceptors/server-error.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '@app/features/_auth';
import { AuthService } from '@app/+auth';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Path } from '../enums';
Expand All @@ -24,7 +24,7 @@ export class ServerErrorInterceptor implements HttpInterceptor {
catchError((error: HttpErrorResponse) => {
if ([401, 403].includes(error.status)) {
this.authService.logout();
this.router.navigateByUrl(Path.Login);
this.router.navigateByUrl(Path.SignIn);
return throwError(error);
} else if (error.status === 500) {
this.router.navigateByUrl('/internal-server-error');
Expand Down
16 changes: 8 additions & 8 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import { NotFoundPage } from '@public/pages/not-found/not-found.page';
import { Path } from './@core/enums/path.enum';
import { AuthGuard, NoAuthGuard } from './@core/guards';
import { NotFoundPage } from './public/pages/not-found/not-found.page';

const routes: Routes = [
// ===== Uncomment if Path.Home is different from empty =====
Expand All @@ -12,15 +12,14 @@ const routes: Routes = [
{
path: '',
loadChildren: () =>
import('@public/public.module').then((m) => m.PublicModule),
import('./public/public.module').then((m) => m.PublicModule),
},

// Auth
{
path: Path.Auth,
canActivate: [NoAuthGuard],
loadChildren: () =>
import('@features/_auth/auth.module').then((m) => m.AuthModule),
loadChildren: () => import('./+auth/auth.module').then((m) => m.AuthModule),
},

// App
Expand All @@ -36,9 +35,7 @@ const routes: Routes = [
{
path: Path.Dashboard,
loadChildren: () =>
import('@features/dashboard/dashboard.module').then(
(m) => m.DashboardModule
),
import('./dashboard/dashboard.module').then((m) => m.DashboardModule),
},
],
},
Expand All @@ -52,7 +49,10 @@ const routes: Routes = [

@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules, relativeLinkResolution: 'legacy' }),
RouterModule.forRoot(routes, {
preloadingStrategy: PreloadAllModules,
relativeLinkResolution: 'legacy',
}),
],
exports: [RouterModule],
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from './+auth';
import { Path } from './@core/enums';
import { SeoService } from './@core/services';
import { AuthService } from './features/_auth';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
Expand All @@ -26,6 +26,6 @@ export class AppComponent implements OnInit {

onLogout() {
this.authService.logout();
this.router.navigate([Path.Login]);
this.router.navigate([Path.SignIn]);
}
}
File renamed without changes.
Empty file.
Loading

0 comments on commit 2f9ab3b

Please sign in to comment.