This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
IcyNet.eu/src/script/component/User.vue

122 lines
4.0 KiB
Vue

<template lang="pug">
.user.list-item.locked-account(v-if='locked')
h1 Locked account
.description This account has been locked
.id User ID: {{ id }}
.row.user.list-item(v-else='v-else')
.col-4
.avatar
img(v-if='avatar_file', v-bind:src="'/usercontent/images/' + avatar_file")
img(v-else='v-else', src='/static/image/avatar.png')
.col-sm.info
.stamps
.stamp(title="Used an external login" v-if="!password")
i.fas.fa-fw.fa-sign-out-alt
.noactive.stamp(v-if='activated == false' title='Not activated.')
i.fas.fa-fw.fa-envelope
.totp.stamp(v-if='totp_enabled' title="Two-Factor Authentication Enabled")
i.fas.fa-fw.fa-user-shield
.dropdown-wrapper.stamp(@click="dropdown = !dropdown" v-on-clickaway='away')
i.fas.fa-fw.fa-ellipsis-v
transition(name="pop")
.dropdown(v-show="dropdown")
.title Actions
.action(v-on:click='$parent.$emit("edit", id)')
i.fas.fa-fw.fa-edit
|&nbsp;Edit User
.action(v-if='bannable' v-on:click='$parent.$emit("ban", id)')
i.fas.fa-fw.fa-ban
|&nbsp;Ban User
.separator
.action(v-if='!activated' v-on:click='activationToken')
i.fas.fa-fw.fa-envelope
|&nbsp;Activation Email
.action(v-if="totp_enabled" v-on:click='totpRevoke')
i.fas.fa-fw.fa-shield
|&nbsp;Revoke 2FA
.action(v-on:click='resetPassword')
i.fas.fa-fw.fa-envelope
|&nbsp;Password Email
.action(v-on:click='$parent.$emit("email", email)')
i.fas.fa-fw.fa-envelope
|&nbsp;Compose Email
.separator
.action(v-on:click='$parent.$emit("lock", id)' v-if="id != 1 && nw_privilege < 2")
i.fas.fa-fw.fa-lock
|&nbsp;Lock Account
.display_name {{ display_name }}
.name {{ id }} - {{ username }} ({{ uuid }})
.row
.col-4 Email
.col {{ email }}
.row
.col-4 Privilege
.col {{ nw_privilege }}
.row
.col-4 Last IP
.col {{ ip_address }}
.row
.col-4 Registered
.col {{ new Date(created_at).toString() }}
</template>
<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', 'locked'],
directives: {
onClickaway: onClickaway,
},
data: function () {
return {
dropdown: false
}
},
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.')
})
}
}
}
</script>