ripple login state across wiki sites open within wiki domain

This commit is contained in:
Paul Rodwell
2016-05-29 19:28:46 +01:00
parent a428f92dfc
commit 0c55a09cf5
2 changed files with 24 additions and 4 deletions

View File

@ -35,12 +35,12 @@ claim_wiki = () ->
if response.ok if response.ok
response.json().then (json) -> response.json().then (json) ->
ownerName = json.ownerName ownerName = json.ownerName
update_footer ownerName, true, true update_footer ownerName, true
else else
console.log 'Attempt to claim site failed', response console.log 'Attempt to claim site failed', response
update_footer = (ownerName, isAuthenticated, isOwner) -> update_footer = (ownerName, isAuthenticated) ->
# we update the owner and the login state in the footer, and # we update the owner and the login state in the footer, and
# populate the security dialog # populate the security dialog
@ -65,7 +65,8 @@ update_footer = (ownerName, isAuthenticated, isOwner) ->
isAuthenticated = false isAuthenticated = false
isOwner = false isOwner = false
user = '' user = ''
update_footer ownerName, isAuthenticated, isOwner document.cookie = "state=loggedOut" + ";domain=." + settings.cookieDomain + "; path=/; max-age=60;"
update_footer ownerName, isAuthenticated
else else
console.log 'logout failed: ', response console.log 'logout failed: ', response
else else
@ -97,6 +98,22 @@ setup = (user) ->
# we will replace font-awesome with a small number of svg icons at a later date... # we will replace font-awesome with a small number of svg icons at a later date...
if (!$("link[href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css']").length) if (!$("link[href='https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css']").length)
$('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">').appendTo("head") $('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">').appendTo("head")
# signon could happen in a different window, so listen for cookie changes
lastCookie = document.cookie
window.setInterval ->
currentCookie = document.cookie
if currentCookie != lastCookie
console.log "Cookie changed"
unless document.cookie.match('(?:^|;)\\s?state=(.*?)(?:;|$)') is null
try
switch document.cookie.match('(?:^|;)\\s?state=(.*?)(?:;|$)')[1]
when 'loggedIn' then isAuthenticated = true
when 'loggedOut' then isAuthenticated = false
update_footer ownerName, isAuthenticated
lastCookie = currentCookie
, 100
wiki.getScript '/security/winchan.js' wiki.getScript '/security/winchan.js'
if (!$("link[href='/security/style.css']").length) if (!$("link[href='/security/style.css']").length)
$('<link rel="stylesheet" href="/security/style.css">').appendTo("head") $('<link rel="stylesheet" href="/security/style.css">').appendTo("head")
@ -114,6 +131,7 @@ setup = (user) ->
dialogHost = settings.wikiHost dialogHost = settings.wikiHost
else else
dialogHost = window.location.hostname dialogHost = window.location.hostname
settings.cookieDomain = dialoghost
if settings.useHttps if settings.useHttps
dialogProtocol = 'https:' dialogProtocol = 'https:'
else else
@ -126,7 +144,7 @@ setup = (user) ->
settings.dialogURL = dialogProtocol + '//' + dialogHost + '/auth/loginDialog' settings.dialogURL = dialogProtocol + '//' + dialogHost + '/auth/loginDialog'
settings.relayURL = dialogProtocol + '//' + dialogHost + '/auth/relay.html' settings.relayURL = dialogProtocol + '//' + dialogHost + '/auth/relay.html'
update_footer ownerName, isAuthenticated, isOwner update_footer ownerName, isAuthenticated
else else
console.log 'Unable to fetch client settings: ', response console.log 'Unable to fetch client settings: ', response

View File

@ -17,6 +17,8 @@
</body> </body>
<script src="/security/winchan.js"></script> <script src="/security/winchan.js"></script>
<script> <script>
document.cookie = "state=loggedIn" + ";domain=." + window.location.hostname + "; path=/; max-age=60;"
var wc = WinChan.onOpen(function(origin, r, cb) { var wc = WinChan.onOpen(function(origin, r, cb) {
cb({ cb({
done: true, done: true,