enable log in via either token or through proxy auth

This commit is contained in:
Igor Serebryany 2023-10-06 14:04:31 -07:00
parent eae72ed29a
commit 49c1b8f106
No known key found for this signature in database
GPG key ID: 0AF607692FD9EB24
3 changed files with 108 additions and 28 deletions

View file

@ -1,10 +1,7 @@
const uuidv4 = require("uuid").v4
const Logger = require('../Logger')
const SocketAuthority = require('../SocketAuthority')
const Database = require('../Database')
const User = require('../objects/user/User')
const { toNumber } = require('../utils/index')
class UserController {
@ -36,9 +33,9 @@ class UserController {
* GET: /api/users/:id
* Get a single user toJSONForBrowser
* Media progress items include: `displayTitle`, `displaySubtitle` (for podcasts), `coverPath` and `mediaUpdatedAt`
*
* @param {import("express").Request} req
* @param {import("express").Response} res
*
* @param {import("express").Request} req
* @param {import("express").Response} res
*/
async findOne(req, res) {
if (!req.user.isAdminOrUp) {
@ -97,15 +94,8 @@ class UserController {
return res.status(500).send('Username already taken')
}
account.id = uuidv4()
account.pash = await this.auth.hashPass(account.password)
delete account.password
account.token = await this.auth.generateAccessToken({ userId: account.id, username })
account.createdAt = Date.now()
const newUser = new User(account)
const success = await Database.createUser(newUser)
if (success) {
const newUser = await this.auth.createUser(account)
if (newUser) {
SocketAuthority.adminEmitter('user_added', newUser.toJSONForBrowser())
res.json({
user: newUser.toJSONForBrowser()
@ -118,9 +108,9 @@ class UserController {
/**
* PATCH: /api/users/:id
* Update user
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
async update(req, res) {
const user = req.reqUser
@ -250,4 +240,4 @@ class UserController {
next()
}
}
module.exports = new UserController()
module.exports = new UserController()