1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-01-23 17:32:20 +00:00
overleaf/services/web/app/coffee/Features/User/UserCreator.coffee

34 lines
698 B
CoffeeScript
Raw Normal View History

2014-02-12 10:23:40 +00:00
User = require("../../models/User").User
logger = require("logger-sharelatex")
metrics = require('metrics-sharelatex')
2014-02-12 10:23:40 +00:00
2017-03-17 14:55:41 +00:00
module.exports = UserCreator =
2014-02-12 10:23:40 +00:00
createNewUser: (opts, callback)->
logger.log opts:opts, "creating new user"
2014-02-12 10:23:40 +00:00
user = new User()
username = opts.email.match(/^[^@]*/)
2017-08-07 10:24:04 +00:00
if !opts.first_name? or opts.first_name == ""
opts.first_name = username[0]
2017-08-07 10:24:04 +00:00
for key, value of opts
user[key] = value
user.ace.syntaxValidation = true
user.featureSwitches?.pdfng = true
2018-05-28 14:08:37 +00:00
user.emails = [
email: user.email
createdAt: new Date()
]
2014-02-12 10:23:40 +00:00
user.save (err)->
callback(err, user)
2017-03-17 14:55:41 +00:00
metrics.timeAsyncMethod(
UserCreator, 'createNewUser',
'mongo.UserCreator',
logger
)