Commit 3673efcb authored by Julien BOUYER's avatar Julien BOUYER
Browse files

UNOTOPLYS-238 feat : suppression des vues, des composants et des tests liés...

UNOTOPLYS-238 feat : suppression des vues, des composants et des tests liés Jhipster inutilisées, refonte des services
parent 293107ca
......@@ -132,11 +132,6 @@ server:
cookie:
http-only: true
# Properties to be exposed on the /info management endpoint
info:
# Comma separated list of profiles that will trigger the ribbon to show
display-ribbon-on-profiles: 'dev'
# ===================================================================
# JHipster specific properties
#
......
import Component from 'vue-class-component';
import { Vue, Inject } from 'vue-property-decorator';
import ActivateService from './activate.service';
@Component
export default class Activate extends Vue {
@Inject('activateService')
private activateService: () => ActivateService;
success = false;
error = false;
beforeRouteEnter(to, from, next) {
next(vm => {
if (to.query.key) {
vm.init(to.query.key);
}
});
}
public init(key: string): void {
this.activateService()
.activateAccount(key)
.then(
res => {
this.success = true;
this.error = false;
},
err => {
this.error = true;
this.success = false;
}
);
}
public openLogin(): void {}
}
import axios, { AxiosInstance } from 'axios';
export default class ActivateService {
private axios: AxiosInstance;
constructor() {
this.axios = axios;
}
public activateAccount(key: string): Promise<any> {
return this.axios.get(`api/activate?key=${key}`);
}
}
<template>
<div>
<div class="row justify-content-center">
<div class="col-md-8">
<h1 v-text="$t('activate.title')">Activation</h1>
<div class="alert alert-success" v-if="success">
<span v-html="$t('activate.messages.success')"><strong>Your user account has been activated.</strong> Please </span>
<a class="alert-link" v-on:click="openLogin" v-text="$t('global.messages.info.authenticated.link')">sign in</a>.
</div>
<div class="alert alert-danger" v-if="error" v-html="$t('activate.messages.error')">
<strong>Your user could not be activated.</strong> Please use the registration form to sign up.
</div>
</div>
</div>
</div>
</template>
<script lang="ts" src="./activate.component.ts"></script>
import { maxLength, minLength, required } from 'vuelidate/lib/validators';
import axios from 'axios';
import { mapGetters } from 'vuex';
import Component from 'vue-class-component';
import { Vue, Inject } from 'vue-property-decorator';
const validations = {
resetPassword: {
currentPassword: {
required,
},
newPassword: {
required,
minLength: minLength(4),
maxLength: maxLength(254),
},
confirmPassword: {
required,
minLength: minLength(4),
maxLength: maxLength(254),
},
},
};
@Component({
validations,
computed: {
...mapGetters(['account']),
},
})
export default class ChangePassword extends Vue {
success: string = null;
error: string = null;
doNotMatch: string = null;
resetPassword: any = {
currentPassword: null,
newPassword: null,
confirmPassword: null,
};
public changePassword(): void {
if (this.resetPassword.newPassword !== this.resetPassword.confirmPassword) {
this.error = null;
this.success = null;
this.doNotMatch = 'ERROR';
} else {
this.doNotMatch = null;
axios
.post('api/account/change-password', {
currentPassword: this.resetPassword.currentPassword,
newPassword: this.resetPassword.newPassword,
})
.then(() => {
this.success = 'OK';
this.error = null;
})
.catch(() => {
this.success = null;
this.error = 'ERROR';
});
}
}
public get username(): string {
return this.$store.getters.account ? this.$store.getters.account.login : '';
}
}
<template>
<div>
<div class="row justify-content-center">
<div class="col-md-8 toastify-container">
<h2 v-if="account" id="password-title">
<span v-html="$t('password.title', { username: username })"
>Password for [<b>{{ username }}</b
>]</span
>
</h2>
<div class="alert alert-success" role="alert" v-if="success" v-html="$t('password.messages.success')">
<strong>Password changed!</strong>
</div>
<div class="alert alert-danger" role="alert" v-if="error" v-html="$t('password.messages.error')">
<strong>An error has occurred!</strong> The password could not be changed.
</div>
<div class="alert alert-danger" role="alert" v-if="doNotMatch" v-text="$t('global.messages.error.dontmatch')">
The password and its confirmation do not match!
</div>
<form name="form" role="form" id="password-form" v-on:submit.prevent="changePassword()">
<div class="form-group">
<label class="form-control-label" for="currentPassword" v-text="$t('global.form[\'currentpassword.label\']')"
>Current password</label
>
<input
type="password"
class="form-control"
id="currentPassword"
name="currentPassword"
:class="{ valid: !$v.resetPassword.currentPassword.$invalid, invalid: $v.resetPassword.currentPassword.$invalid }"
v-bind:placeholder="$t('global.form[\'currentpassword.placeholder\']')"
v-model="$v.resetPassword.currentPassword.$model"
required
/>
<div v-if="$v.resetPassword.currentPassword.$anyDirty && $v.resetPassword.currentPassword.$invalid">
<small
class="form-text text-danger"
v-if="!$v.resetPassword.currentPassword.required"
v-text="$t('global.messages.validate.newpassword.required')"
>
Your password is required.
</small>
</div>
</div>
<div class="form-group">
<label class="form-control-label" for="newPassword" v-text="$t('global.form[\'newpassword.label\']')">New password</label>
<input
type="password"
class="form-control"
id="newPassword"
name="newPassword"
v-bind:placeholder="$t('global.form[\'newpassword.placeholder\']')"
:class="{ valid: !$v.resetPassword.newPassword.$invalid, invalid: $v.resetPassword.newPassword.$invalid }"
v-model="$v.resetPassword.newPassword.$model"
minlength="4"
maxlength="50"
required
/>
<div v-if="$v.resetPassword.newPassword.$anyDirty && $v.resetPassword.newPassword.$invalid">
<small
class="form-text text-danger"
v-if="!$v.resetPassword.newPassword.required"
v-text="$t('global.messages.validate.newpassword.required')"
>
Your password is required.
</small>
<small
class="form-text text-danger"
v-if="!$v.resetPassword.newPassword.minLength"
v-text="$t('global.messages.validate.newpassword.minlength')"
>
Your password is required to be at least 4 characters.
</small>
<small
class="form-text text-danger"
v-if="!$v.resetPassword.newPassword.maxLength"
v-text="$t('global.messages.validate.newpassword.maxlength')"
>
Your password cannot be longer than 50 characters.
</small>
</div>
<!--<jhi-password-strength-bar [passwordToCheck]="newPassword"></jhi-password-strength-bar>-->
</div>
<div class="form-group">
<label class="form-control-label" for="confirmPassword" v-text="$t('global.form[\'confirmpassword.label\']')"
>New password confirmation</label
>
<input
type="password"
class="form-control"
id="confirmPassword"
name="confirmPassword"
:class="{ valid: !$v.resetPassword.confirmPassword.$invalid, invalid: $v.resetPassword.confirmPassword.$invalid }"
v-bind:placeholder="$t('global.form[\'confirmpassword.placeholder\']')"
v-model="$v.resetPassword.confirmPassword.$model"
minlength="4"
maxlength="50"
required
/>
<div v-if="$v.resetPassword.confirmPassword.$anyDirty && $v.resetPassword.confirmPassword.$invalid">
<small
class="form-text text-danger"
v-if="!$v.resetPassword.confirmPassword.required"
v-text="$t('global.messages.validate.confirmpassword.required')"
>
Your confirmation password is required.
</small>
<small
class="form-text text-danger"
v-if="!$v.resetPassword.confirmPassword.minLength"
v-text="$t('global.messages.validate.confirmpassword.minlength')"
>
Your confirmation password is required to be at least 4 characters.
</small>
<small
class="form-text text-danger"
v-if="!$v.resetPassword.confirmPassword.maxLength"
v-text="$t('global.messages.validate.confirmpassword.maxlength')"
>
Your confirmation password cannot be longer than 50 characters.
</small>
</div>
</div>
<button type="submit" :disabled="$v.resetPassword.$invalid" class="btn btn-primary" v-text="$t('password.form.button')">
Save
</button>
</form>
</div>
</div>
</div>
</template>
<script lang="ts" src="./change-password.component.ts"></script>
import axios from 'axios';
import Component from 'vue-class-component';
import { Vue, Inject } from 'vue-property-decorator';
import AccountService from '@/account/account.service';
@Component({
watch: {
$route() {
this.$root.$emit('bv::hide::modal', 'login-page');
},
},
})
export default class LoginForm extends Vue {
@Inject('accountService')
private accountService: () => AccountService;
public authenticationError = null;
public login = null;
public password = null;
public rememberMe: boolean = null;
public doLogin(): void {
const data = { username: this.login, password: this.password, rememberMe: this.rememberMe };
axios
.post('api/authenticate', data)
.then(result => {
const bearerToken = result.headers.authorization;
if (bearerToken && bearerToken.slice(0, 7) === 'Bearer ') {
const jwt = bearerToken.slice(7, bearerToken.length);
if (this.rememberMe) {
localStorage.setItem('jhi-authenticationToken', jwt);
} else {
sessionStorage.setItem('jhi-authenticationToken', jwt);
}
}
this.authenticationError = false;
this.$root.$emit('bv::hide::modal', 'login-page');
this.accountService().retrieveAccount();
})
.catch(() => {
this.authenticationError = true;
});
}
}
<template>
<div class="modal-body">
<div class="row justify-content-center">
<div class="col-md-8">
<b-alert show variant="danger" v-if="authenticationError" v-html="$t('login.messages.error.authentication')">
<strong>Failed to sign in!</strong> Please check your credentials and try again.
</b-alert>
</div>
<div class="col-md-8">
<b-form role="form" v-on:submit.prevent="doLogin()">
<b-form-group v-bind:label="$t('global.form[\'username.label\']')" label-for="username">
<b-form-input
id="username"
type="text"
name="username"
autofocus
v-bind:placeholder="$t('global.form[\'username.placeholder\']')"
v-model="login"
>
</b-form-input>
</b-form-group>
<b-form-group v-bind:label="$t('login.form.password')" label-for="password">
<b-form-input
id="password"
type="password"
name="password"
v-model.trim="name"
v-bind:placeholder="$t('login.form[\'password.placeholder\']')"
v-model="password"
>
</b-form-input>
</b-form-group>
<b-form-checkbox id="rememberMe" name="rememberMe" v-model="rememberMe" checked>
<span v-text="$t('login.form.rememberme')">Remember me</span>
</b-form-checkbox>
<div>
<b-button type="submit" variant="primary" v-text="$t('login.form.button')">Sign in</b-button>
</div>
</b-form>
<p></p>
<div>
<b-alert show variant="warning">
<b-link :to="'/account/reset/request'" class="alert-link" v-text="$t('login.password.forgot')"
>Did you forget your password?</b-link
>
</b-alert>
</div>
<div>
<b-alert show variant="warning">
<span v-text="$t('global.messages.info.register.noaccount')">You don't have an account yet?</span>
<b-link :to="'/register'" class="alert-link" v-text="$t('global.messages.info.register.link')">Register a new account</b-link>
</b-alert>
</div>
</div>
</div>
</div>
</template>
<script lang="ts" src="./login-form.component.ts"></script>
import Vue from 'vue';
import { Component, Inject } from 'vue-property-decorator';
import { email, helpers, maxLength, minLength, required, sameAs } from 'vuelidate/lib/validators';
import RegisterService from '@/account/register/register.service';
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from '@/constants';
const loginPattern = helpers.regex('alpha', /^[a-zA-Z0-9!$&*+=?^_`{|}~.-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$|^[_.@A-Za-z0-9-]+$/);
const validations: any = {
registerAccount: {
login: {
required,
minLength: minLength(1),
maxLength: maxLength(50),
pattern: loginPattern,
},
email: {
required,
minLength: minLength(5),
maxLength: maxLength(254),
email,
},
password: {
required,
minLength: minLength(4),
maxLength: maxLength(254),
},
},
confirmPassword: {
required,
minLength: minLength(4),
maxLength: maxLength(50),
// prettier-ignore
sameAsPassword: sameAs(function() {
return this.registerAccount.password;
}),
},
};
@Component({
validations,
})
export default class Register extends Vue {
@Inject('registerService') private registerService: () => RegisterService;
public registerAccount: any = {
login: undefined,
email: undefined,
password: undefined,
};
public confirmPassword: any = null;
public error = '';
public errorEmailExists = '';
public errorUserExists = '';
public success = false;
public register(): void {
this.error = null;
this.errorUserExists = null;
this.errorEmailExists = null;
this.registerAccount.langKey = this.$store.getters.currentLanguage;
this.registerService()
.processRegistration(this.registerAccount)
.then(() => {
this.success = true;
})
.catch(error => {
this.success = null;
if (error.response.status === 400 && error.response.data.type === LOGIN_ALREADY_USED_TYPE) {
this.errorUserExists = 'ERROR';
} else if (error.response.status === 400 && error.response.data.type === EMAIL_ALREADY_USED_TYPE) {
this.errorEmailExists = 'ERROR';
} else {
this.error = 'ERROR';
}
});
}
public openLogin(): void {}
}
import axios from 'axios';
export default class RegisterService {
public processRegistration(account: any): Promise<any> {
return axios.post('api/register', account);
}
}
<template>
<div>
<div class="row justify-content-center">
<div class="col-md-8 toastify-container">
<h1 v-text="$t('register.title')" id="register-title">Registration</h1>
<div class="alert alert-success" role="alert" v-if="success" v-html="$t('register.messages.success')">
<strong>Registration saved!</strong> Please check your email for confirmation.
</div>
<div class="alert alert-danger" role="alert" v-if="error" v-html="$t('register.messages.error.fail')">
<strong>Registration failed!</strong> Please try again later.
</div>
<div class="alert alert-danger" role="alert" v-if="errorUserExists" v-html="$t('register.messages.error.userexists')">
<strong>Login name already registered!</strong> Please choose another one.
</div>
<div class="alert alert-danger" role="alert" v-if="errorEmailExists" v-html="$t('register.messages.error.emailexists')">
<strong>Email is already in use!</strong> Please choose another one.
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-8">
<form id="register-form" name="registerForm" role="form" v-on:submit.prevent="register()" v-if="!success" no-validate>
<div class="form-group">
<label class="form-control-label" for="username" v-text="$t('global.form[\'username.label\']')">Username</label>
<input
type="text"
class="form-control"
v-model="$v.registerAccount.login.$model"
id="username"
name="login"
:class="{ valid: !$v.registerAccount.login.$invalid, invalid: $v.registerAccount.login.$invalid }"
required
minlength="1"
maxlength="50"
pattern="^[a-zA-Z0-9!#$&'*+=?^_`{|}~.-]+@?[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"
v-bind:placeholder="$t('global.form[\'username.placeholder\']')"
/>
<div v-if="$v.registerAccount.login.$anyDirty && $v.registerAccount.login.$invalid">
<small
class="form-text text-danger"
v-if="!$v.registerAccount.login.required"
v-text="$t('register.messages.validate.login.required')"
>
Your username is required.
</small>
<small
class="form-text text-danger"
v-if="!$v.registerAccount.login.minLength"
v-text="$t('register.messages.validate.login.minlength')"
>
Your username is required to be at least 1 character.
</small>
<small
class="form-text text-danger"
v-if="!$v.registerAccount.login.maxLength"
v-text="$t('register.messages.validate.login.maxlength')"
>
Your username cannot be longer than 50 characters.
</small>
<small
class="form-text text-danger"
v-if="!$v.registerAccount.login.pattern"
v-text="$t('register.messages.validate.login.pattern')"
>
Your username can only contain letters and digits.
</small>
</div>
</div>
<div class="form-group">
<label class="form-control-label" for="email" v-text="$t('global.form[\'email.label\']')">Email</label>
<input
type="email"