mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge branch 'master' into as-v1-dash-link
This commit is contained in:
commit
d3b4567a5c
1 changed files with 17 additions and 15 deletions
|
@ -1,6 +1,9 @@
|
|||
request = require("./request")
|
||||
_ = require("underscore")
|
||||
settings = require("settings-sharelatex")
|
||||
{db, ObjectId} = require("../../../../app/js/infrastructure/mongojs")
|
||||
UserModel = require("../../../../app/js/models/User").User
|
||||
AuthenticationManager = require("../../../../app/js/Features/Authentication/AuthenticationManager")
|
||||
|
||||
count = 0
|
||||
|
||||
|
@ -17,20 +20,20 @@ class User
|
|||
login: (callback = (error) ->) ->
|
||||
@getCsrfToken (error) =>
|
||||
return callback(error) if error?
|
||||
@request.post {
|
||||
url: "/register" # Register will log in, but also ensure user exists
|
||||
json:
|
||||
email: @email
|
||||
password: @password
|
||||
}, (error, response, body) =>
|
||||
filter = {@email}
|
||||
options = {upsert: true, new: true, setDefaultsOnInsert: true}
|
||||
UserModel.findOneAndUpdate filter, {}, options, (error, user) =>
|
||||
return callback(error) if error?
|
||||
db.users.findOne {email: @email}, (error, user) =>
|
||||
AuthenticationManager.setUserPassword user._id, @password, (error) =>
|
||||
return callback(error) if error?
|
||||
@id = user?._id?.toString()
|
||||
@_id = user?._id?.toString()
|
||||
@first_name = user?.first_name
|
||||
@referal_id = user?.referal_id
|
||||
callback()
|
||||
@request.post {
|
||||
url: "/login"
|
||||
json: { @email, @password }
|
||||
}, callback
|
||||
|
||||
logout: (callback = (error) ->) ->
|
||||
@getCsrfToken (error) =>
|
||||
|
@ -104,8 +107,10 @@ class User
|
|||
}, (error, response, body) ->
|
||||
return callback(error) if error?
|
||||
if !body?.project_id?
|
||||
console.error "SOMETHING WENT WRONG CREATING PROJECT", response.statusCode, response.headers["location"], body
|
||||
callback(null, body.project_id)
|
||||
error = new Error("SOMETHING WENT WRONG CREATING PROJECT", response.statusCode, response.headers["location"], body)
|
||||
callback error
|
||||
else
|
||||
callback(null, body.project_id)
|
||||
|
||||
deleteProject: (project_id, callback=(error)) ->
|
||||
@request.delete {
|
||||
|
@ -161,13 +166,10 @@ class User
|
|||
|
||||
getCsrfToken: (callback = (error) ->) ->
|
||||
@request.get {
|
||||
url: "/register"
|
||||
url: "/dev/csrf"
|
||||
}, (err, response, body) =>
|
||||
return callback(err) if err?
|
||||
csrfMatches = body.match("window.csrfToken = \"(.*?)\";")
|
||||
if !csrfMatches?
|
||||
return callback(new Error("no csrf token found"))
|
||||
@csrfToken = csrfMatches[1]
|
||||
@csrfToken = body
|
||||
@request = @request.defaults({
|
||||
headers:
|
||||
"x-csrf-token": @csrfToken
|
||||
|
|
Loading…
Reference in a new issue