Add:Email inputs for users

This commit is contained in:
advplyr 2023-10-04 17:05:12 -05:00
parent 565ff36d4e
commit bfe514b7d4
5 changed files with 24 additions and 7 deletions

View File

@ -14,13 +14,17 @@
</div> </div>
<div class="w-1/2 px-2"> <div class="w-1/2 px-2">
<ui-text-input-with-label v-if="!isEditingRoot" v-model="newUser.password" :label="isNew ? $strings.LabelPassword : $strings.LabelChangePassword" type="password" /> <ui-text-input-with-label v-if="!isEditingRoot" v-model="newUser.password" :label="isNew ? $strings.LabelPassword : $strings.LabelChangePassword" type="password" />
<ui-text-input-with-label v-else v-model="newUser.email" :label="$strings.LabelEmail" />
</div> </div>
</div> </div>
<div v-show="!isEditingRoot" class="flex py-2"> <div v-show="!isEditingRoot" class="flex py-2">
<div class="px-2 w-52"> <div class="w-1/2 px-2">
<ui-dropdown v-model="newUser.type" :label="$strings.LabelAccountType" :disabled="isEditingRoot" :items="accountTypes" @input="userTypeUpdated" /> <ui-text-input-with-label v-model="newUser.email" :label="$strings.LabelEmail" />
</div> </div>
<div class="flex-grow" /> <div class="px-2 w-52">
<ui-dropdown v-model="newUser.type" :label="$strings.LabelAccountType" :disabled="isEditingRoot" :items="accountTypes" small @input="userTypeUpdated" />
</div>
<!-- <div class="flex-grow" /> -->
<div class="flex items-center pt-4 px-2"> <div class="flex items-center pt-4 px-2">
<p class="px-3 font-semibold" id="user-enabled-toggle" :class="isEditingRoot ? 'text-gray-300' : ''">{{ $strings.LabelEnable }}</p> <p class="px-3 font-semibold" id="user-enabled-toggle" :class="isEditingRoot ? 'text-gray-300' : ''">{{ $strings.LabelEnable }}</p>
<ui-toggle-switch labeledBy="user-enabled-toggle" v-model="newUser.isActive" :disabled="isEditingRoot" /> <ui-toggle-switch labeledBy="user-enabled-toggle" v-model="newUser.isActive" :disabled="isEditingRoot" />
@ -257,7 +261,6 @@ export default {
if (account.type === 'root' && !account.isActive) return if (account.type === 'root' && !account.isActive) return
this.processing = true this.processing = true
console.log('Calling update', account)
this.$axios this.$axios
.$patch(`/api/users/${this.account.id}`, account) .$patch(`/api/users/${this.account.id}`, account)
.then((data) => { .then((data) => {
@ -329,6 +332,7 @@ export default {
if (this.account) { if (this.account) {
this.newUser = { this.newUser = {
username: this.account.username, username: this.account.username,
email: this.account.email,
password: this.account.password, password: this.account.password,
type: this.account.type, type: this.account.type,
isActive: this.account.isActive, isActive: this.account.isActive,
@ -337,9 +341,9 @@ export default {
itemTagsSelected: [...(this.account.itemTagsSelected || [])] itemTagsSelected: [...(this.account.itemTagsSelected || [])]
} }
} else { } else {
this.fetchAllTags()
this.newUser = { this.newUser = {
username: null, username: null,
email: null,
password: null, password: null,
type: 'user', type: 'user',
isActive: true, isActive: true,

View File

@ -129,7 +129,6 @@ export default {
this.users = res.users.sort((a, b) => { this.users = res.users.sort((a, b) => {
return a.createdAt - b.createdAt return a.createdAt - b.createdAt
}) })
console.log('Loaded users', this.users)
}) })
.catch((error) => { .catch((error) => {
console.error('Failed', error) console.error('Failed', error)

View File

@ -115,6 +115,13 @@ class UserController {
} }
} }
/**
* PATCH: /api/users/:id
* Update user
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
async update(req, res) { async update(req, res) {
const user = req.reqUser const user = req.reqUser
@ -126,6 +133,7 @@ class UserController {
var account = req.body var account = req.body
var shouldUpdateToken = false var shouldUpdateToken = false
// When changing username create a new API token
if (account.username !== undefined && account.username !== user.username) { if (account.username !== undefined && account.username !== user.username) {
const usernameExists = await Database.userModel.getUserByUsername(account.username) const usernameExists = await Database.userModel.getUserByUsername(account.username)
if (usernameExists) { if (usernameExists) {

View File

@ -59,6 +59,7 @@ class User extends Model {
id: userExpanded.id, id: userExpanded.id,
oldUserId: userExpanded.extraData?.oldUserId || null, oldUserId: userExpanded.extraData?.oldUserId || null,
username: userExpanded.username, username: userExpanded.username,
email: userExpanded.email || null,
pash: userExpanded.pash, pash: userExpanded.pash,
type: userExpanded.type, type: userExpanded.type,
token: userExpanded.token, token: userExpanded.token,
@ -96,6 +97,7 @@ class User extends Model {
return { return {
id: oldUser.id, id: oldUser.id,
username: oldUser.username, username: oldUser.username,
email: oldUser.email || null,
pash: oldUser.pash || null, pash: oldUser.pash || null,
type: oldUser.type || null, type: oldUser.type || null,
token: oldUser.token || null, token: oldUser.token || null,

View File

@ -7,6 +7,7 @@ class User {
this.id = null this.id = null
this.oldUserId = null // TODO: Temp for keeping old access tokens this.oldUserId = null // TODO: Temp for keeping old access tokens
this.username = null this.username = null
this.email = null
this.pash = null this.pash = null
this.type = null this.type = null
this.token = null this.token = null
@ -76,6 +77,7 @@ class User {
id: this.id, id: this.id,
oldUserId: this.oldUserId, oldUserId: this.oldUserId,
username: this.username, username: this.username,
email: this.email,
pash: this.pash, pash: this.pash,
type: this.type, type: this.type,
token: this.token, token: this.token,
@ -97,6 +99,7 @@ class User {
id: this.id, id: this.id,
oldUserId: this.oldUserId, oldUserId: this.oldUserId,
username: this.username, username: this.username,
email: this.email,
type: this.type, type: this.type,
token: (this.type === 'root' && hideRootToken) ? '' : this.token, token: (this.type === 'root' && hideRootToken) ? '' : this.token,
mediaProgress: this.mediaProgress ? this.mediaProgress.map(li => li.toJSON()) : [], mediaProgress: this.mediaProgress ? this.mediaProgress.map(li => li.toJSON()) : [],
@ -140,6 +143,7 @@ class User {
this.id = user.id this.id = user.id
this.oldUserId = user.oldUserId this.oldUserId = user.oldUserId
this.username = user.username this.username = user.username
this.email = user.email || null
this.pash = user.pash this.pash = user.pash
this.type = user.type this.type = user.type
this.token = user.token this.token = user.token
@ -184,7 +188,7 @@ class User {
update(payload) { update(payload) {
var hasUpdates = false var hasUpdates = false
// Update the following keys: // Update the following keys:
const keysToCheck = ['pash', 'type', 'username', 'isActive'] const keysToCheck = ['pash', 'type', 'username', 'email', 'isActive']
keysToCheck.forEach((key) => { keysToCheck.forEach((key) => {
if (payload[key] !== undefined) { if (payload[key] !== undefined) {
if (key === 'isActive' || payload[key]) { // pash, type, username must evaluate to true (cannot be null or empty) if (key === 'isActive' || payload[key]) { // pash, type, username must evaluate to true (cannot be null or empty)