Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webapp): create generic email & password field #801

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions www/webapp/src/components/DonateDirectDebitForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@
validate-on-blur
/>

<v-text-field
<generic-email
v-model="email"
label="Email Address (optional)"
:prepend-icon="mdiEmail"
outlined
:rules="email_rules"
:error-messages="email_errors"
validate-on-blur
:errorMessages="email_errors"
:required="false"
/>

<v-btn
Expand All @@ -98,10 +94,10 @@

<script>
import axios from 'axios';
import {email_pattern} from '@/validation';
import {digestError} from '@/utils';
import ErrorAlert from '@/components/ErrorAlert.vue';
import {mdiAccount, mdiBank, mdiCash100, mdiEmail, mdiMessageTextOutline} from "@mdi/js";
import {mdiAccount, mdiBank, mdiCash100, mdiMessageTextOutline} from "@mdi/js";
import GenericEmail from "@/components/Field/GenericEmail.vue";

const HTTP = axios.create({
baseURL: '/api/v1/',
Expand All @@ -112,6 +108,7 @@
export default {
name: 'DonateDirectDebitForm',
components: {
GenericEmail,
ErrorAlert,
},
data: () => ({
Expand All @@ -125,7 +122,6 @@
mdiBank,
mdiCash100,
mdiMessageTextOutline,
mdiEmail,

/* from env */
creditorid: import.meta.env.VITE_APP_DESECSTACK_API_SEPA_CREDITOR_ID,
Expand Down Expand Up @@ -154,7 +150,6 @@

/* email field */
email: '',
email_rules: [v => v === '' || !!email_pattern.test(v || '') || 'This is not an email address.'],
email_errors: [],

/* donation interval (every N months) */
Expand Down
101 changes: 101 additions & 0 deletions www/webapp/src/components/Field/GenericEmail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<template>
<v-text-field
v-bind="computedProps"
v-on="$listeners"
/>
</template>

<script>
import {email_pattern} from '@/validation';
import {mdiEmail, mdiEmailLock} from '@mdi/js';
import {VTextField} from 'vuetify/lib/components';

export default {
name: 'GenericEmail',
extends: VTextField,
props: {
value: {
type: String,
required: false,
},
errorMessages: {
type: [String, Array],
default: () => [],
},
label: {
type: String,
required: false,
},
placeholder: {
type: String,
required: false,
},
required: {
type: Boolean,
default: true,
},
standalone: {
type: Boolean,
default: false,
},
readonly: {
type: Boolean,
required: false,
},
autofocus: {
type: Boolean,
required: false,
},
new: {
type: Boolean,
required: false,
},
},
computed: {
computedProps() {
let label = 'Email Address';
if(!this.required) {
label += ' (optional)';
}
if(this.new) {
label = 'New ' + label;
}
if(this.standalone) {
label = '';
}
if(this.label) { // Override if custom is set.
label = this.label;
}
const icon = this.readonly ? mdiEmailLock : mdiEmail;
const ruleDefs = {
required: v => !!v || 'Email is required.',
valid: v => (v !== undefined && !!email_pattern.test(v)) || 'We need an valid email address for account recovery and technical support.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text either should be generic or configurable through a prop.

};
let rules = []
if(this.required) {
rules.push(ruleDefs.required);
}
if(this.new) {
rules.push(ruleDefs.valid);
}
return {
type: 'email',
value: this.value,
'error-messages': this.errorMessages,
label: label,
required: this.required,
disabled: this.readonly,
autofocus: this.autofocus,
placeholder: this.placeholder ?? 'Email Address',
prependIcon: this.standalone ? '' : icon,
prependInnerIcon: this.standalone ? icon : '',
flat: this.standalone,
solo: this.standalone,
outlined: true,
rules: rules,
validateOnInput: true,
}
}
},
};
</script>
91 changes: 91 additions & 0 deletions www/webapp/src/components/Field/GenericPassword.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<template>
<v-text-field
v-bind="computedProps"
v-on="$listeners"
@click:append="toggleHide()"
/>
</template>

<script>
import {mdiEye, mdiEyeOff, mdiKey} from '@mdi/js';
import {VTextField} from 'vuetify/lib/components';

export default {
name: 'GenericPassword',
extends: VTextField,
props: {
errorMessages: {
type: [String, Array],
default: () => [],
},
label: {
type: String,
required: false,
},
required: {
type: Boolean,
default: true,
},
standalone: {
type: Boolean,
default: false,
},
new: {
type: Boolean,
required: false,
},
},
data() {
return {
hide_password: true,
};
},
computed: {
computedProps() {
const icon = mdiKey;
const iconToggle = this.hide_password ? mdiEyeOff : mdiEye;
let label = 'Password';
if(!this.required) {
label += ' (Optional)';
}
if(this.new) {
label = 'New ' + label;
}
if(this.label) { // override with custom label
label = this.label;
}
const ruleDefs = {
required: v => !!v || 'Password is required.',
min: v => (v !== undefined && v.length >= 8) || 'Min 8 characters',
};
let rules = []
if(this.required) {
rules.push(ruleDefs.required)
}
if(this.new) {
rules.push(ruleDefs.min)
}
return {
...this.$props,
type: this.hide_password ? 'password' : 'text',
label: label,
autocomplete: this.new ? 'new-password' : '',
prependIcon: this.standalone ? '' : icon,
prependInnerIcon: this.standalone ? icon : '',
appendIcon: iconToggle,
flat: this.standalone,
solo: this.standalone,
outlined: true,
rules: rules,
errorMessages: this.errorMessages,
validateOnInput: true,
}
}
},
methods: {
toggleHide() {
this.hide_password = !this.hide_password;
}
},
};
</script>
29 changes: 9 additions & 20 deletions www/webapp/src/components/ResetPasswordActionHandler.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<template>
<div>
<div class="text-center" v-if="!success">
<v-text-field
v-model="payload.new_password"
:append-icon="show ? 'mdi-eye' : 'mdi-eye-off'"
label="New password"
required
:disabled="working"
:rules="[rules.required, rules.min]"
:type="show ? 'text' : 'password'"
hint="At least 8 characters"
autocomplete="new-password"
@click:append="show = !show"
tabindex="1"
></v-text-field>
<generic-password
v-model="payload.new_password"
:autofocus="true"
:new="true"
:standalone="true"
tabindex="1"
/>
<v-btn
depressed
color="primary"
Expand All @@ -31,16 +25,11 @@

<script>
import GenericActionHandler from "./GenericActionHandler.vue"
import GenericPassword from "@/components/Field/GenericPassword.vue";

export default {
name: 'ResetPasswordActionHandler',
components: {GenericPassword},
extends: GenericActionHandler,
data: () => ({
rules: {
required: value => !!value || 'Required.',
min: v => (v !== undefined && v.length >= 8) || 'Min 8 characters',
},
show: false,
}),
};
</script>
53 changes: 17 additions & 36 deletions www/webapp/src/views/ChangeEmail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,21 @@
</p>
</v-alert>

<v-text-field
v-model="email"
label="Current Email"
prepend-icon="mdi-blank"
outlined
required
:disabled="true"
validate-on-blur
<generic-email
v-model="email"
label="Current Email Address"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this overwritten by computed?

:readonly="true"
/>
<v-text-field
v-model="password"
:append-icon="show ? 'mdi-eye' : 'mdi-eye-off'"
prepend-icon="mdi-blank"
outlined
label="Password"
required
:rules="[rules.required]"
:type="show ? 'text' : 'password'"
:error-messages="password_errors"
@change="password_errors=[]"
@click:append="show = !show"
ref="password"
tabindex="1"
></v-text-field>
<v-text-field

<generic-password
v-model="password"
ref="password"
tabindex="1"
/>

<generic-email
v-model="new_email"
label="New Email"
prepend-icon="mdi-email"
outlined
required
:rules="[rules.required, rules.email]"
:error-messages="email_errors"
@change="email_errors=[]"
validate-on-blur
:new="true"
tabindex="2"
/>
</v-card-text>
Expand All @@ -91,13 +72,15 @@

<script>
import { HTTP, withWorking ,digestError} from '@/utils';
import {email_pattern} from '@/validation';

import ErrorAlert from "@/components/ErrorAlert.vue";
import GenericEmail from "@/components/Field/GenericEmail.vue";
import GenericPassword from "@/components/Field/GenericPassword.vue";

export default {
name: 'ChangeEmail',
components: {
GenericEmail,
GenericPassword,
ErrorAlert,
},
data: () => ({
Expand All @@ -108,13 +91,11 @@
email: '',
rules: {
required: v => !!v || 'Required.',
email: v => !!email_pattern.test(v) || 'Not a valid email address.'
},
show: false,

/* password field */
password: '',
password_errors: [],

/* email field */
new_email: '',
Expand Down
Loading
Loading