mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 13:47:33 +01:00
31 lines
790 B
JavaScript
31 lines
790 B
JavaScript
import nconf from 'nconf';
|
|
import shortid from 'short-uuid';
|
|
|
|
import { NotAuthorized } from '../errors';
|
|
|
|
const COMMUNITY_MANAGER_EMAIL = nconf.get('EMAILS_COMMUNITY_MANAGER_EMAIL');
|
|
const translator = shortid('0123456789abcdefghijklmnopqrstuvwxyz');
|
|
|
|
export function generateUsername () {
|
|
const newName = `hb-${translator.new()}`;
|
|
return newName.substring(0, 20);
|
|
}
|
|
|
|
export function loginRes (user, req, res) {
|
|
if (user.auth.blocked) {
|
|
throw new NotAuthorized(res.t(
|
|
'accountSuspended',
|
|
{ communityManagerEmail: COMMUNITY_MANAGER_EMAIL, userId: user._id },
|
|
));
|
|
}
|
|
|
|
const responseData = {
|
|
id: user._id,
|
|
apiToken: user.apiToken,
|
|
newUser: user.newUser || false,
|
|
username: user.auth.local.username,
|
|
};
|
|
|
|
return res.respond(200, responseData);
|
|
}
|