2018-09-20 09:59:30 -04:00
|
|
|
V1Api = require './V1Api'
|
|
|
|
Settings = require 'settings-sharelatex'
|
|
|
|
logger = require 'logger-sharelatex'
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = V1Handler =
|
|
|
|
|
|
|
|
authWithV1: (email, password, callback=(err, isValid, v1Profile)->) ->
|
|
|
|
V1Api.request {
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/v1/sharelatex/login',
|
|
|
|
json: {email, password},
|
|
|
|
expectedStatusCodes: [403]
|
|
|
|
}, (err, response, body) ->
|
|
|
|
if err?
|
|
|
|
logger.err {email, err},
|
|
|
|
"[V1Handler] error while talking to v1 login api"
|
|
|
|
return callback(err)
|
|
|
|
if response.statusCode in [200, 403]
|
|
|
|
isValid = body.valid
|
|
|
|
userProfile = body.user_profile
|
|
|
|
logger.log {email, isValid, v1UserId: body?.user_profile?.id},
|
|
|
|
"[V1Handler] got response from v1 login api"
|
|
|
|
callback(null, isValid, userProfile)
|
|
|
|
else
|
|
|
|
err = new Error("Unexpected status from v1 login api: #{response.statusCode}")
|
|
|
|
callback(err)
|
2018-12-14 10:45:18 -05:00
|
|
|
|
2018-12-18 06:14:41 -05:00
|
|
|
doPasswordReset: (v1_user_id, password, callback=(err, created)->) ->
|
|
|
|
logger.log({v1_user_id},
|
2018-12-14 10:45:18 -05:00
|
|
|
"sending password reset request to v1 login api")
|
|
|
|
V1Api.request {
|
|
|
|
method: 'POST'
|
|
|
|
url: "/api/v1/sharelatex/reset_password"
|
|
|
|
json: {
|
2018-12-18 06:14:41 -05:00
|
|
|
user_id: v1_user_id,
|
|
|
|
password: password
|
2018-12-14 10:45:18 -05:00
|
|
|
}
|
|
|
|
expectedStatusCodes: [200]
|
|
|
|
}, (err, response, body) ->
|
|
|
|
if err?
|
2018-12-18 06:14:41 -05:00
|
|
|
logger.err {v1_user_id, err}, "error while talking to v1 password reset api"
|
2018-12-14 10:45:18 -05:00
|
|
|
return callback(err, false)
|
|
|
|
if response.statusCode in [200]
|
2018-12-18 06:14:41 -05:00
|
|
|
logger.log {v1_user_id, changed: true}, "got success response from v1 password reset api"
|
2018-12-14 10:45:18 -05:00
|
|
|
callback(null, true)
|
|
|
|
else
|
|
|
|
err = new Error("Unexpected status from v1 password reset api: #{response.statusCode}")
|
|
|
|
callback(err, false)
|
2019-01-07 06:15:38 -05:00
|
|
|
|
|
|
|
getDocExported: (token, callback=(err, info)->) ->
|
|
|
|
# default to not exported
|
|
|
|
return callback(null, {
|
|
|
|
exported: false
|
|
|
|
exporting: false
|
|
|
|
}) unless Settings.apis?.v1?
|
|
|
|
|
|
|
|
V1Api.request { url: "/api/v1/sharelatex/docs/#{token}/exported_to_v2" }, (err, response, body) ->
|
|
|
|
return callback err if err?
|
|
|
|
callback null, body
|