mirror of
https://github.com/mollersuite/monofile.git
synced 2024-10-06 20:16:25 -07:00
change nickname added to apiv1
This commit is contained in:
parent
e574438ea8
commit
03fa036e38
|
@ -11,6 +11,7 @@ import * as Accounts from '../../../lib/accounts'
|
|||
import * as Authentication from '../../../lib/auth'
|
||||
import { assertAPI, getAccount, noAPIAccess, requiresAccount, requiresPermissions } from "../../../lib/middleware";
|
||||
import ServeError from "../../../lib/errors";
|
||||
import { sendMail } from '../../../lib/mail';
|
||||
|
||||
const Configuration = require(`${process.cwd()}/config.json`)
|
||||
|
||||
|
@ -173,5 +174,57 @@ module.exports = function(files: Files) {
|
|||
}
|
||||
)
|
||||
|
||||
router.put("/me/name",
|
||||
requiresAccount,
|
||||
noAPIAccess,
|
||||
parser,
|
||||
(req, res) => {
|
||||
const Account = res.locals.acc as Accounts.Account
|
||||
|
||||
const newUsername = req.body.username
|
||||
|
||||
if (
|
||||
typeof newUsername != "string"
|
||||
||
|
||||
newUsername.length < 3
|
||||
||
|
||||
req.body.username.length > 20
|
||||
) {
|
||||
ServeError(res, 400, "username must be between 3 and 20 characters in length")
|
||||
return
|
||||
}
|
||||
|
||||
if (Accounts.getFromUsername(newUsername)) {
|
||||
ServeError(res, 400, "account with this username already exists")
|
||||
}
|
||||
|
||||
if (
|
||||
(
|
||||
newUsername.match(/[A-Za-z0-9_\-\.]+/)
|
||||
||
|
||||
[]
|
||||
)[0] != req.body.username
|
||||
) {
|
||||
ServeError(res, 400, "username contains invalid characters")
|
||||
return
|
||||
}
|
||||
|
||||
Account.username = newUsername
|
||||
Accounts.save()
|
||||
|
||||
if (Account.email) {
|
||||
sendMail(
|
||||
Account.email,
|
||||
`Your login details have been updated`,
|
||||
`<b>Hello there!</b> Your username has been updated to <span username>${newUsername}</span>. Please update your devices accordingly. Thank you for using monofile.`
|
||||
).then(() => {
|
||||
res.send("OK")
|
||||
}).catch((err) => {})
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
return router
|
||||
}
|
Loading…
Reference in a new issue