Skip to content
Snippets Groups Projects
Commit b1bc4065 authored by simon.mellerin's avatar simon.mellerin
Browse files

Merge branch '49-email-no-username' into 'main'

#49 - connection - from 'username' to 'e-mail address'

Closes #49

See merge request !47
parents d696d799 29d897ac
No related branches found
No related tags found
1 merge request!47#49 - connection - from 'username' to 'e-mail address'
Pipeline #10470 passed
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
<Form <Form
class="flex flex-col gap-2" class="flex flex-col gap-2"
:validation-schema="validationSchema" :validation-schema="validationSchema"
@submit="emit('login', $event.username, $event.password)" @submit="emit('login', $event.email, $event.password)"
> >
<Field name="username" v-slot="{ field, errorMessage }"> <Field name="email" v-slot="{ field, errorMessage }">
<label for="username">{{ t('connection.username') }}</label> <label for="email">{{ t('connection.emailAddress') }}</label>
<InputText id="username" v-bind="field" :invalid="!!errorMessage" /> <InputText id="email" v-bind="field" :invalid="!!errorMessage" />
<Message v-if="errorMessage" severity="error">{{ errorMessage }}</Message> <Message v-if="errorMessage" severity="error">{{ errorMessage }}</Message>
</Field> </Field>
<Field name="password" v-slot="{ value, errorMessage, handleChange }"> <Field name="password" v-slot="{ value, errorMessage, handleChange }">
...@@ -40,14 +40,14 @@ import Message from 'primevue/message' ...@@ -40,14 +40,14 @@ import Message from 'primevue/message'
import Password from 'primevue/password' import Password from 'primevue/password'
const emit = defineEmits<{ const emit = defineEmits<{
login: [username: string, password: string] login: [email: string, password: string]
}>() }>()
const { t } = useI18n() const { t } = useI18n()
const validationSchema = toTypedSchema( const validationSchema = toTypedSchema(
yup.object({ yup.object({
username: yup.string().required().label(t('connection.username')), email: yup.string().required().label(t('connection.emailAddress')),
password: yup.string().required().label(t('connection.password')) password: yup.string().required().label(t('connection.password'))
}) })
) )
......
...@@ -63,7 +63,7 @@ export type OcTreeNode = { ...@@ -63,7 +63,7 @@ export type OcTreeNode = {
} }
export type Credentials = { export type Credentials = {
username: string email: string
password: string password: string
} }
......
...@@ -18,7 +18,7 @@ export function httpFetch( ...@@ -18,7 +18,7 @@ export function httpFetch(
options?.method ?? 'GET', options?.method ?? 'GET',
url, url,
true, true,
options?.auth?.username, options?.auth?.email,
options?.auth?.password options?.auth?.password
); );
......
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
}, },
connection: { connection: {
catchphrase: 'One account, different community data-sharing areas', catchphrase: 'One account, different community data-sharing areas',
username: 'Username', emailAddress: 'E-mail address',
password: 'Password', password: 'Password',
login: 'Login', login: 'Login',
logout: 'Logout', logout: 'Logout',
......
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
}, },
connection: { connection: {
catchphrase: 'Un seul compte, différents espaces communautaires de partage de données', catchphrase: 'Un seul compte, différents espaces communautaires de partage de données',
username: 'Nom d\'utilisateur', emailAddress: 'Adresse e-mail',
password: 'Mot de passe', password: 'Mot de passe',
login: 'Connexion', login: 'Connexion',
logout: 'Déconnexion', logout: 'Déconnexion',
......
...@@ -71,12 +71,12 @@ const breadcrumbItems = computed<OcBreadcrumbItem[]>(() => [ ...@@ -71,12 +71,12 @@ const breadcrumbItems = computed<OcBreadcrumbItem[]>(() => [
} }
]) ])
async function connection(username: string, password: string) { async function connection(email: string, password: string) {
const profileInfos = await getProfileInfos({ username: username, password: password }) const profileInfos = await getProfileInfos({ email, password })
if (profileInfos) { if (profileInfos) {
accountStore.auth = { accountStore.auth = {
username: username, email: email,
password: password password: password
} }
accountStore.infos = profileInfos.infos accountStore.infos = profileInfos.infos
......
...@@ -17,11 +17,12 @@ export const useAccountStore = defineStore<string, AccountState>('account', () = ...@@ -17,11 +17,12 @@ export const useAccountStore = defineStore<string, AccountState>('account', () =
const localAuth = localStorage.getItem('token') const localAuth = localStorage.getItem('token')
if (localAuth !== null) { if (localAuth !== null) {
const [username, password] = atob(localAuth).split(':') const [email, password] = atob(localAuth).split(':')
if (email && password) {
auth.value = { auth.value = {
username: username, email: email,
password: password, password: password,
}
} }
} }
...@@ -33,7 +34,7 @@ export const useAccountStore = defineStore<string, AccountState>('account', () = ...@@ -33,7 +34,7 @@ export const useAccountStore = defineStore<string, AccountState>('account', () =
watch(auth, (auth: Credentials) => { watch(auth, (auth: Credentials) => {
if (auth) { if (auth) {
localStorage.setItem("token", btoa(`${auth.username}:${auth.password}`)); localStorage.setItem("token", btoa(`${auth.email}:${auth.password}`));
} else { } else {
localStorage.removeItem("token") localStorage.removeItem("token")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment