Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
6015cd55
Commit
6015cd55
authored
Jul 20, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Idiotamiticize the decaf
parent
d22fd8af
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
389 additions
and
356 deletions
+389
-356
account-controller.js
h/static/scripts/account/account-controller.js
+141
-148
account.js
h/static/scripts/account/account.js
+61
-61
auth-controller.js
h/static/scripts/account/auth-controller.js
+106
-76
accounts.js
h/static/scripts/config/accounts.js
+81
-71
No files found.
h/static/scripts/account/account-controller.js
View file @
6015cd55
var
AccountController
;
var
__hasProp
=
{}.
hasOwnProperty
;
AccountController
=
(
function
()
{
AccountController
.
inject
=
[
'$scope'
,
'$filter'
,
'auth'
,
'flash'
,
'formRespond'
,
'identity'
,
'session'
];
function
AccountController
(
$scope
,
$filter
,
auth
,
flash
,
formRespond
,
identity
,
session
)
{
var
onDelete
;
var
onError
;
var
onSuccess
;
var
angular
=
require
(
'angular'
);
AccountController
.
inject
=
[
'$scope'
,
'$filter'
,
'auth'
,
'flash'
,
'formRespond'
,
'identity'
,
'session'
];
function
AccountController
(
$scope
,
$filter
,
auth
,
flash
,
formRespond
,
identity
,
session
)
{
var
personaFilter
=
$filter
(
'persona'
);
$scope
.
subscriptionDescription
=
{
reply
:
'Someone replies to one of my annotations'
};
onSuccess
=
function
(
form
,
response
)
{
var
formModel
;
var
m
;
var
msgs
;
var
type
;
var
ref
=
response
.
flash
;
for
(
type
in
ref
)
{
msgs
=
ref
[
type
];
for
(
var
i
=
0
;
i
<
msgs
.
length
;
i
++
)
{
m
=
msgs
[
i
];
flash
[
type
](
m
);
}
function
onSuccess
(
form
,
response
)
{
// Fire flash messages
for
(
var
type
in
response
.
flash
)
{
response
.
flash
[
type
].
map
(
function
(
message
)
{
flash
[
type
](
message
);
});
}
form
.
$setPristine
();
formModel
=
form
.
$name
.
slice
(
0
,
-
4
);
var
formModel
=
form
.
$name
.
slice
(
0
,
-
4
);
// Reset form fields
$scope
[
formModel
]
=
{};
// Update status button
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
'success'
);
return
$scope
.
email
=
response
.
email
;
$scope
.
email
=
response
.
email
;
};
onDelete
=
function
(
form
,
response
)
{
function
onDelete
(
form
,
response
)
{
identity
.
logout
();
return
onSuccess
(
form
,
response
);
onSuccess
(
form
,
response
);
};
onError
=
function
(
form
,
response
)
{
var
m
;
var
msgs
;
var
type
;
function
onError
(
form
,
response
)
{
if
(
response
.
status
>=
400
&&
response
.
status
<
500
)
{
formRespond
(
form
,
response
.
data
.
errors
);
}
else
{
if
(
response
.
data
.
flash
)
{
var
ref
=
response
.
data
.
flash
;
for
(
type
in
ref
)
{
if
(
!
__hasProp
.
call
(
ref
,
type
))
{
continue
;
}
msgs
=
ref
[
type
];
for
(
var
i
=
0
;
i
<
msgs
.
length
;
i
++
)
{
m
=
msgs
[
i
];
flash
[
type
](
m
);
}
for
(
type
in
response
.
data
.
flash
)
{
response
.
data
.
flash
[
type
].
map
(
function
(
message
)
{
flash
[
type
](
message
);
});
}
}
else
{
flash
.
error
(
'Sorry, we were unable to perform your request'
);
}
}
return
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
''
);
// Update status button
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
''
);
};
$scope
.
tab
=
'Account'
;
session
.
profile
().
$promise
.
then
((
function
()
{
return
function
(
result
)
{
session
.
profile
().
$promise
.
then
(
function
(
result
)
{
$scope
.
subscriptions
=
result
.
subscriptions
;
return
$scope
.
email
=
result
.
email
;
};
})(
this
));
$scope
.
email
=
result
.
email
;
});
// Data for each of the forms
$scope
.
editProfile
=
{};
$scope
.
changePassword
=
{};
$scope
.
deleteAccount
=
{};
$scope
.
delete
=
function
(
form
)
{
var
errorHandler
;
var
packet
;
var
promise
;
var
successHandler
;
var
username
;
// If the password is correct, the account is deleted.
// The extension is then removed from the page.
// Confirmation of success is given.
if
(
!
form
.
$valid
)
{
return
;
}
username
=
personaFilter
(
auth
.
user
);
packet
=
{
var
username
=
personaFilter
(
auth
.
user
);
var
packet
=
{
username
:
username
,
pwd
:
form
.
pwd
.
$modelValue
};
successHandler
=
angular
.
bind
(
null
,
onDelete
,
form
);
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
promise
=
session
.
disable_user
(
packet
);
return
promise
.
$promise
.
then
(
successHandler
,
errorHandler
);
var
successHandler
=
angular
.
bind
(
null
,
onDelete
,
form
);
var
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
var
promise
=
session
.
disable_user
(
packet
).
$promise
;
return
promise
.
then
(
successHandler
,
errorHandler
);
};
$scope
.
submit
=
function
(
form
)
{
var
errorHandler
;
var
packet
;
var
promise
;
var
successHandler
;
var
username
;
formRespond
(
form
);
if
(
!
form
.
$valid
)
{
return
;
}
username
=
personaFilter
(
auth
.
user
);
packet
=
{
var
username
=
personaFilter
(
auth
.
user
);
var
packet
=
{
username
:
username
,
pwd
:
form
.
pwd
.
$modelValue
,
password
:
form
.
password
.
$modelValue
};
successHandler
=
angular
.
bind
(
null
,
onSuccess
,
form
);
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
var
successHandler
=
angular
.
bind
(
null
,
onSuccess
,
form
);
var
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
// Update status button
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
'loading'
);
promise
=
session
.
edit_profile
(
packet
);
return
promise
.
$promise
.
then
(
successHandler
,
errorHandler
);
var
promise
=
session
.
edit_profile
(
packet
).
$promise
;
return
promise
.
then
(
successHandler
,
errorHandler
);
};
$scope
.
changeEmailSubmit
=
function
(
form
)
{
var
errorHandler
;
var
packet
;
var
promise
;
var
successHandler
;
var
username
;
formRespond
(
form
);
if
(
!
form
.
$valid
)
{
return
;
}
username
=
personaFilter
(
auth
.
user
);
packet
=
{
var
username
=
personaFilter
(
auth
.
user
);
var
packet
=
{
username
:
username
,
pwd
:
form
.
pwd
.
$modelValue
,
email
:
form
.
email
.
$modelValue
,
emailAgain
:
form
.
emailAgain
.
$modelValue
};
successHandler
=
angular
.
bind
(
null
,
onSuccess
,
form
);
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
var
successHandler
=
angular
.
bind
(
null
,
onSuccess
,
form
);
var
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
// Update status button
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
'loading'
);
promise
=
session
.
edit_profile
(
packet
);
return
promise
.
$promise
.
then
(
successHandler
,
errorHandler
);
var
promise
=
session
.
edit_profile
(
packet
).
$promise
;
return
promise
.
then
(
successHandler
,
errorHandler
);
};
$scope
.
updated
=
function
(
index
,
form
)
{
var
errorHandler
;
var
packet
;
var
promise
;
var
successHandler
;
packet
=
{
var
packet
=
{
username
:
auth
.
user
,
subscriptions
:
JSON
.
stringify
(
$scope
.
subscriptions
[
index
])
};
successHandler
=
angular
.
bind
(
null
,
onSuccess
,
form
);
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
promise
=
session
.
edit_profile
(
packet
);
return
promise
.
$promise
.
then
(
successHandler
,
errorHandler
);
};
}
return
AccountController
;
var
successHandler
=
angular
.
bind
(
null
,
onSuccess
,
form
);
var
errorHandler
=
angular
.
bind
(
null
,
onError
,
form
);
})();
var
promise
=
session
.
edit_profile
(
packet
).
$promise
;
return
promise
.
then
(
successHandler
,
errorHandler
);
};
}
angular
.
module
(
'h'
).
controller
(
'AccountController'
,
AccountController
);
h/static/scripts/account/account.js
View file @
6015cd55
var
angular
=
require
(
'angular'
);
var
AuthAppController
=
(
function
()
{
AuthAppController
.
$inject
=
[
'$location'
,
'$scope'
,
'$timeout'
,
'$window'
,
'session'
];
function
AuthAppController
(
$location
,
$scope
,
$timeout
,
$window
,
session
)
{
var
onlogin
;
onlogin
=
function
()
{
return
$window
.
location
.
href
=
'/stream'
;
AuthAppController
.
$inject
=
[
'$location'
,
'$scope'
,
'$timeout'
,
'$window'
,
'session'
];
function
AuthAppController
(
$location
,
$scope
,
$timeout
,
$window
,
session
)
{
function
onlogin
()
{
window
.
location
.
href
=
'/stream'
;
};
$scope
.
account
=
{};
$scope
.
model
=
{};
$scope
.
account
.
tab
=
$location
.
path
().
split
(
'/'
)[
1
];
$scope
.
$on
(
'auth'
,
function
(
event
,
err
,
data
)
{
if
(
data
!=
null
?
data
.
userid
:
void
0
)
{
return
$timeout
(
onlogin
,
1000
);
$timeout
(
onlogin
,
1000
);
}
});
$scope
.
$watch
(
'account.tab'
,
function
(
tab
,
old
)
{
if
(
tab
!==
old
)
{
return
$location
.
path
(
'/'
+
tab
);
$location
.
path
(
'/'
+
tab
);
}
});
// TODO: We should be calling identity.beginProvisioning() here in order to
// move toward become a federated BrowserID provider.
session
.
load
(
function
(
data
)
{
if
(
data
.
userid
)
{
return
onlogin
();
onlogin
();
}
});
}
return
AuthAppController
;
}
})();
var
AuthPageController
=
(
function
()
{
AuthPageController
.
$inject
=
[
'$routeParams'
,
'$scope'
];
function
AuthPageController
(
$routeParams
,
$scope
)
{
AuthPageController
.
$inject
=
[
'$routeParams'
,
'$scope'
];
function
AuthPageController
(
$routeParams
,
$scope
)
{
$scope
.
model
.
code
=
$routeParams
.
code
;
$scope
.
hasActivationCode
=
!!
$routeParams
.
code
;
}
}
return
AuthPageController
;
})();
var
configure
=
[
'$httpProvider'
,
'$locationProvider'
,
'$routeProvider'
,
function
(
$httpProvider
,
$locationProvider
,
$routeProvider
)
{
configure
.
$inject
=
[
'$httpProvider'
,
'$locationProvider'
,
'$routeProvider'
];
function
configure
(
$httpProvider
,
$locationProvider
,
$routeProvider
)
{
// Use the Pyramid XSRF header name
$httpProvider
.
defaults
.
xsrfHeaderName
=
'X-CSRF-Token'
;
$locationProvider
.
html5Mode
(
true
);
$routeProvider
.
when
(
'/login'
,
{
controller
:
'AuthPageController'
,
templateUrl
:
'auth.html'
...
...
@@ -62,12 +64,11 @@ var configure = [
controller
:
'AuthPageController'
,
templateUrl
:
'auth.html'
});
return
$routeProvider
.
when
(
'/reset_password/:code?'
,
{
$routeProvider
.
when
(
'/reset_password/:code?'
,
{
controller
:
'AuthPageController'
,
templateUrl
:
'auth.html'
});
}
];
}
angular
.
module
(
'h'
)
.
config
(
configure
)
...
...
@@ -75,5 +76,4 @@ angular.module('h')
.
controller
(
'AuthPageController'
,
AuthPageController
);
require
(
'./account-controller'
);
require
(
'./auth-controller'
);
h/static/scripts/account/auth-controller.js
View file @
6015cd55
var
AuthController
=
(
function
()
{
AuthController
.
$inject
=
[
'$scope'
,
'$timeout'
,
'flash'
,
'session'
,
'formRespond'
];
function
AuthController
(
$scope
,
$timeout
,
flash
,
session
,
formRespond
)
{
var
failure
,
success
,
timeout
;
timeout
=
null
;
success
=
function
(
data
)
{
var
_ref
;
AuthController
.
$inject
=
[
'$scope'
,
'$timeout'
,
'flash'
,
'session'
,
'formRespond'
];
function
AuthController
(
$scope
,
$timeout
,
flash
,
session
,
formRespond
)
{
var
pendingTimeout
=
null
;
function
success
(
data
)
{
if
(
data
.
userid
)
{
$scope
.
$emit
(
'auth'
,
null
,
data
);
}
$scope
.
account
.
tab
=
(
function
()
{
switch
(
$scope
.
account
.
tab
)
{
case
'register'
:
...
...
@@ -22,64 +25,91 @@ var AuthController = (function() {
return
$scope
.
account
.
tab
;
}
})();
angular
.
copy
({},
$scope
.
model
);
return
(
_ref
=
$scope
.
form
)
!=
null
?
_ref
.
$setPristine
()
:
void
0
;
if
(
$scope
.
form
!=
null
)
{
$scope
.
form
.
$setPristine
()
}
};
failure
=
function
(
form
,
response
)
{
var
errors
,
reason
,
_ref
;
function
failure
(
form
,
response
)
{
var
errors
,
reason
;
try
{
_ref
=
response
.
data
,
errors
=
_ref
.
errors
,
reason
=
_ref
.
reason
;
}
catch
(
_error
)
{
reason
=
"Oops, something went wrong on the server. Please try again later!"
;
errors
=
response
.
data
.
errors
;
reason
=
response
.
data
.
reason
;
}
catch
(
e
)
{
reason
=
'Oops, something went wrong on the server. '
+
'Please try again later!'
;
}
return
formRespond
(
form
,
errors
,
reason
);
};
this
.
submit
=
function
(
form
)
{
function
timeout
()
{
angular
.
copy
({},
$scope
.
model
);
if
(
$scope
.
form
!=
null
)
{
$scope
.
form
.
$setPristine
();
}
flash
.
info
(
'For your security, '
+
'the forms have been reset due to inactivity.'
);
}
function
cancelTimeout
()
{
if
(
pendingTimeout
==
null
)
{
return
;
}
$timeout
.
cancel
(
pendingTimeout
);
pendingTimeout
=
null
;
}
this
.
submit
=
function
submit
(
form
)
{
formRespond
(
form
);
if
(
!
form
.
$valid
)
{
return
;
}
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
'loading'
);
return
session
[
form
.
$name
](
$scope
.
model
,
success
,
angular
.
bind
(
this
,
failure
,
form
)).
$promise
.
finally
(
function
()
{
var
handler
=
session
[
form
.
$name
];
var
_failure
=
angular
.
bind
(
this
,
failure
,
form
);
var
res
=
handler
(
$scope
.
model
,
success
,
_failure
);
res
.
$promise
.
finally
(
function
()
{
return
$scope
.
$broadcast
(
'formState'
,
form
.
$name
,
''
);
});
};
if
(
$scope
.
account
==
null
)
{
$scope
.
account
=
{
tab
:
'login'
};
}
if
(
$scope
.
model
==
null
)
{
$scope
.
model
=
{};
}
$scope
.
$on
(
'auth'
,
(
function
()
{
var
preventCancel
;
return
preventCancel
=
$scope
.
$on
(
'$destroy'
,
function
()
{
if
(
timeout
)
{
$timeout
.
cancel
(
timeout
);
}
return
$scope
.
$emit
(
'auth'
,
'cancel'
);
// Stop the inactivity timeout when the scope is destroyed.
var
removeDestroyHandler
=
$scope
.
$on
(
'$destroy'
,
function
()
{
cancelTimeout
(
pendingTimeout
);
$scope
.
$emit
(
'auth'
,
'cancel'
);
});
})());
// Skip the cancel when destroying the scope after a successful auth.
$scope
.
$on
(
'auth'
,
removeDestroyHandler
);
// Reset the auth forms afterfive minutes of inactivity.
$scope
.
$watchCollection
(
'model'
,
function
(
value
)
{
if
(
timeout
)
{
$timeout
.
cancel
(
timeout
);
}
cancelTimeout
(
pendingTimeout
);
if
(
value
&&
!
angular
.
equals
(
value
,
{}))
{
return
timeout
=
$timeout
(
function
()
{
var
_ref
;
angular
.
copy
({},
$scope
.
model
);
if
((
_ref
=
$scope
.
form
)
!=
null
)
{
_ref
.
$setPristine
();
}
return
flash
.
info
(
'For your security, the forms have been reset due to inactivity.'
);
},
300000
);
pendingTimeout
=
$timeout
(
timeout
,
300000
);
}
});
}
return
AuthController
;
})();
}
angular
.
module
(
'h'
).
controller
(
'AuthController'
,
AuthController
);
h/static/scripts/config/accounts.js
View file @
6015cd55
var
angular
=
require
(
'angular'
);
var
SESSION_ACTIONS
=
[
'login'
,
'logout'
,
'register'
,
'forgot_password'
,
'reset_password'
,
'edit_profile'
,
'disable_user'
];
var
SESSION_ACTIONS
=
[
'login'
,
'logout'
,
'register'
,
'forgot_password'
,
'reset_password'
,
'edit_profile'
,
'disable_user'
];
configure
.
$inject
=
[
'$httpProvider'
,
'identityProvider'
,
'sessionProvider'
];
function
configure
(
$httpProvider
,
identityProvider
,
sessionProvider
)
{
// Pending authentication check
var
authCheck
=
null
;
var
configure
=
[
'$httpProvider'
,
'identityProvider'
,
'sessionProvider'
,
function
(
$httpProvider
,
identityProvider
,
sessionProvider
)
{
var
action
;
var
authCheck
;
authCheck
=
null
;
// Use the Pyramid XSRF header name
$httpProvider
.
defaults
.
xsrfHeaderName
=
'X-CSRF-Token'
;
identityProvider
.
checkAuthentication
=
[
'$q'
,
'session'
,
function
(
$q
,
session
)
{
return
(
authCheck
=
$q
.
defer
()).
promise
.
then
((
function
()
{
return
session
.
load
().
$promise
.
then
(
function
(
data
)
{
'$q'
,
'session'
,
function
(
$q
,
session
)
{
authCheck
=
$q
.
defer
();
session
.
load
().
$promise
.
then
(
function
(
data
)
{
if
(
data
.
userid
)
{
return
authCheck
.
resolve
(
data
.
csrf
);
authCheck
.
resolve
(
data
.
csrf
);
}
else
{
return
authCheck
.
reject
(
'no session'
);
authCheck
.
reject
(
'no session'
);
}
},
function
()
{
return
authCheck
.
reject
(
'request failure'
);
})
.
catch
(
function
()
{
authCheck
.
reject
(
'request failure'
);
});
})());
return
authCheck
.
promise
;
}
];
identityProvider
.
forgetAuthentication
=
[
'$q'
,
'flash'
,
'session'
,
function
(
$q
,
flash
,
session
)
{
return
session
.
logout
({}).
$promise
.
then
(
function
()
{
'$q'
,
'flash'
,
'session'
,
function
(
$q
,
flash
,
session
)
{
return
session
.
logout
({}).
$promise
.
then
(
function
()
{
authCheck
=
$q
.
defer
();
authCheck
.
reject
(
'no session'
);
return
null
;
}).
catch
(
function
(
err
)
{
})
.
catch
(
function
(
err
)
{
flash
.
error
(
'Sign out failed!'
);
throw
err
;
});
}
];
identityProvider
.
requestAuthentication
=
[
'$q'
,
'$rootScope'
,
function
(
$q
,
$rootScope
)
{
return
authCheck
.
promise
.
catch
(
function
()
{
var
authRequest
;
return
(
authRequest
=
$q
.
defer
()).
promise
.
finally
((
function
()
{
return
$rootScope
.
$on
(
'auth'
,
function
(
event
,
err
,
data
)
{
'$q'
,
'$rootScope'
,
function
(
$q
,
$rootScope
)
{
return
authCheck
.
promise
.
catch
(
function
()
{
var
authRequest
=
$q
.
defer
();
$rootScope
.
$on
(
'auth'
,
function
(
event
,
err
,
data
)
{
if
(
err
)
{
return
authRequest
.
reject
(
err
);
}
else
{
return
authRequest
.
resolve
(
data
.
csrf
);
}
});
})());
return
authRequest
.
promise
;
});
}
];
sessionProvider
.
actions
.
load
=
{
method
:
'GET'
,
withCredentials
:
true
};
sessionProvider
.
actions
.
profile
=
{
method
:
'GET'
,
params
:
{
...
...
@@ -67,21 +79,19 @@ var configure = [
},
withCredentials
:
true
};
var
results
=
[];
for
(
var
i
=
0
;
i
<
SESSION_ACTIONS
.
length
;
i
++
)
{
action
=
SESSION_ACTIONS
[
i
];
results
.
push
(
sessionProvider
.
actions
[
action
]
=
{
var
action
=
SESSION_ACTIONS
[
i
];
sessionProvider
.
actions
[
action
]
=
{
method
:
'POST'
,
params
:
{
__formid__
:
action
},
withCredentials
:
true
});
}
return
results
;
};
}
];
}
angular
.
module
(
'h'
)
.
value
(
'xsrf'
,
{
token
:
null
})
.
config
(
configure
);
angular
.
module
(
'h'
)
.
value
(
'xsrf'
,
{
token
:
null
})
.
config
(
configure
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment