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