Commit 686fe9cf authored by Randall Leeds's avatar Randall Leeds

Revert "Merge pull request #903 from hypothesis/882-login-from-code-3"

This reverts commit ba92681d2fed403a00b49e13697b13aa37e0e855, reversing
changes made to 71dd9111bad26d5d4235ecdd1b42c60591cd2f35.
parent 57928a30
......@@ -31,13 +31,6 @@ class App
authentication.persona = null
authentication.token = null
if oldValue?
# Tell the providers that we have logged out
setTimeout ->
# TODO: call this after the annotation reloading has finished
for p in providers
p.channel.notify method: 'onLogout'
# Leave Highlighting mode when logging out
if annotator.tool is 'highlight'
# Because of logging out, we must leave Highlighting Mode.
......@@ -46,14 +39,6 @@ class App
# change (caused by leaving Highlighting Mode) will trigger
# a reload anyway.
$scope.skipAuthChangeReload = true
else
if oldValue?
# Tell the providers that we have logged in
setTimeout ->
for p in providers
p.channel.notify
method: 'onLogin'
params: newValue[0]
$scope.$watch 'auth.persona', (newValue, oldValue) =>
if oldValue? and not newValue?
......
......@@ -13,8 +13,6 @@ class Annotator.Guest extends Annotator
# Plugin configuration
options:
Document: {}
# Use this with caution! Consider security implications!
#CodeAuth: {}
# Internal state
comments: null
......@@ -28,10 +26,6 @@ class Annotator.Guest extends Annotator
super
delete @options.noScan
# Save this reference to the Annotator class, so it's available
# later, even if someone has deleted the original reference
@Annotator = Annotator
# Create an array for holding the comments
@comments = []
......@@ -65,7 +59,6 @@ class Annotator.Guest extends Annotator
event.initUIEvent "annotatorReady", false, false, window, 0
event.annotator = this
window.dispatchEvent event
, 1000
# Load plugins
for own name, opts of @options
......
......@@ -32,6 +32,10 @@ class Annotator.Host extends Annotator.Guest
if @frame.hasClass 'annotator-collapsed'
this.showFrame()
# Save this reference to the Annotator class, so it's available
# later, even if someone has deleted the original reference
@Annotator = Annotator
# Configure notification classes
Annotator.$.extend Annotator.Notification,
INFO: 'info'
......
class Annotator.Plugin.CodeAuth extends Annotator.Plugin
# These actions will be axposed on @annotator
actions: [
'loginWithUsernameAndPassword'
'logout'
'getLoginStatus'
'registerUser'
]
pluginInit: ->
for i in @actions
@annotator[i] = this[i]
addEventListener "annotatorReady", => @annotator.panel
.bind('onLogin', (ctx, user) =>
if @_pendingLogin?
@_pendingLogin?.resolve()
delete @_pendingLogin
else
event = document.createEvent "UIEvents"
event.initUIEvent "annotatorLogin", false, false, window, 0
event.user = user
window.dispatchEvent event
)
.bind('onLoginFailed', (ctx, data) =>
@_pendingLogin?.reject data
delete @_pendingLogin
)
.bind('onLogout', =>
if @_pendingLogout?
@_pendingLogout.resolve()
delete @_pendingLogout
else
event = document.createEvent "UIEvents"
event.initUIEvent "annotatorLogout", false, false, window, 0
window.dispatchEvent event
)
.bind('onRegisterFailed', (ctx, data) =>
@_pendingRegister?.reject data
delete @_pendingRegister
)
.bind('onRegister', (ctx, user) =>
if @_pendingRegister?
@_pendingRegister?.resolve user
delete @_pendingRegister
)
# Public API to trigger a login
loginWithUsernameAndPassword: (username, password) =>
@_pendingLogin = @annotator.Annotator.$.Deferred()
if @annotator.panel?
@annotator.panel.notify method: "login", params:
username: username
password: password
else
@pendingLogin.reject "Panel connection is not yet available."
@_pendingLogin
# Public API to trigger a logout
logout: =>
@_pendingLogout = @annotator.Annotator.$.Deferred()
if @annotator.panel?
@annotator.panel.notify method: "logout"
else
@pendingLogout.reject "Panel connection is not yet available."
@_pendingLogout
# Public API to get login status
getLoginStatus: =>
result = @annotator.Annotator.$.Deferred()
if @annotator.panel?
@annotator.panel.call
method: "getLoginStatus"
success: (data) ->
result.resolve data
error: (problem) -> result.reject problem
else
result.reject "Panel connection is not yet available."
result
# Public API to register a user
registerUser: (username, email, password) =>
@_pendingRegister = @annotator.Annotator.$.Deferred()
if @annotator.panel?
@annotator.panel.notify method: "registerUser", params:
username: username
email: email
password: password
else
@pendingRegister.reject "Panel connection is not yet available."
@_pendingRegister
......@@ -235,35 +235,6 @@ class Hypothesis extends Annotator
$rootScope.$apply => this.setVisibleHighlights state
)
.bind('login', (ctx, params) =>
@auth.$login(params).catch (data) =>
for p in @providers
p.channel.notify
method: 'onLoginFailed'
params: data
)
.bind('logout', =>
@auth.$logout()
)
.bind('getLoginStatus', =>
@auth.persona
)
.bind('registerUser', (ctx, params) =>
@auth.$register params, (data) =>
for p in @providers
p.channel.notify
method: 'onRegister'
params: data.persona
, (data) =>
for p in @providers
p.channel.notify
method: 'onRegisterFailed'
params: data
)
_setupWrapper: ->
@wrapper = @element.find('#wrapper')
.on 'mousewheel', (event, delta) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment