Move these functions, they don't need to be events

This commit is contained in:
Evert Prants 2017-12-08 15:52:30 +02:00
parent 3155f1a79c
commit c481708ede
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 38 additions and 40 deletions

View File

@ -26,13 +26,13 @@
i.fa.fa-fw.fa-ban
| Ban User
.separator
.action(v-if='!activated' v-on:click='$parent.$emit("activation", id)')
.action(v-if='!activated' v-on:click='activationToken')
i.fa.fa-fw.fa-envelope
| Activation Email
.action(v-if="totp_enabled" v-on:click='$parent.$emit("totp-revoke", id)')
.action(v-if="totp_enabled" v-on:click='totpRevoke')
i.fa.fa-fw.fa-shield
| Revoke 2FA
.action(v-on:click='$parent.$emit("reset-password", id)')
.action(v-on:click='resetPassword')
i.fa.fa-fw.fa-envelope
| Password Email
@ -54,6 +54,7 @@
<script type="text/javascript">
import { directive as onClickaway } from 'vue-clickaway'
const csrfToken = document.querySelector('meta[name="csrf-token"]').content
export default {
props: ['avatar_file', 'activated', 'display_name', 'id', 'username', 'uuid', 'email', 'nw_privilege', 'created_at', 'password', 'bannable', 'ip_address', 'totp_enabled'],
@ -68,6 +69,40 @@
methods: {
away: function () {
this.dropdown = false
},
activationToken: function () {
this.$http.post('/admin/api/user/resend_activation', {
user_id: this.id,
csrf: csrfToken
}).then(data => {
alert('Email sent!')
}).catch(err => {
console.error(err)
alert('Failed to send activation email to this user.')
})
},
totpRevoke: function () {
this.$http.post('/admin/api/user/revoke_totp', {
user_id: this.id,
csrf: csrfToken
}).then(data => {
alert('Success!')
this.$root.$emit('reload_users')
}).catch(err => {
console.error(err)
alert('An error occured.')
})
},
resetPassword: function () {
this.$http.post('/admin/api/user/reset_password', {
user_id: this.id,
csrf: csrfToken
}).then(data => {
alert('Email sent!')
}).catch(err => {
console.error(err)
alert('Failed to send activation email to this user.')
})
}
}
}

View File

@ -84,43 +84,6 @@
this.editing = id
})
this.$on('activation', function (id) {
this.$http.post('/admin/api/user/resend_activation', {
user_id: id,
csrf: csrfToken
}).then(data => {
alert('Email sent!')
}).catch(err => {
console.error(err)
alert('Failed to send activation email to this user.')
})
})
this.$on('totp-revoke', function (id) {
this.$http.post('/admin/api/user/revoke_totp', {
user_id: id,
csrf: csrfToken
}).then(data => {
alert('Success!')
this.getUsers(this.pagination.page)
}).catch(err => {
console.error(err)
alert('An error occured.')
})
})
this.$on('reset-password', function (id) {
this.$http.post('/admin/api/user/reset_password', {
user_id: id,
csrf: csrfToken
}).then(data => {
alert('Email sent!')
}).catch(err => {
console.error(err)
alert('Failed to send activation email to this user.')
})
})
this.$root.$on('reload_users', () => {
this.getUsers(this.pagination.page)
})