summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2019-03-04 01:14:38 +0100
committerJannik Schönartz2019-03-04 01:14:38 +0100
commit6471511909de79c1f3739ba9d6a5b45b7eb1fadb (patch)
treeb0702eae88cea3ce8fff89f1fa2f91849e79e1ee
parent[webapp] add option to disable all animations (diff)
downloadbas-6471511909de79c1f3739ba9d6a5b45b7eb1fadb.tar.gz
bas-6471511909de79c1f3739ba9d6a5b45b7eb1fadb.tar.xz
bas-6471511909de79c1f3739ba9d6a5b45b7eb1fadb.zip
[authentication] Restructure api to match our new error code standard
Moved most of the res.send from the lib to the api Fixed frontend to match the new api
-rw-r--r--server/api/authentication.js55
-rw-r--r--server/api/users.js56
-rw-r--r--server/lib/authentication.js170
-rw-r--r--webapp/src/components/AccountModule.vue2
-rw-r--r--webapp/src/components/StartPageLogin.vue8
-rw-r--r--webapp/src/components/StartPageSetup.vue2
-rw-r--r--webapp/src/components/UserModuleDelete.vue6
-rw-r--r--webapp/src/components/UserModuleEdit.vue2
-rw-r--r--webapp/src/main.js2
9 files changed, 157 insertions, 146 deletions
diff --git a/server/api/authentication.js b/server/api/authentication.js
index 60b08a1..2aa5101 100644
--- a/server/api/authentication.js
+++ b/server/api/authentication.js
@@ -14,29 +14,70 @@ noAuthRouter.get('/setup', (req, res) => {
})
})
-noAuthRouter.post('/token', (req, res) => {
- authentication.loginToken(req, res)
+// Authentification method for the API using the authorization header. (GET)
+noAuthRouter.postAsync('/token', async (req, res) => {
+ const body = req.body
+ const result = await authentication.verifyUser(body.username, body.password)
+ const code = result.code
+ delete result.code
+ return res.status(code).send(result)
})
-noAuthRouter.post('/login', (req, res) => {
- authentication.loginCookie(req, res)
+/*
+ * username
+ * password
+ *
+ * @return: Return an object with the jwt. { token:<TOKEN> }
+ */
+noAuthRouter.postAsync('/cookies', async (req, res) => {
+ const body = req.body
+ const result = await authentication.verifyUser(body.username, body.password)
+ const code = result.code
+ delete result.code
+ if (code !== 200) return res.status(code).send(result)
+ else {
+ // The token has the form header.payload.signature
+ // We split the cookie in header.payload and signature in two seperate cookies.
+ // The signature cookie is httpOnly so JavaScript never has access to the full cookie.
+ // Read more at: https://medium.com/lightrail/getting-token-authentication-right-in-a-stateless-single-page-application-57d0c6474e3
+ const split = result.token.split('.')
+ const headerPayload = split[0] + '.' + split[1]
+ const signature = split[2]
+ res.cookie('jwt_hp', headerPayload, { secure: true, httpOnly: false, sameSite: 'strict' })
+ res.cookie('jwt_s', signature, { secure: true, httpOnly: true, sameSite: 'strict' })
+ return res.send()
+ }
})
+// Logout method for the frontend. Deleting the cookies by overwriting them.
noAuthRouter.post('/logout', (req, res) => {
- authentication.logout(req, res)
+ // End session properly.
+ res.clearCookie('jwt_hp')
+ res.clearCookie('jwt_s')
+ // TODO: blacklisting jwt ?
+ // authentication.logout()
+ // TODO: Implement.. blacklisting for jwt's and destroy the cookies..
+ // Maybe use express-jwt and use the rewoke function.
+ return res.status(200).send()
})
// Setup method for creating the initial root account.
noAuthRouter.postAsync('/setup', async (req, res) => {
+ const body = req.body
const users = await db.user.findAll()
if (users.length > 0) res.status(403).send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
else {
- const user = await authentication.signup(req, res)
+ const result = await authentication.signup(body)
+ const code = result.code
+ delete result.code
+ if (result.error) return res.status(code).send(result)
+
+ const user = await db.user.findOne({ where: { id: result.id } })
const roleDb = await db.role.create({ name: user.username, descr: 'Superadmin' })
const permission = await db.permission.findOne({ where: { name: 'superadmin' } })
await roleDb.addPermissions(permission.id)
await user.addRoles(roleDb.id)
- res.status(200).send({ auth: true, status: 'VALID' })
+ res.send()
}
})
diff --git a/server/api/users.js b/server/api/users.js
index 178c6fb..c4d9a2f 100644
--- a/server/api/users.js
+++ b/server/api/users.js
@@ -13,13 +13,7 @@ var authentication = require(path.join(__appdir, 'lib', 'authentication'))
* @return: Returns a list of all users in the database and their given roles.
*/
router.getAsync('', async (req, res) => {
- const users = await db.user.findAll({ include: ['roles'], order: [['name', 'ASC']] })
-
- // Remove passwords
- await users.forEach(x => {
- x = x.dataValues
- delete x.password
- })
+ const users = await db.user.findAll({ attributes: { exclude: ['password'] }, include: ['roles'], order: [['name', 'ASC']] })
res.status(200).send(users)
})
@@ -28,12 +22,9 @@ router.getAsync('', async (req, res) => {
*/
router.getAsync('/:id', async (req, res) => {
const id = req.params.id === 'current' ? req.user.id : req.params.id
- const user = await db.user.findOne({ where: { id } })
+ const user = await db.user.findOne({ where: { id }, attributes: { exclude: ['password'] } })
if (user) {
- // Remove the hased password.
- let u = user.dataValues
- delete u.password
- res.status(200).send(u)
+ res.status(200).send(user)
} else {
res.status(404).end()
}
@@ -62,48 +53,54 @@ router.postAsync('/:id/roles', async (req, res) => {
// Post request for creating new user accounts.
router.postAsync(['/', '/:id'], async (req, res) => {
+ const body = req.body
if (req.params.id !== 'current') {
// TODO: Check for permission to delete / create / update user
}
if (req.query.delete !== undefined && req.query.delete !== 'false') {
- const count = await db.user.destroy({ where: { id: req.body.ids } })
- return res.status(200).send({ count })
+ const count = await db.user.destroy({ where: { id: body.ids } })
+ return res.send({ count })
}
if (req.params.id === undefined) {
- await authentication.signup(req, res)
- return res.status(200).send({ auth: true, status: 'VALID' })
+ const result = await authentication.signup(body)
+ const code = result.code
+ delete result.code
+ return res.status(code).send(result)
} else {
const id = req.params.id === 'current' ? req.user.id : req.params.id
let email = req.body.email
- if (!authentication.validateEmail(req.body.email)) return res.status(500).send({ status: 'EMAIL_INVALID', error_message: 'The provided email is invalid.' })
+ if (!authentication.validateEmail(req.body.email)) return res.status(500).send({ error: 'EMAIL_INVALID', message: 'The provided email is invalid.' })
let user
user = await db.user.findOne({ where: { id: id } })
if (user) {
let userinfo = {
- name: req.body.name,
+ name: body.name,
email: email
}
// Check if the username is set and if it's valid.
- let username = req.body.username
+ let username = body.username
if (username && req.params.id !== 'current') {
- if (!authentication.validateUsername(username)) return res.status(400).send({ auth: false, status: 'INVALID_USERNAME', error_message: 'Username does not fullfill the requirements. (No whitespaces)' })
+ if (!authentication.validateUsername(username)) return res.status(400).send({ error: 'INVALID_USERNAME', message: 'Username does not fullfill the requirements. (No whitespaces)' })
// Check if the username already exists.
let userDb = await db.user.findOne({ where: { username: username, id: { $not: id } } })
- if (userDb) return res.status(400).send({ auth: false, status: 'USER_ALREADY_EXISTS', error_message: 'The provided username already exists.' })
+ if (userDb) return res.status(400).send({ error: 'USER_ALREADY_EXISTS', message: 'The provided username already exists.' })
userinfo.username = username
}
// Update the user.
await user.update(userinfo)
- if (req.body.password) {
- return authentication.changePassword(req, res)
+ if (body.password) {
+ const result = await authentication.changePassword(id, body.password, body.passwordCurrent)
+ const code = result.code
+ delete result.code
+ res.status(code).send(result)
}
}
res.status(200).end()
@@ -112,11 +109,16 @@ router.postAsync(['/', '/:id'], async (req, res) => {
// Post request for changing the password.
router.postAsync('/:id/password', async (req, res) => {
+ const id = req.params.id
+ const body = req.body
// Check if passwords are set.
- if (req.body.passwordCurrent && req.body.password) {
- if (req.body.passwordCurrent === req.body.password) return res.status(500).send({ auth: false, status: 'PASSWORD_ERROR', error_message: 'The provided password must be different than the old password.' })
- return authentication.changePassword(req, res)
- } else res.status(400).send({ auth: false, status: 'PASSWORD_MISSING', error_message: 'This service requires the current and the new password.' })
+ if (body.passwordCurrent && body.password) {
+ if (body.passwordCurrent === body.password) return res.status(500).send({ error: 'PASSWORD_ERROR', message: 'The provided password must be different than the old password.' })
+ const result = await authentication.changePassword(id, body.password, body.passwordCurrent)
+ const code = result.code
+ delete result.code
+ res.status(code).send(result)
+ } else res.status(400).send({ error: 'PASSWORD_MISSING', message: 'This service requires the current and the new password.' })
})
// Function for deleting a single user
diff --git a/server/lib/authentication.js b/server/lib/authentication.js
index dcbe880..58ae73c 100644
--- a/server/lib/authentication.js
+++ b/server/lib/authentication.js
@@ -6,119 +6,81 @@ var db = require(path.join(__appdir, 'lib', 'sequelize'))
var securePassword = require('secure-password')
var pwd = securePassword()
-module.exports = { loginCookie, loginToken, logout, verifyToken, signup, changePassword, validateEmail, validateUsername }
-
-// Authentifivation method for the frontend using secure httpOnly cookies. (POST)
-async function loginCookie (req, res) {
- var params = req.body
- var result = await verifyUser(res, params.username, params.password)
- if (result.status !== 'SUCCESS') return res.status(401).send(result)
-
- // The token has the form header.payload.signature
- // We split the cookie in header.payload and signature in two seperate cookies.
- // The signature cookie is httpOnly so JavaScript never has access to the full cookie.
- // Read more at: https://medium.com/lightrail/getting-token-authentication-right-in-a-stateless-single-page-application-57d0c6474e3
- const split = result.data.token.split('.')
- const headerPayload = split[0] + '.' + split[1]
- const signature = split[2]
- res.cookie('jwt_hp', headerPayload, { secure: true, httpOnly: false, sameSite: 'strict' })
- res.cookie('jwt_s', signature, { secure: true, httpOnly: true, sameSite: 'strict' })
- return res.status(200).send({ auth: true, status: 'VALID' })
-}
-
-// Authentification method for the API using the authorization header. (GET)
-async function loginToken (req, res) {
- var body = req.body
-
- var result = await verifyUser(res, body.username, body.password)
- if (result.status !== 'SUCCESS') return res.status(401).send(result)
- const token = result.data.token
- return res.status(200).send({ auth: true, token })
-}
+module.exports = { verifyUser, verifyToken, signup, changePassword, validateEmail, validateUsername }
// Method for creating a new user.
-async function signup (req, res) {
+async function signup (user) {
// TODO: Implement some security stuff. Not every user who call this request should be able to sign up.
- var params = req.body
- if (!params.username) return res.status(400).send({ auth: false, status: 'USER_MISSING', error_message: 'This service requires an username.' })
- if (!validateUsername(params.username)) return res.status(400).send({ auth: false, status: 'INVALID_USERNAME', error_message: 'Username does not fullfill the requirements. (No whitespaces)' })
- if (!params.password) return res.status(400).send({ auth: false, status: 'PASSWORD_MISSING', error_message: 'This services requires a password.' })
+ if (!user.username) return { code: 400, error: 'USER_MISSING', message: 'This service requires an username.' }
+ if (!validateUsername(user.username)) return { code: 400, error: 'INVALID_USERNAME', message: 'Username does not fullfill the requirements. (No whitespaces)' }
+ if (!user.password) return { code: 400, error: 'PASSWORD_MISSING', message: 'This services requires a password.' }
// if (!params.email) return res.status(500).send({ auth: false, status: 'EMAIL_MISSING', error_message: 'This services requires an email.' })
// Database and user validation.
- let userDb = await db.user.findOne({ where: { username: params.username } })
+ let userDb = await db.user.findOne({ where: { username: user.username } })
// User exists validation.
- if (userDb) return res.status(500).send({ auth: false, status: 'USER_ALREADY_EXISTS', error_message: 'The provided username already exists.' })
+ if (userDb) return { code: 500, error: 'USER_ALREADY_EXISTS', message: 'The provided username already exists.' }
// Password requirements validation.
- if (!validatePassword(params.password)) return res.status(400).send({ auth: false, status: 'PASSWORD_REQUIREMENTS', error_message: 'The password requirements are not fullfilled.' })
+ if (!validatePassword(user.password)) return { code: 400, error: 'PASSWORD_REQUIREMENTS', message: 'The password requirements are not fullfilled.' }
// Email validation.
- // if (!validateEmail(params.email)) return res.status(500).send({ auth: false, status: 'EMAIL_INVALID', error_message: 'The provided email is invalid.' })
- var userPassword = Buffer.from(params.password)
+ // if (!validateEmail(params.email)) return { code: 400, error: 'EMAIL_INVALID', message: 'The provided email is invalid.' }
+ var userPassword = Buffer.from(user.password)
// Register user
try {
var hash = await pwd.hash(userPassword)
} catch (error) {
- return res.status(500).send({ auth: false, status: 'PASSWORD_HASH_ERROR', error_message: 'Hashing the password failed.' })
+ return { code: 500, error: 'PASSWORD_HASH_ERROR', message: 'Hashing the password failed.' }
}
// Saving the non improved hash and creating the user in the db.
- const newUser = await db.user.create({ username: params.username, password: hash, email: params.email, name: params.name })
+ const newUser = await db.user.create({ username: user.username, password: hash, email: user.email, name: user.name })
+ if (!newUser) return { code: 500, error: 'USER_CREATE_ERROR', message: 'User could not be created.' }
// TODO: Username could also be used because those are unique as well.
var userId = newUser.id
// Verify & improving the hash.
- var result = await verifyHash(res, userPassword, hash, userId)
- if (result.status !== 'SUCCESS') return res.status(401).send(result)
-
- return newUser
+ var result = await verifyHash(userPassword, hash, userId)
+ if (result.error) return result
+ result.id = userId
+ return result
}
-// Logout method for the frontend. Deleting the cookies by overwriting them.
-function logout (req, res) {
- // End session properly.
- res.clearCookie('jwt_hp')
- res.clearCookie('jwt_s')
- return res.status(200).send()
- // TODO: Implement.. blacklisting for jwt's and destroy the cookies..
- // Maybe use express-jwt and use the rewoke function.
-}
-
-async function changePassword (req, res) {
+async function changePassword (id, password, passwordCurrent = '') {
// 1. Get the user and verify it's existence.
- let user = await db.user.findOne({ where: { id: req.params.id } })
- if (!user) return res.send({ status: 'INVALID_USER', error_message: 'There is no user with the provided id.' })
+ let user = await db.user.findOne({ where: { id: id } })
+ if (!user) return { code: 404, error: 'USER_NOTFOUND', message: 'There is no user with the provided id.' }
- const pwNew = Buffer.from(req.body.password)
+ const pwNew = Buffer.from(password)
// 2. Only if the current password is set we have to check if it's valid.
// This is because root can set passwords witout having the old ones.
// But the authentication if you can call this function without the currentPasswords needs to be in the API.
- if (req.body.passwordCurrent) {
+ if (passwordCurrent) {
// Verify the current hast with the provided current password.
- const pwCurrent = Buffer.from(req.body.passwordCurrent)
- var result = await verifyHash(res, pwCurrent, Buffer.from(user.password), user.id)
- if (result.status !== 'SUCCESS') return res.status(400).send(result)
+ const pwCurrent = Buffer.from(passwordCurrent)
+ var result = await verifyHash(pwCurrent, Buffer.from(user.password), user.id)
+ if (result.error) return result
}
// 3. Check if the new provided password fullfills the requirements
- if (!validatePassword(req.body.password)) return res.status(400).send({ status: 'PASSWORD_REQUIREMENTS', error_message: 'The provided password doesn\'t fullfill the requirements' })
+ if (!validatePassword(password)) return { code: 400, error: 'PASSWORD_REQUIREMENTS', message: 'The provided password doesn\'t fullfill the requirements' }
// 4. Calculate the new password hash.
try {
var hash = await pwd.hash(pwNew)
} catch (error) {
- return res.status(500).send({ auth: false, status: 'PASSWORD_HASH_ERROR', error_message: 'Hashing the password failed.' })
+ return { code: 500, error: 'PASSWORD_HASH_ERROR', message: 'Hashing the password failed.' }
}
- // 5. Write the hash in the dbW
+ // 5. Write the hash in the db.
await user.update({ password: hash })
// 6. Verify & improving the hash.
- await verifyHash(res, pwNew, hash, user.id)
- res.status(200).send({ auth: true, status: 'VALID' })
+ const res = await verifyHash(pwNew, hash, user.id)
+ return res
}
// Middleware function.
@@ -135,14 +97,14 @@ function verifyToken (req, res, next) {
} else if (req.cookies.jwt_hp && req.cookies.jwt_s) {
token = req.cookies.jwt_hp + '.' + req.cookies.jwt_s
} else {
- if (res) return res.status(401).send({ auth: false, status: 'TOKEN_MISSING', error_message: 'This service requires a token.' })
+ if (res) return res.status(401).send({ error: 'TOKEN_MISSING', message: 'This service requires a token.' })
else return next(new Error('TOKEN_MISSING'))
}
// Verify the token with the secret.
jwt.verify(token, config.secret, err => {
if (err) {
- if (res) return res.status(401).send({ auth: false, status: 'TOKEN_INVALID', error_message: 'The provided token is invalid.' })
+ if (res) return res.status(401).send({ error: 'TOKEN_INVALID', message: 'The provided token is invalid.' })
else return next(new Error('TOKEN_INVALID'))
}
req.token = token
@@ -153,85 +115,85 @@ function verifyToken (req, res, next) {
db.user.findOne({ where: { id: req.user.id } }).then(user => {
if (user) next()
else {
- if (res) return res.status(401).send({ auth: false, status: 'TOKEN_INVALID', error_message: 'The token is from an invalid userid.' })
+ if (res) return res.status(401).send({ error: 'TOKEN_INVALID', message: 'The token is from an invalid userid.' })
else return next(new Error('TOKEN_INVALID'))
}
})
})
}
-// Function for validating the e-mail.
-function validateEmail (email) {
- // TODO: Remove if email is not optional
- if (email === '') return true
-
- // Removed escape before [ because eslint told me so.
- var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
- return re.test(String(email).toLowerCase())
-}
-
-// ################################################
-// ############## Helper function #################
-// ################################################
-
// The function for verifying a user.
-async function verifyUser (res, username, password) {
- if (!username) return { auth: false, status: 'USER_MISSING', error_message: 'This service requires an username.' }
- if (!password) return { auth: false, status: 'PASSWORD_MISSING', error_message: 'This services requires a password.' }
+async function verifyUser (username, password) {
+ if (!username) return { code: 400, error: 'USER_MISSING', message: 'This service requires an username.' }
+ if (!password) return { code: 400, error: 'PASSWORD_MISSING', message: 'This services requires a password.' }
const userDb = await db.user.findOne({ where: { username: username } })
- if (!userDb) {
- return { auth: false, status: 'USER_NOTFOUND', error_message: 'User does not exist.' }
- }
+ if (!userDb) return { code: 404, error: 'USER_NOTFOUND', message: 'User does not exist.' }
+
var user = {}
user.id = userDb.id
var userPassword = Buffer.from(password)
var hash = Buffer.from(userDb.password)
// Verify & improving the hash.
- var result = await verifyHash(res, userPassword, hash, user.id)
- if (result.status !== 'SUCCESS') return result
+ var result = await verifyHash(userPassword, hash, user.id)
+ if (result.error) return result
try {
var token = await jwt.sign({ user }, config.secret, { expiresIn: '12h' })
} catch (error) {
- return { auth: false, status: 'JWT_ERROR', error_message: 'Jwt sign failed.' }
+ return { code: 500, error: 'JWT_ERROR', message: 'Jwt sign failed.' }
}
- return { auth: true, status: 'SUCCESS', data: { token: token } }
+ result.token = token
+ return result
+}
+
+// Function for validating the e-mail.
+function validateEmail (email) {
+ // TODO: Remove if email is not optional
+ if (email === '') return true
+
+ // Removed escape before [ because eslint told me so.
+ var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
+ return re.test(String(email).toLowerCase())
}
+// ################################################
+// ############## Helper function #################
+// ################################################
+
// The verify hash function from the secure-passwords with error handling.
-async function verifyHash (res, password, hash, userId) {
+async function verifyHash (password, hash, userId) {
// Check if the hash in the database fullfills the requirements needed for pwd.verify.
// Hash will be a Buffer of length SecurePassword.HASH_BYTES.
- if (hash.length !== securePassword.HASH_BYTES) return { auth: false, status: 'DATABASE_HASH_INVALID', error_message: 'The hash in the database is corrupted.' }
+ if (hash.length !== securePassword.HASH_BYTES) return { code: 500, error: 'DATABASE_HASH_INVALID', message: 'The hash in the database is corrupted.' }
// Password must be a Buffer of length SecurePassword.PASSWORD_BYTES_MIN - SecurePassword.PASSWORD_BYTES_MAX.
- if (password.length < securePassword.PASSWORD_BYTES_MIN || password.length > securePassword.PASSWORD_BYTES_MAX) return { auth: false, status: 'PASSWORD_INVALID', error_message: 'The provided password has an invalid length.' }
+ if (password.length < securePassword.PASSWORD_BYTES_MIN || password.length > securePassword.PASSWORD_BYTES_MAX) return { code: 401, error: 'PASSWORD_INVALID', message: 'The provided password has an invalid length.' }
// Verification of the password. Rehash if needed.
try {
var result = await pwd.verify(password, hash)
} catch (error) {
- return { auth: false, status: 'PASSWORD_VERIFY_ERROR', error_message: 'Verifying the password failed.' }
+ return { code: 500, error: 'PASSWORD_VERIFY_ERROR', message: 'Verifying the password failed.' }
}
// Check the state of the verification.
- if (result === securePassword.INVALID_UNRECOGNIZED_HASH) return { auth: false, status: 'INVALID_UNRECOGNIZED_HASH', error_message: 'This hash was not made with secure-password. Attempt legacy algorithm.' }
- if (result === securePassword.INVALID) return { auth: false, status: 'PASSWORD_INVALID', error_message: 'The provided password is invalid.' }
- if (result === securePassword.VALID) return { status: 'SUCCESS' }
+ if (result === securePassword.INVALID_UNRECOGNIZED_HASH) return { code: 500, error: 'INVALID_UNRECOGNIZED_HASH', message: 'This hash was not made with secure-password. Attempt legacy algorithm.' }
+ if (result === securePassword.INVALID) return { code: 401, error: 'PASSWORD_INVALID', message: 'The provided password is invalid.' }
+ if (result === securePassword.VALID) return { code: 200 }
if (result === securePassword.VALID_NEEDS_REHASH) {
try {
var improvedHash = await pwd.hash(password)
} catch (error) {
- return { auth: false, status: 'PASSWORD_REHASH_ERROR', error_message: 'Rehashing the password failed.' }
+ return { code: 500, error: 'PASSWORD_REHASH_ERROR', message: 'Rehashing the password failed.' }
}
// Update the improved hash in the db.
const user = await db.user.findOne({ where: { id: userId } })
await user.updateAttributes({
password: improvedHash
})
- return { status: 'SUCCESS' }
+ return { code: 200 }
}
}
diff --git a/webapp/src/components/AccountModule.vue b/webapp/src/components/AccountModule.vue
index 11395cb..9d22715 100644
--- a/webapp/src/components/AccountModule.vue
+++ b/webapp/src/components/AccountModule.vue
@@ -317,7 +317,7 @@ export default {
this.cancelEditPassword()
this.$snackbar({ color: 'success', text: this.$t('passwordChanged') })
}).catch(error => {
- if (error.response.data.status === 'PASSWORD_INVALID') {
+ if (error.response.data.error === 'PASSWORD_INVALID') {
this.invalidPasswordError = true
this.passwordNew = ''
this.passwordConfirm = ''
diff --git a/webapp/src/components/StartPageLogin.vue b/webapp/src/components/StartPageLogin.vue
index 87d4054..3e4b5b8 100644
--- a/webapp/src/components/StartPageLogin.vue
+++ b/webapp/src/components/StartPageLogin.vue
@@ -75,7 +75,7 @@ export default {
},
login () {
if (this.$refs.form.validate()) {
- this.$http.post('/api/authentication/login', { username: this.username, password: this.password })
+ this.$http.post('/api/authentication/cookies', { username: this.username, password: this.password })
.then(response => {
const nextRoute = this.$store.state.loginRedirect
if (nextRoute) this.$router.replace(nextRoute)
@@ -83,12 +83,12 @@ export default {
this.$socket.open()
})
.catch(error => {
- if (error.response.data.status === 'USER_NOTFOUND') {
+ if (error.response.data.error === 'USER_NOTFOUND') {
this.usernameError = true
- } else if (error.response.data.status === 'PASSWORD_INVALID') {
+ } else if (error.response.data.error === 'PASSWORD_INVALID') {
this.passwordError = true
} else {
- this.$snackbar({ color: 'error', text: error.response.data.error_message })
+ this.$snackbar({ color: 'error', text: error.response.data.message })
}
this.$refs.form.validate()
})
diff --git a/webapp/src/components/StartPageSetup.vue b/webapp/src/components/StartPageSetup.vue
index 1bde01c..0d111bc 100644
--- a/webapp/src/components/StartPageSetup.vue
+++ b/webapp/src/components/StartPageSetup.vue
@@ -67,7 +67,7 @@ export default {
this.$snackbar({ color: 'success', text: this.$t('rootCreated'), timeout: 15000 })
this.$router.replace({ name: 'login' })
}).catch(error => {
- this.$snackbar({ color: 'error', text: error.response.data.error_message, timeout: 15000 })
+ this.$snackbar({ color: 'error', text: error.response.data.message, timeout: 15000 })
})
}
}
diff --git a/webapp/src/components/UserModuleDelete.vue b/webapp/src/components/UserModuleDelete.vue
index 1487be7..c0c54e1 100644
--- a/webapp/src/components/UserModuleDelete.vue
+++ b/webapp/src/components/UserModuleDelete.vue
@@ -55,6 +55,12 @@ export default {
await this.$http.post('/api/users/?delete', {
ids: this.dialog.info.selected.map(x => x.id)
})
+ if (this.doIDeleteMyself) {
+ this.$http.post('/api/authentication/logout').then(response => {
+ this.$router.push('/login')
+ this.$socket.close()
+ })
+ }
this.$store.dispatch('users/loadData')
this.setDialog({ show: false })
}
diff --git a/webapp/src/components/UserModuleEdit.vue b/webapp/src/components/UserModuleEdit.vue
index e4f3cb0..e134a7e 100644
--- a/webapp/src/components/UserModuleEdit.vue
+++ b/webapp/src/components/UserModuleEdit.vue
@@ -74,7 +74,7 @@ export default {
this.setDialog({ show: false })
this.$snackbar({ color: 'success', text: this.dialog.info.id ? this.$t('userUpdated') : this.$t('userCreated') })
}).catch(error => {
- if (error.response.data.status === 'USER_ALREADY_EXISTS') {
+ if (error.response.data.error === 'USER_ALREADY_EXISTS') {
this.$refs.editComponent.setUsernameTakenError()
}
})
diff --git a/webapp/src/main.js b/webapp/src/main.js
index 70afb40..9604fd1 100644
--- a/webapp/src/main.js
+++ b/webapp/src/main.js
@@ -60,7 +60,7 @@ Vue.use(VueCodemirror, {
Vue.use(VueTouch)
axios.interceptors.response.use(null, error => {
- if (error && error.response.status === 401) {
+ if (error && error.response.error === 401) {
axios.post('/api/authentication/logout').then(response => {
router.push('/login')
socket.close()