Commit ef955f89 authored by gergely-ujvari's avatar gergely-ujvari

Merge pull request #2210 from hypothesis/client-config

Break out client configuration into a Bundle
parents d212725d 8a3e15b5
angular = require('angular')
AUTH_SESSION_ACTIONS = [
'login'
'logout'
'register'
'forgot_password'
'reset_password'
'edit_profile'
'disable_user'
]
class AuthAppController
this.$inject = ['$location', '$scope', '$timeout', '$window', 'session']
......@@ -43,15 +33,10 @@ class AuthPageController
configure = [
'$httpProvider', '$locationProvider', '$routeProvider',
'identityProvider', 'sessionProvider'
'$httpProvider', '$locationProvider', '$routeProvider'
(
$httpProvider, $locationProvider, $routeProvider,
identityProvider, sessionProvider
$httpProvider, $locationProvider, $routeProvider
) ->
# Pending authentication check
authCheck = null
# Use the Pyramid XSRF header name
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token'
......@@ -69,56 +54,6 @@ configure = [
$routeProvider.when '/reset_password/:code?',
controller: 'AuthPageController'
templateUrl: 'auth.html'
identityProvider.checkAuthentication = [
'$q', 'session',
($q, session) ->
(authCheck = $q.defer()).promise.then do ->
session.load().$promise.then (data) ->
if data.userid then authCheck.resolve data.csrf
else authCheck.reject 'no session'
, -> authCheck.reject 'request failure'
]
identityProvider.forgetAuthentication = [
'$q', 'flash', 'session',
($q, flash, session) ->
session.logout({}).$promise
.then ->
authCheck = $q.defer()
authCheck.reject 'no session'
return null
.catch (err) ->
flash.error('Sign out failed!')
throw err
]
identityProvider.requestAuthentication = [
'$q', '$rootScope',
($q, $rootScope) ->
authCheck.promise.catch ->
(authRequest = $q.defer()).promise.finally do ->
$rootScope.$on 'auth', (event, err, data) ->
if err then authRequest.reject err
else authRequest.resolve data.csrf
]
sessionProvider.actions.load =
method: 'GET'
withCredentials: true
sessionProvider.actions.profile =
method: 'GET'
params:
__formid__: 'profile'
withCredentials: true
for action in AUTH_SESSION_ACTIONS
sessionProvider.actions[action] =
method: 'POST'
params:
__formid__: action
withCredentials: true
]
......
......@@ -146,7 +146,6 @@ module.exports = angular.module('h', [
.service('unicode', require('./unicode'))
.service('viewFilter', require('./view-filter'))
.value('xsrf', token: null)
.value('AnnotationSync', require('./annotation-sync'))
.value('AnnotationUISync', require('./annotation-ui-sync'))
.value('Discovery', require('./discovery'))
......
angular = require('angular')
SESSION_ACTIONS = [
'login'
'logout'
'register'
'forgot_password'
'reset_password'
'edit_profile'
'disable_user'
]
configure = [
'$httpProvider', 'identityProvider', 'sessionProvider'
($httpProvider, identityProvider, sessionProvider) ->
# Pending authentication check
authCheck = null
# Use the Pyramid XSRF header name
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token'
identityProvider.checkAuthentication = [
'$q', 'session',
($q, session) ->
(authCheck = $q.defer()).promise.then do ->
session.load().$promise.then (data) ->
if data.userid then authCheck.resolve data.csrf
else authCheck.reject 'no session'
, -> authCheck.reject 'request failure'
]
identityProvider.forgetAuthentication = [
'$q', 'flash', 'session',
($q, flash, session) ->
session.logout({}).$promise
.then ->
authCheck = $q.defer()
authCheck.reject 'no session'
return null
.catch (err) ->
flash.error('Sign out failed!')
throw err
]
identityProvider.requestAuthentication = [
'$q', '$rootScope',
($q, $rootScope) ->
authCheck.promise.catch ->
(authRequest = $q.defer()).promise.finally do ->
$rootScope.$on 'auth', (event, err, data) ->
if err then authRequest.reject err
else authRequest.resolve data.csrf
]
sessionProvider.actions.load =
method: 'GET'
withCredentials: true
sessionProvider.actions.profile =
method: 'GET'
params:
__formid__: 'profile'
withCredentials: true
for action in SESSION_ACTIONS
sessionProvider.actions[action] =
method: 'POST'
params:
__formid__: action
withCredentials: true
]
angular.module('h')
.value('xsrf', token: null)
.config(configure)
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