-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Rotzbua
wants to merge
2
commits into
desec-io:main
Choose a base branch
from
Rotzbua:webapp_input
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
}; | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this overwritten by |
||
: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> | ||
|
@@ -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: () => ({ | ||
|
@@ -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: '', | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.