mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-23 21:41:44 +02:00
Use Form component in all forms
This commit is contained in:
parent
540a4368f1
commit
27fdbd5489
16
resources/js/components/Form.js
vendored
16
resources/js/components/Form.js
vendored
@ -77,13 +77,13 @@ class Form {
|
|||||||
/**
|
/**
|
||||||
* Reset the form fields.
|
* Reset the form fields.
|
||||||
*/
|
*/
|
||||||
// reset () {
|
reset () {
|
||||||
// Object.keys(this)
|
Object.keys(this)
|
||||||
// .filter(key => !Form.ignore.includes(key))
|
.filter(key => !Form.ignore.includes(key))
|
||||||
// .forEach(key => {
|
.forEach(key => {
|
||||||
// this[key] = deepCopy(this.originalData[key])
|
this[key] = deepCopy(this.originalData[key])
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Submit the form via a GET request.
|
* Submit the form via a GET request.
|
||||||
@ -267,6 +267,6 @@ class Form {
|
|||||||
|
|
||||||
Form.routes = {}
|
Form.routes = {}
|
||||||
Form.errorMessage = 'Something went wrong. Please try again.'
|
Form.errorMessage = 'Something went wrong. Please try again.'
|
||||||
Form.ignore = ['isBusy', /*'successful', 'errors',*/ 'originalData']
|
Form.ignore = ['isBusy', /*'successful'*/, 'errors', 'originalData']
|
||||||
|
|
||||||
export default Form
|
export default Form
|
||||||
|
@ -7,16 +7,16 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.email') }}</label>
|
<label class="label">{{ $t('auth.forms.email') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="email" type="email" class="input" v-model="email" required autofocus />
|
<input id="email" type="email" class="input" v-model="form.email" required autofocus />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.email">{{ validationErrors.email.toString() }}</p>
|
<field-error :form="form" field="email" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.password') }}</label>
|
<label class="label">{{ $t('auth.forms.password') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="password" type="password" class="input" v-model="password" required />
|
<input id="password" type="password" class="input" v-model="form.password" required />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.password">{{ validationErrors.password.toString() }}</p>
|
<field-error :form="form" field="password" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
@ -49,13 +49,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import Form from './../../components/Form'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
email : '',
|
errorMessage: '',
|
||||||
password : '',
|
form: new Form({
|
||||||
validationErrors: {},
|
email: '',
|
||||||
errorMessage: ''
|
password: ''
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -63,10 +67,7 @@
|
|||||||
handleSubmit(e) {
|
handleSubmit(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
axios.post('api/login', {
|
this.form.post('/api/login')
|
||||||
email: this.email,
|
|
||||||
password: this.password
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
localStorage.setItem('user',response.data.message.name)
|
localStorage.setItem('user',response.data.message.name)
|
||||||
localStorage.setItem('jwt',response.data.message.token)
|
localStorage.setItem('jwt',response.data.message.token)
|
||||||
@ -76,18 +77,11 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
||||||
this.validationErrors = {}
|
|
||||||
this.errorMessage = ''
|
|
||||||
|
|
||||||
if( error.response.status === 401 ) {
|
if( error.response.status === 401 ) {
|
||||||
this.errorMessage = this.$t('auth.forms.password_do_not_match')
|
this.errorMessage = this.$t('auth.forms.password_do_not_match')
|
||||||
}
|
}
|
||||||
else if( error.response.status == 422 ) {
|
else if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = error.response.data.errors
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -7,30 +7,30 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.name') }}</label>
|
<label class="label">{{ $t('auth.forms.name') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="name" type="text" class="input" v-model="name" required autofocus />
|
<input id="name" type="text" class="input" v-model="form.name" required autofocus />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.name">{{ validationErrors.name.toString() }}</p>
|
<field-error :form="form" field="name" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.email') }}</label>
|
<label class="label">{{ $t('auth.forms.email') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="email" type="email" class="input" v-model="email" required />
|
<input id="email" type="email" class="input" v-model="form.email" required />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.email">{{ validationErrors.email.toString() }}</p>
|
<field-error :form="form" field="email" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.password') }}</label>
|
<label class="label">{{ $t('auth.forms.password') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="password" type="password" class="input" v-model="password" required />
|
<input id="password" type="password" class="input" v-model="form.password" required />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.password">{{ validationErrors.password.toString() }}</p>
|
<field-error :form="form" field="password" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.confirm_password') }}</label>
|
<label class="label">{{ $t('auth.forms.confirm_password') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="password_confirmation" type="password" class="input" v-model="password_confirmation" required />
|
<input id="password_confirmation" type="password" class="input" v-model="form.password_confirmation" required />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.passwordConfirmation">{{ validationErrors.passwordConfirmation.toString() }}</p>
|
<field-error :form="form" field="password_confirmation" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
@ -55,15 +55,19 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import Form from './../../components/Form'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
|
errorMessage: '',
|
||||||
|
form: new Form({
|
||||||
name : '',
|
name : '',
|
||||||
email : '',
|
email : '',
|
||||||
password : '',
|
password : '',
|
||||||
password_confirmation : '',
|
password_confirmation : '',
|
||||||
validationErrors: {},
|
})
|
||||||
errorMessage: ''
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -77,7 +81,7 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -85,14 +89,8 @@
|
|||||||
handleSubmit(e) {
|
handleSubmit(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
axios.post('api/register', {
|
this.form.post('api/register')
|
||||||
name: this.name,
|
|
||||||
email: this.email,
|
|
||||||
password: this.password,
|
|
||||||
password_confirmation : this.password_confirmation
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
||||||
localStorage.setItem('user',response.data.message.name)
|
localStorage.setItem('user',response.data.message.name)
|
||||||
localStorage.setItem('jwt',response.data.message.token)
|
localStorage.setItem('jwt',response.data.message.token)
|
||||||
|
|
||||||
@ -101,14 +99,8 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = {}
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
|
|
||||||
if( error.response.status == 422 ) {
|
|
||||||
this.validationErrors = error.response.data.errors
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.email') }}</label>
|
<label class="label">{{ $t('auth.forms.email') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="email" type="email" class="input" v-model="email" required autofocus />
|
<input id="email" type="email" class="input" v-model="form.email" required autofocus />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.email">{{ validationErrors.email.toString() }}</p>
|
<field-error :form="form" field="email" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
@ -19,58 +19,52 @@
|
|||||||
<router-link :to="{ name: 'login' }" class="button is-text">{{ $t('commons.cancel') }}</router-link>
|
<router-link :to="{ name: 'login' }" class="button is-text">{{ $t('commons.cancel') }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
<div class="field" v-if="errorMessage">
|
||||||
<br />
|
<span class="tag is-danger">
|
||||||
<span class="tag is-danger" v-if="errorMessage">
|
|
||||||
{{ errorMessage }}
|
{{ errorMessage }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="columns is-mobile is-centered" v-if="response">
|
<div class="columns is-mobile is-centered" v-if="response">
|
||||||
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
||||||
{{ response }}
|
{{ response }}
|
||||||
</router-link>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import Form from './../../../components/Form'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
email : '',
|
|
||||||
validationErrors: {},
|
|
||||||
response: '',
|
response: '',
|
||||||
errorMessage: ''
|
errorMessage: '',
|
||||||
|
form: new Form({
|
||||||
|
email: '',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods : {
|
methods : {
|
||||||
handleSubmit(e){
|
handleSubmit(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
this.validationErrors = {}
|
this.form.post('/api/password/email')
|
||||||
|
|
||||||
axios.post('/api/password/email', {
|
|
||||||
email: this.email
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
||||||
this.response = response.data.status
|
this.response = response.data.status
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
if( error.response.data.requestFailed ) {
|
||||||
if( error.response.status == 422 ) {
|
|
||||||
this.validationErrors = error.response.data.errors
|
|
||||||
}
|
|
||||||
else if( error.response.data.requestFailed ) {
|
|
||||||
this.errorMessage = error.response.data.requestFailed
|
this.errorMessage = error.response.data.requestFailed
|
||||||
}
|
}
|
||||||
else {
|
else if( error.response.status !== 422 ) {
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,23 +7,23 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.email') }}</label>
|
<label class="label">{{ $t('auth.forms.email') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="email" type="email" class="input" v-model="email" disabled readonly />
|
<input id="email" type="email" class="input" v-model="form.email" disabled readonly />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.email">{{ validationErrors.email.toString() }}</p>
|
<field-error :form="form" field="email" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.new_password') }}</label>
|
<label class="label">{{ $t('auth.forms.new_password') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="password" type="password" class="input" v-model="password" required />
|
<input id="password" type="password" class="input" v-model="form.password" required />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.password">{{ validationErrors.password.toString() }}</p>
|
<field-error :form="form" field="password" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('auth.forms.confirm_password') }}</label>
|
<label class="label">{{ $t('auth.forms.confirm_password') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="password_confirmation" type="password" class="input" v-model="password_confirmation" required />
|
<input id="password_confirmation" type="password" class="input" v-model="form.password_confirmation" required />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.password_confirmation">{{ validationErrors.password_confirmation.toString() }}</p>
|
<field-error :form="form" field="password_confirmation" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
@ -33,63 +33,55 @@
|
|||||||
<router-link :to="{ name: 'login' }" class="button is-text">{{ $t('commons.cancel') }}</router-link>
|
<router-link :to="{ name: 'login' }" class="button is-text">{{ $t('commons.cancel') }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
<div class="field" v-if="errorMessage">
|
||||||
<br />
|
<span class="tag is-danger">
|
||||||
<span class="tag is-danger" v-if="errorMessage">
|
|
||||||
{{ errorMessage }}
|
{{ errorMessage }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import Form from './../../../components/Form'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
|
errorMessage: '',
|
||||||
|
form: new Form({
|
||||||
email : '',
|
email : '',
|
||||||
password : '',
|
password : '',
|
||||||
password_confirmation : '',
|
password_confirmation : '',
|
||||||
token : '',
|
token: ''
|
||||||
validationErrors: {},
|
})
|
||||||
errorMessage: ''
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created () {
|
created () {
|
||||||
this.email = this.$route.query.email
|
this.form.email = this.$route.query.email
|
||||||
this.token = this.$route.params.token
|
this.form.token = this.$route.params.token
|
||||||
},
|
},
|
||||||
|
|
||||||
methods : {
|
methods : {
|
||||||
handleSubmit(e) {
|
handleSubmit(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
this.validationErrors = {}
|
this.form.post('/api/password/reset')
|
||||||
|
|
||||||
axios.post('/api/password/reset', {
|
|
||||||
email: this.email,
|
|
||||||
password: this.password,
|
|
||||||
password_confirmation : this.password_confirmation,
|
|
||||||
token: this.token
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
||||||
this.$router.go('/');
|
this.$router.go('/');
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
if( error.response.data.resetFailed ) {
|
||||||
if( error.response.status == 422 ) {
|
|
||||||
this.validationErrors = error.response.data.errors
|
|
||||||
}
|
|
||||||
else if( error.response.data.resetFailed ) {
|
|
||||||
this.errorMessage = error.response.data.resetFailed
|
this.errorMessage = error.response.data.resetFailed
|
||||||
}
|
}
|
||||||
else {
|
else if( error.response.status !== 422 ) {
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -21,14 +21,14 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="twofaccount.service" autofocus />
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="form.service" autofocus />
|
||||||
</div>
|
</div>
|
||||||
<field-error :form="form" field="service" />
|
<field-error :form="form" field="service" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="twofaccount.account" />
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="form.account" />
|
||||||
</div>
|
</div>
|
||||||
<field-error :form="form" field="account" />
|
<field-error :form="form" field="account" />
|
||||||
</div>
|
</div>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control is-expanded">
|
<div class="control is-expanded">
|
||||||
<input class="input" type="text" placeholder="otpauth://totp/..." v-model="twofaccount.uri" :disabled="uriIsLocked" />
|
<input class="input" type="text" placeholder="otpauth://totp/..." v-model="form.uri" :disabled="uriIsLocked" />
|
||||||
</div>
|
</div>
|
||||||
<div class="control" v-if="uriIsLocked">
|
<div class="control" v-if="uriIsLocked">
|
||||||
<a class="button is-dark field-lock" @click="uriIsLocked = false" :title="$t('twofaccounts.forms.unlock.title')">
|
<a class="button is-dark field-lock" @click="uriIsLocked = false" :title="$t('twofaccounts.forms.unlock.title')">
|
||||||
@ -95,15 +95,8 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
twofaccount: {
|
|
||||||
'service' : '',
|
|
||||||
'account' : '',
|
|
||||||
'uri' : '',
|
|
||||||
'icon' : ''
|
|
||||||
},
|
|
||||||
uriIsLocked: true,
|
uriIsLocked: true,
|
||||||
tempIcon: '',
|
tempIcon: '',
|
||||||
validationErrors: {},
|
|
||||||
form: new Form({
|
form: new Form({
|
||||||
service: '',
|
service: '',
|
||||||
account: '',
|
account: '',
|
||||||
@ -118,17 +111,14 @@
|
|||||||
|
|
||||||
createAccount() {
|
createAccount() {
|
||||||
// set current temp icon as account icon
|
// set current temp icon as account icon
|
||||||
this.twofaccount.icon = this.tempIcon
|
this.form.icon = this.tempIcon
|
||||||
|
|
||||||
this.form.post('/api/twofaccounts', this.twofaccount)
|
this.form.post('/api/twofaccounts')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if( error.response.status == 422 ) {
|
if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = error.response.data.errors
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -137,9 +127,7 @@
|
|||||||
|
|
||||||
cancelCreation: function() {
|
cancelCreation: function() {
|
||||||
// clean possible uploaded temp icon
|
// clean possible uploaded temp icon
|
||||||
if( this.tempIcon ) {
|
|
||||||
this.deleteIcon()
|
this.deleteIcon()
|
||||||
}
|
|
||||||
|
|
||||||
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
||||||
},
|
},
|
||||||
@ -147,19 +135,16 @@
|
|||||||
uploadQrcode(event) {
|
uploadQrcode(event) {
|
||||||
|
|
||||||
let imgdata = new FormData();
|
let imgdata = new FormData();
|
||||||
|
|
||||||
imgdata.append('qrcode', this.$refs.qrcodeInput.files[0]);
|
imgdata.append('qrcode', this.$refs.qrcodeInput.files[0]);
|
||||||
|
|
||||||
this.form.upload('/api/qrcode/decode', imgdata)
|
this.form.upload('/api/qrcode/decode', imgdata)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.twofaccount = response.data;
|
this.form.service = response.data.service;
|
||||||
this.validationErrors['qrcode'] = '';
|
this.form.account = response.data.account;
|
||||||
|
this.form.uri = response.data.uri;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if( error.response.status == 422 ) {
|
if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = error.response.data.errors
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -169,24 +154,17 @@
|
|||||||
uploadIcon(event) {
|
uploadIcon(event) {
|
||||||
|
|
||||||
// clean possible already uploaded temp icon
|
// clean possible already uploaded temp icon
|
||||||
if( this.tempIcon ) {
|
|
||||||
this.deleteIcon()
|
this.deleteIcon()
|
||||||
}
|
|
||||||
|
|
||||||
let imgdata = new FormData();
|
let imgdata = new FormData();
|
||||||
|
|
||||||
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
||||||
|
|
||||||
this.form.upload('/api/icon/upload', imgdata)
|
this.form.upload('/api/icon/upload', imgdata)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.tempIcon = response.data;
|
this.tempIcon = response.data;
|
||||||
this.validationErrors['icon'] = '';
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if( error.response.status == 422 ) {
|
if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = error.response.data.errors
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -200,15 +178,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clearTwofaccount() {
|
|
||||||
this.twofaccount.service = ''
|
|
||||||
this.twofaccount.account = ''
|
|
||||||
this.twofaccount.uri = ''
|
|
||||||
this.twofaccount.icon = ''
|
|
||||||
|
|
||||||
this.deleteIcon()
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
<div class="columns is-mobile is-centered">
|
<div class="columns is-mobile is-centered">
|
||||||
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
||||||
<h1 class="title">{{ $t('twofaccounts.forms.edit_account') }}</h1>
|
<h1 class="title">{{ $t('twofaccounts.forms.edit_account') }}</h1>
|
||||||
<form @submit.prevent="updateAccount">
|
<form @submit.prevent="updateAccount" @keydown="form.onKeydown($event)">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="twofaccount.service" autofocus />
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="form.service" autofocus />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.service">{{ validationErrors.service.toString() }}</p>
|
<field-error :form="form" field="service" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="twofaccount.account" />
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="form.account" />
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger" v-if="validationErrors.account">{{ validationErrors.account.toString() }}</p>
|
<field-error :form="form" field="account" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="help is-danger help-for-file" v-if="validationErrors.icon">{{ validationErrors.icon.toString() }}</p>
|
<field-error :form="form" field="icon" class="help-for-file" />
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button type="submit" class="button is-link">{{ $t('twofaccounts.forms.save') }}</button>
|
<button type="submit" class="button is-link">{{ $t('twofaccounts.forms.save') }}</button>
|
||||||
@ -52,18 +52,21 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
import Form from './../../components/Form'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
twofaccount: {
|
|
||||||
'service' : '',
|
|
||||||
'account' : '',
|
|
||||||
'uri' : '',
|
|
||||||
'icon' : ''
|
|
||||||
},
|
|
||||||
twofaccountExists: false,
|
twofaccountExists: false,
|
||||||
tempIcon: '',
|
tempIcon: '',
|
||||||
validationErrors: {}
|
form: new Form({
|
||||||
|
service: '',
|
||||||
|
account: '',
|
||||||
|
uri: '',
|
||||||
|
icon: '',
|
||||||
|
qrcode: null
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -76,11 +79,11 @@
|
|||||||
|
|
||||||
axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.twofaccount = response.data
|
this.form.fill(response.data)
|
||||||
this.twofaccountExists = true
|
this.twofaccountExists = true
|
||||||
|
|
||||||
// set account icon as temp icon
|
// set account icon as temp icon
|
||||||
this.tempIcon = this.twofaccount.icon
|
this.tempIcon = this.form.icon
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
||||||
@ -91,26 +94,23 @@
|
|||||||
updateAccount() {
|
updateAccount() {
|
||||||
|
|
||||||
// Set new icon and delete old one
|
// Set new icon and delete old one
|
||||||
if( this.tempIcon !== this.twofaccount.icon ) {
|
if( this.tempIcon !== this.form.icon ) {
|
||||||
let oldIcon = ''
|
let oldIcon = ''
|
||||||
|
|
||||||
oldIcon = this.twofaccount.icon
|
oldIcon = this.form.icon
|
||||||
|
|
||||||
this.twofaccount.icon = this.tempIcon
|
this.form.icon = this.tempIcon
|
||||||
this.tempIcon = oldIcon
|
this.tempIcon = oldIcon
|
||||||
this.deleteIcon()
|
this.deleteIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
axios.put('/api/twofaccounts/' + this.$route.params.twofaccountId, this.twofaccount)
|
this.form.put('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if( error.response.status == 422 ) {
|
if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = error.response.data.errors
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -129,26 +129,15 @@
|
|||||||
this.deleteIcon()
|
this.deleteIcon()
|
||||||
|
|
||||||
let imgdata = new FormData();
|
let imgdata = new FormData();
|
||||||
|
|
||||||
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
||||||
|
|
||||||
let config = {
|
this.form.upload('/api/icon/upload', imgdata)
|
||||||
header : {
|
|
||||||
'Content-Type' : 'multipart/form-data',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
axios.post('/api/icon/upload', imgdata, config)
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.tempIcon = response.data;
|
this.tempIcon = response.data;
|
||||||
this.validationErrors['icon'] = '';
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if( error.response.status == 422 ) {
|
if( error.response.status !== 422 ) {
|
||||||
this.validationErrors = error.response.data.errors
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -156,7 +145,7 @@
|
|||||||
|
|
||||||
deleteIcon(event) {
|
deleteIcon(event) {
|
||||||
|
|
||||||
if( this.tempIcon && this.tempIcon !== this.twofaccount.icon ) {
|
if( this.tempIcon && this.tempIcon !== this.form.icon ) {
|
||||||
axios.delete('/api/icon/delete/' + this.tempIcon)
|
axios.delete('/api/icon/delete/' + this.tempIcon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user