mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 04:15:25 -05:00
Merge pull request #1726 from sharelatex/hb-sso-password-setting
Check for password from v1 before showing password change form GitOrigin-RevId: 58ef0f9d3c8ce3ab7ca51d3538f1be13f05d4658
This commit is contained in:
parent
16f905358a
commit
5517adcbd1
3 changed files with 41 additions and 8 deletions
|
@ -3,10 +3,11 @@ UserSessionsManager = require("./UserSessionsManager")
|
||||||
ErrorController = require("../Errors/ErrorController")
|
ErrorController = require("../Errors/ErrorController")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
Settings = require("settings-sharelatex")
|
Settings = require("settings-sharelatex")
|
||||||
|
request = require 'request'
|
||||||
fs = require('fs')
|
fs = require('fs')
|
||||||
AuthenticationController = require('../Authentication/AuthenticationController')
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
||||||
|
|
||||||
module.exports =
|
module.exports = UserPagesController =
|
||||||
|
|
||||||
registerPage : (req, res)->
|
registerPage : (req, res)->
|
||||||
sharedProjectData =
|
sharedProjectData =
|
||||||
|
@ -72,12 +73,17 @@ module.exports =
|
||||||
shouldAllowEditingDetails = !(Settings?.ldap?.updateUserDetailsOnLogin) and !(Settings?.saml?.updateUserDetailsOnLogin)
|
shouldAllowEditingDetails = !(Settings?.ldap?.updateUserDetailsOnLogin) and !(Settings?.saml?.updateUserDetailsOnLogin)
|
||||||
UserGetter.getUser user_id, (err, user)->
|
UserGetter.getUser user_id, (err, user)->
|
||||||
return next(err) if err?
|
return next(err) if err?
|
||||||
res.render 'user/settings',
|
|
||||||
title:'account_settings'
|
UserPagesController._hasPassword user, (err, passwordPresent) ->
|
||||||
user: user,
|
if err
|
||||||
shouldAllowEditingDetails: shouldAllowEditingDetails
|
logger.err {err}, "error getting password status from v1"
|
||||||
languages: Settings.languages,
|
res.render 'user/settings',
|
||||||
accountSettingsTabActive: true
|
title:'account_settings'
|
||||||
|
user: user,
|
||||||
|
hasPassword: passwordPresent,
|
||||||
|
shouldAllowEditingDetails: shouldAllowEditingDetails
|
||||||
|
languages: Settings.languages,
|
||||||
|
accountSettingsTabActive: true
|
||||||
|
|
||||||
sessionsPage: (req, res, next) ->
|
sessionsPage: (req, res, next) ->
|
||||||
user = AuthenticationController.getSessionUser(req)
|
user = AuthenticationController.getSessionUser(req)
|
||||||
|
@ -89,3 +95,19 @@ module.exports =
|
||||||
res.render 'user/sessions',
|
res.render 'user/sessions',
|
||||||
title: "sessions"
|
title: "sessions"
|
||||||
sessions: sessions
|
sessions: sessions
|
||||||
|
|
||||||
|
_hasPassword: (user, callback) ->
|
||||||
|
request.get {
|
||||||
|
url: "#{Settings.apis.v1.url}/api/v1/sharelatex/has_password"
|
||||||
|
auth: { user: Settings.apis.v1.user, pass: Settings.apis.v1.pass }
|
||||||
|
body: { user_id: user?.overleaf?.id }
|
||||||
|
timeout: 20 * 1000
|
||||||
|
json: true
|
||||||
|
}, (err, response, body) ->
|
||||||
|
if err
|
||||||
|
# for errors assume password and show password setting form
|
||||||
|
return callback(err, true)
|
||||||
|
else if body?.has_password
|
||||||
|
return callback(err, true)
|
||||||
|
return callback(err, false)
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,9 @@ block content
|
||||||
if externalAuthenticationSystemUsed() && !settings.overleaf
|
if externalAuthenticationSystemUsed() && !settings.overleaf
|
||||||
p
|
p
|
||||||
Password settings are managed externally
|
Password settings are managed externally
|
||||||
|
else if !hasPassword
|
||||||
|
p
|
||||||
|
| #[a(href="/user/password/reset", target='_blank') #{translate("no_existing_password")}]
|
||||||
else
|
else
|
||||||
- var submitAction
|
- var submitAction
|
||||||
if settings.overleaf
|
if settings.overleaf
|
||||||
|
|
|
@ -10,7 +10,13 @@ describe "UserPagesController", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
||||||
@settings = {}
|
@settings = {
|
||||||
|
apis:
|
||||||
|
v1:
|
||||||
|
url: 'some.host'
|
||||||
|
user: 'one'
|
||||||
|
pass: 'two'
|
||||||
|
}
|
||||||
@user =
|
@user =
|
||||||
_id: @user_id = "kwjewkl"
|
_id: @user_id = "kwjewkl"
|
||||||
features:{}
|
features:{}
|
||||||
|
@ -39,6 +45,7 @@ describe "UserPagesController", ->
|
||||||
"../Errors/ErrorController": @ErrorController
|
"../Errors/ErrorController": @ErrorController
|
||||||
'../Dropbox/DropboxHandler': @DropboxHandler
|
'../Dropbox/DropboxHandler': @DropboxHandler
|
||||||
'../Authentication/AuthenticationController': @AuthenticationController
|
'../Authentication/AuthenticationController': @AuthenticationController
|
||||||
|
'request': @request = sinon.stub()
|
||||||
@req =
|
@req =
|
||||||
query:{}
|
query:{}
|
||||||
session:
|
session:
|
||||||
|
@ -133,6 +140,7 @@ describe "UserPagesController", ->
|
||||||
|
|
||||||
describe "settingsPage", ->
|
describe "settingsPage", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@request.get = sinon.stub().callsArgWith(1, null, {statusCode: 200}, {has_password: true})
|
||||||
@UserGetter.getUser = sinon.stub().callsArgWith(1, null, @user)
|
@UserGetter.getUser = sinon.stub().callsArgWith(1, null, @user)
|
||||||
|
|
||||||
it "should render user/settings", (done)->
|
it "should render user/settings", (done)->
|
||||||
|
|
Loading…
Reference in a new issue