mirror of https://github.com/requarks/wiki
parent
85717bd369
commit
cb0d86906f
@ -0,0 +1,30 @@
|
||||
class BaseError extends Error {
|
||||
constructor (message) {
|
||||
super(message)
|
||||
this.name = this.constructor.name
|
||||
Error.captureStackTrace(this, this.constructor)
|
||||
}
|
||||
}
|
||||
|
||||
class AuthGenericError extends BaseError { constructor (message = 'An unexpected error occured during login.') { super(message) } }
|
||||
class AuthLoginFailed extends BaseError { constructor (message = 'Invalid email / username or password.') { super(message) } }
|
||||
class AuthProviderInvalid extends BaseError { constructor (message = 'Invalid authentication provider.') { super(message) } }
|
||||
class AuthTFAFailed extends BaseError { constructor (message = 'Incorrect TFA Security Code.') { super(message) } }
|
||||
class AuthTFAInvalid extends BaseError { constructor (message = 'Invalid TFA Security Code or Login Token.') { super(message) } }
|
||||
class BruteInstanceIsInvalid extends BaseError { constructor (message = 'Invalid Brute Force Instance.') { super(message) } }
|
||||
class BruteTooManyAttempts extends BaseError { constructor (message = 'Too many attempts! Try again later.') { super(message) } }
|
||||
class LocaleInvalidNamespace extends BaseError { constructor (message = 'Invalid locale or namespace.') { super(message) } }
|
||||
class UserCreationFailed extends BaseError { constructor (message = 'An unexpected error occured during user creation.') { super(message) } }
|
||||
|
||||
module.exports = {
|
||||
BaseError,
|
||||
AuthGenericError,
|
||||
AuthLoginFailed,
|
||||
AuthProviderInvalid,
|
||||
AuthTFAFailed,
|
||||
AuthTFAInvalid,
|
||||
BruteInstanceIsInvalid,
|
||||
BruteTooManyAttempts,
|
||||
LocaleInvalidNamespace,
|
||||
UserCreationFailed
|
||||
}
|
@ -1,15 +1,25 @@
|
||||
'use strict'
|
||||
|
||||
/* global appdata, appconfig */
|
||||
|
||||
const _ = require('lodash')
|
||||
const Promise = require('bluebird')
|
||||
const crypto = require('crypto')
|
||||
|
||||
module.exports = {
|
||||
sanitizeCommitUser (user) {
|
||||
let wlist = new RegExp('[^a-zA-Z0-9-_.\',& ' + appdata.regex.cjk + appdata.regex.arabic + ']', 'g')
|
||||
return {
|
||||
name: _.chain(user.name).replace(wlist, '').trim().value(),
|
||||
email: appconfig.git.showUserEmail ? user.email : appconfig.git.serverEmail
|
||||
}
|
||||
// let wlist = new RegExp('[^a-zA-Z0-9-_.\',& ' + appdata.regex.cjk + appdata.regex.arabic + ']', 'g')
|
||||
// return {
|
||||
// name: _.chain(user.name).replace(wlist, '').trim().value(),
|
||||
// email: appconfig.git.showUserEmail ? user.email : appconfig.git.serverEmail
|
||||
// }
|
||||
},
|
||||
/**
|
||||
* Generate a random token
|
||||
*
|
||||
* @param {any} length
|
||||
* @returns
|
||||
*/
|
||||
async generateToken (length) {
|
||||
return Promise.fromCallback(clb => {
|
||||
crypto.randomBytes(length, clb)
|
||||
}).then(buf => {
|
||||
return buf.toString('hex')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue