Merge pull request '12-user-info-jwt' (#6) from 12-user-info-jwt into develop

Reviewed-on: #6
This commit is contained in:
William Nolin 2021-12-22 16:27:46 -05:00
commit 0960eaa507
11 changed files with 73 additions and 157 deletions

View File

@ -1,6 +1,6 @@
--- ---
global-variables: global-variables:
release: &release ${DRONE_BRANCH##**/} release: &release ${DRONE_TAG}
environment: &environment environment: &environment
CRE_REGISTRY_IMAGE: registry.fyloz.dev:5443/colorrecipesexplorer/frontend CRE_REGISTRY_IMAGE: registry.fyloz.dev:5443/colorrecipesexplorer/frontend
CRE_PORT: 9102 CRE_PORT: 9102
@ -21,6 +21,9 @@ steps:
- echo -n "latest" > .tags - echo -n "latest" > .tags
when: when:
branch: develop branch: develop
event:
exclude:
- pull_request
- name: set-docker-tags-release - name: set-docker-tags-release
image: *alpine-image image: *alpine-image
@ -29,9 +32,10 @@ steps:
commands: commands:
- echo -n "latest-release,$CRE_RELEASE" > .tags - echo -n "latest-release,$CRE_RELEASE" > .tags
when: when:
branch: release/** event:
- tag
- name: containerize - name: containerize-dev
image: plugins/docker image: plugins/docker
environment: environment:
<<: *environment <<: *environment
@ -40,7 +44,16 @@ steps:
when: when:
branch: branch:
- develop - develop
- release/**
- name: containerize-release
image: plugins/docker
environment:
<<: *environment
settings:
repo: *docker-registry-repo
when:
event:
- tag
- name: deploy - name: deploy
image: alpine:latest image: alpine:latest
@ -70,10 +83,11 @@ steps:
- ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker pull $CRE_REGISTRY_IMAGE:$CRE_RELEASE" - ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker pull $CRE_REGISTRY_IMAGE:$CRE_RELEASE"
- ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker run -d -p $CRE_PORT:80 --name=$DEPLOY_CONTAINER_NAME $CRE_REGISTRY_IMAGE:$CRE_RELEASE" - ssh -p $DEPLOY_SERVER_SSH_PORT $DEPLOY_SERVER_USERNAME@$DEPLOY_SERVER "docker run -d -p $CRE_PORT:80 --name=$DEPLOY_CONTAINER_NAME $CRE_REGISTRY_IMAGE:$CRE_RELEASE"
when: when:
branch: release/** event:
- tag
trigger: trigger:
branch: branch:
- develop - develop
- release/** event:
- master - tag

View File

@ -1,14 +1,13 @@
import {NgModule} from '@angular/core' import {NgModule} from '@angular/core'
import {RouterModule, Routes} from '@angular/router' import {RouterModule, Routes} from '@angular/router'
import {LogoutComponent} from './pages/logout/logout.component' import {Login, Logout} from './accounts'
import {Login} from './accounts'
const routes: Routes = [{ const routes: Routes = [{
path: 'login', path: 'login',
component: Login component: Login
}, { }, {
path: 'logout', path: 'logout',
component: LogoutComponent component: Logout
}, { }, {
path: '', path: '',
redirectTo: 'login' redirectTo: 'login'

View File

@ -1,19 +1,16 @@
import {NgModule} from '@angular/core' import {NgModule} from '@angular/core'
import {AccountsRoutingModule} from './accounts-routing.module' import {AccountsRoutingModule} from './accounts-routing.module'
import {LoginComponent} from './pages/login/login.component'
import {SharedModule} from '../shared/shared.module' import {SharedModule} from '../shared/shared.module'
import {LogoutComponent} from './pages/logout/logout.component' import {Login, Logout} from './accounts'
import {Login} from './accounts'
import {CreInputsModule} from '../shared/components/inputs/inputs.module' import {CreInputsModule} from '../shared/components/inputs/inputs.module'
import {CreButtonsModule} from '../shared/components/buttons/buttons.module' import {CreButtonsModule} from '../shared/components/buttons/buttons.module'
@NgModule({ @NgModule({
declarations: [ declarations: [
LoginComponent, Login,
LogoutComponent, Logout
Login
], ],
imports: [ imports: [
SharedModule, SharedModule,

View File

@ -1,12 +1,11 @@
import {Component, HostListener, ViewChild} from '@angular/core' import {Component, HostListener, ViewChild} from '@angular/core'
import {FormControl, Validators} from '@angular/forms' import {FormControl, Validators} from '@angular/forms'
import {ErrorHandlingComponent} from '../shared/components/subscribing.component' import {ErrorHandlingComponent, SubscribingComponent} from '../shared/components/subscribing.component'
import {AccountService} from './services/account.service' import {AccountService} from './services/account.service'
import {AppState} from '../shared/app-state' import {AppState} from '../shared/app-state'
import {ErrorHandler, ErrorService} from '../shared/service/error.service' import {ErrorHandler, ErrorService} from '../shared/service/error.service'
import {ActivatedRoute, Router} from '@angular/router' import {ActivatedRoute, Router} from '@angular/router'
import {CreForm, ICreForm} from "../shared/components/forms/forms"; import {CreForm, ICreForm} from "../shared/components/forms/forms";
import {take, takeUntil} from "rxjs/operators";
import {AlertService} from "../shared/service/alert.service"; import {AlertService} from "../shared/service/alert.service";
@Component({ @Component({
@ -61,3 +60,32 @@ export class Login extends ErrorHandlingComponent {
} }
} }
} }
@Component({
selector: 'cre-logout',
template: ''
})
export class Logout extends SubscribingComponent {
constructor(
private accountService: AccountService,
private alertService: AlertService,
private appState: AppState,
errorService: ErrorService,
router: Router,
activatedRoute: ActivatedRoute
) {
super(errorService, activatedRoute, router)
this.appState.title = 'Connexion'
}
ngOnInit(): void {
if (!this.appState.isAuthenticated) {
this.urlUtils.navigateTo('/account/login')
}
this.subscribeAndNavigate(
this.accountService.logout(),
'/account/login'
)
}
}

View File

@ -1,36 +0,0 @@
<form [formGroup]="form">
<mat-card class="x-centered y-centered">
<mat-card-header>
<mat-card-title>Connexion au système</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-form-field>
<mat-label>Numéro d'utilisateur</mat-label>
<input matInput [formControl]="idFormControl" type="text"/>
<mat-icon matSuffix>person</mat-icon>
<mat-error *ngIf="idFormControl.invalid">
<span *ngIf="idFormControl.errors.required">Un numéro d'utilisateur est requis</span>
<span *ngIf="idFormControl.errors.pattern">Le numéro d'utilisateur doit être un nombre</span>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Mot de passe</mat-label>
<input matInput [formControl]="passwordFormControl" type="password"/>
<mat-icon matSuffix>lock</mat-icon>
<mat-error *ngIf="passwordFormControl.invalid">
<span *ngIf="passwordFormControl.errors.required">Un mot de passe est requis</span>
</mat-error>
</mat-form-field>
</mat-card-content>
<mat-card-actions class="justify-content-end">
<button
mat-raised-button
type="submit"
color="accent"
[disabled]="form.invalid"
(click)="submit()">
Connexion
</button>
</mat-card-actions>
</mat-card>
</form>

View File

@ -1,8 +0,0 @@
mat-card
width: 25rem
.alert p
margin: 0
mat-form-field
width: 100%

View File

@ -1,55 +0,0 @@
import {Component, OnInit} from '@angular/core'
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms'
import {AccountService} from '../../services/account.service'
import {ActivatedRoute, Router} from '@angular/router'
import {ErrorService} from '../../../shared/service/error.service'
import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component'
import {AppState} from '../../../shared/app-state'
@Component({
selector: 'cre-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.sass']
})
export class LoginComponent extends ErrorHandlingComponent implements OnInit {
form: FormGroup
idFormControl: FormControl
passwordFormControl: FormControl
constructor(
private formBuilder: FormBuilder,
private accountService: AccountService,
private appState: AppState,
errorService: ErrorService,
router: Router,
activatedRoute: ActivatedRoute
) {
super(errorService, activatedRoute, router)
this.appState.title = 'Connexion'
}
ngOnInit(): void {
this.errorService.activeErrorHandler = this
if (this.appState.isAuthenticated) {
this.router.navigate(['/color'])
}
this.idFormControl = this.formBuilder.control(null, Validators.compose([Validators.required, Validators.pattern(new RegExp('^[0-9]+$'))]))
this.passwordFormControl = this.formBuilder.control(null, Validators.required)
this.form = this.formBuilder.group({
id: this.idFormControl,
password: this.passwordFormControl
})
}
submit() {
this.subscribe(
this.accountService.login(
this.idFormControl.value,
this.passwordFormControl.value
),
response => console.log(response)
)
}
}

View File

@ -1,35 +0,0 @@
import {Component} from '@angular/core';
import {AccountService} from "../../services/account.service";
import {ActivatedRoute, Router} from "@angular/router";
import {AppState} from "../../../shared/app-state";
import {SubscribingComponent} from "../../../shared/components/subscribing.component";
import {ErrorService} from "../../../shared/service/error.service";
@Component({
selector: 'cre-logout',
templateUrl: './logout.component.html',
styleUrls: ['./logout.component.sass']
})
export class LogoutComponent extends SubscribingComponent {
constructor(
private accountService: AccountService,
private appState: AppState,
errorService: ErrorService,
router: Router,
activatedRoute: ActivatedRoute
) {
super(errorService, activatedRoute, router)
}
ngOnInit(): void {
if (!this.appState.isAuthenticated) {
this.urlUtils.navigateTo('/account/login')
}
this.subscribeAndNavigate(
this.accountService.logout(),
'/account/login'
)
}
}

View File

@ -27,7 +27,7 @@ abstract class _BaseMixPage extends SubscribingComponent {
protected mixService: MixService, protected mixService: MixService,
private recipeService: RecipeService, private recipeService: RecipeService,
private materialTypeService: MaterialTypeService, private materialTypeService: MaterialTypeService,
private materialService: MaterialService, protected materialService: MaterialService,
errorService: ErrorService, errorService: ErrorService,
router: Router, router: Router,
activatedRoute: ActivatedRoute activatedRoute: ActivatedRoute
@ -50,13 +50,15 @@ abstract class _BaseMixPage extends SubscribingComponent {
set recipe(recipe: Recipe) { set recipe(recipe: Recipe) {
this._recipe = recipe this._recipe = recipe
this.materials$ = this.materialService.getAllForMixCreation(recipe.id) this.materials$ = this.fetchMaterials(recipe.id)
} }
get recipe(): Recipe { get recipe(): Recipe {
return this._recipe return this._recipe
} }
protected abstract fetchMaterials(recipeId: number): Observable<Material[]>
abstract submit(dto: MixSaveDto) abstract submit(dto: MixSaveDto)
} }
@ -65,6 +67,10 @@ abstract class _BaseMixPage extends SubscribingComponent {
templateUrl: 'add.html' templateUrl: 'add.html'
}) })
export class MixAdd extends _BaseMixPage { export class MixAdd extends _BaseMixPage {
protected fetchMaterials(recipeId: number): Observable<Material[]> {
return this.materialService.getAllForMixCreation(recipeId)
}
submit(dto: MixSaveDto) { submit(dto: MixSaveDto) {
this.subscribeAndNavigate( this.subscribeAndNavigate(
this.mixService.saveDto(dto), this.mixService.saveDto(dto),
@ -80,21 +86,27 @@ export class MixAdd extends _BaseMixPage {
export class MixEdit extends _BaseMixPage { export class MixEdit extends _BaseMixPage {
mix: Mix mix: Mix
private mixId: number
ngOnInit() { ngOnInit() {
super.ngOnInit() super.ngOnInit()
this.mixId = this.urlUtils.parseIntUrlParam('id')
this.fetchMix() this.fetchMix()
} }
private fetchMix() { private fetchMix() {
const mixId = this.urlUtils.parseIntUrlParam('id')
this.subscribe( this.subscribe(
this.mixService.getById(mixId), this.mixService.getById(this.mixId),
mix => this.mix = mix mix => this.mix = mix
) )
} }
protected fetchMaterials(recipeId: number): Observable<Material[]> {
return this.materialService.getAllForMixUpdate(this.mixId)
}
submit(dto: MixSaveDto) { submit(dto: MixSaveDto) {
this.subscribeAndNavigate( this.subscribeAndNavigate(
this.mixService.updateDto({...dto, id: this.mix.id}), this.mixService.updateDto({...dto, id: this.mix.id}),