1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/user.js

43 lines
1.0 KiB
JavaScript
Raw Normal View History

'use strict';
const gravatarUrl = require('gravatar-url');
2020-07-31 22:15:09 +02:00
const Joi = require('joi');
module.exports = class User {
constructor({
2020-05-12 23:05:26 +02:00
id,
name,
email,
username,
imageUrl,
permissions,
2020-05-12 23:05:26 +02:00
seenAt,
loginAttempts,
createdAt,
} = {}) {
if (!username && !email) {
throw new TypeError('Username or Email us reuqired');
}
Joi.assert(email, Joi.string().email(), 'Email');
Joi.assert(username, Joi.string(), 'Username');
Joi.assert(name, Joi.string(), 'Name');
2020-05-12 23:05:26 +02:00
this.id = id;
this.name = name;
this.username = username;
this.email = email;
this.permissions = permissions;
this.imageUrl = imageUrl || this.generateImageUrl();
2020-05-12 23:05:26 +02:00
this.seenAt = seenAt;
this.loginAttempts = loginAttempts;
this.createdAt = createdAt;
}
generateImageUrl() {
return gravatarUrl(this.email || this.username, {
size: '42',
default: 'retro',
});
}
};