Commit 6015cd55 authored by Randall Leeds's avatar Randall Leeds

Idiotamiticize the decaf

parent d22fd8af
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 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);
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'
};
function onSuccess(form, response) {
// Fire flash messages
for (var type in response.flash) {
response.flash[type].map(function (message) {
flash[type](message);
});
}
form.$setPristine();
var formModel = form.$name.slice(0, -4);
// Reset form fields
$scope[formModel] = {};
// Update status button
$scope.$broadcast('formState', form.$name, 'success');
$scope.email = response.email;
};
function onDelete(form, response) {
identity.logout();
onSuccess(form, response);
};
function onError(form, response) {
if (response.status >= 400 && response.status < 500) {
formRespond(form, response.data.errors);
} else {
if (response.data.flash) {
for (type in response.data.flash) {
response.data.flash[type].map(function (message) {
flash[type](message);
});
}
}
form.$setPristine();
formModel = form.$name.slice(0, -4);
$scope[formModel] = {};
$scope.$broadcast('formState', form.$name, 'success');
return $scope.email = response.email;
};
onDelete = function(form, response) {
identity.logout();
return onSuccess(form, response);
};
onError = function(form, response) {
var m;
var msgs;
var type;
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);
}
}
} else {
flash.error('Sorry, we were unable to perform your request');
}
flash.error('Sorry, we were unable to perform your request');
}
return $scope.$broadcast('formState', form.$name, '');
};
$scope.tab = 'Account';
session.profile().$promise.then((function() {
return function(result) {
$scope.subscriptions = result.subscriptions;
return $scope.email = result.email;
};
})(this));
$scope.editProfile = {};
$scope.changePassword = {};
$scope.deleteAccount = {};
$scope.delete = function(form) {
var errorHandler;
var packet;
var promise;
var successHandler;
var username;
if (!form.$valid) {
return;
}
username = personaFilter(auth.user);
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);
}
// Update status button
$scope.$broadcast('formState', form.$name, '');
};
$scope.tab = 'Account';
session.profile().$promise.then(function(result) {
$scope.subscriptions = result.subscriptions;
$scope.email = result.email;
});
// Data for each of the forms
$scope.editProfile = {};
$scope.changePassword = {};
$scope.deleteAccount = {};
$scope.delete = function(form) {
// 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;
}
var username = personaFilter(auth.user);
var packet = {
username: username,
pwd: form.pwd.$modelValue
};
$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 = {
username: username,
pwd: form.pwd.$modelValue,
password: form.password.$modelValue
};
successHandler = angular.bind(null, onSuccess, form);
errorHandler = angular.bind(null, onError, form);
$scope.$broadcast('formState', form.$name, 'loading');
promise = session.edit_profile(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) {
formRespond(form);
if (!form.$valid) {
return;
}
var username = personaFilter(auth.user);
var packet = {
username: username,
pwd: form.pwd.$modelValue,
password: form.password.$modelValue
};
$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 = {
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);
$scope.$broadcast('formState', form.$name, 'loading');
promise = session.edit_profile(packet);
return promise.$promise.then(successHandler, errorHandler);
var successHandler = angular.bind(null, onSuccess, form);
var errorHandler = angular.bind(null, onError, form);
// Update status button
$scope.$broadcast('formState', form.$name, 'loading');
var promise = session.edit_profile(packet).$promise;
return promise.then(successHandler, errorHandler);
};
$scope.changeEmailSubmit = function(form) {
formRespond(form);
if (!form.$valid) {
return;
}
var username = personaFilter(auth.user);
var packet = {
username: username,
pwd: form.pwd.$modelValue,
email: form.email.$modelValue,
emailAgain: form.emailAgain.$modelValue
};
$scope.updated = function(index, form) {
var errorHandler;
var packet;
var promise;
var successHandler;
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);
var successHandler = angular.bind(null, onSuccess, form);
var errorHandler = angular.bind(null, onError, form);
// Update status button
$scope.$broadcast('formState', form.$name, 'loading');
var promise = session.edit_profile(packet).$promise;
return promise.then(successHandler, errorHandler);
};
$scope.updated = function(index, form) {
var packet = {
username: auth.user,
subscriptions: JSON.stringify($scope.subscriptions[index])
};
}
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);
var angular = require('angular');
var AuthAppController = (function() {
AuthAppController.$inject = ['$location', '$scope', '$timeout', '$window',
'session'];
AuthAppController.$inject = [
'$location', '$scope', '$timeout', '$window',
'session'
];
function AuthAppController(
$location, $scope, $timeout, $window,
session
) {
function onlogin() {
window.location.href = '/stream';
};
function AuthAppController($location, $scope, $timeout, $window, session) {
var onlogin;
onlogin = function() {
return $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);
}
});
$scope.$watch('account.tab', function(tab, old) {
if (tab !== old) {
return $location.path('/' + tab);
}
});
session.load(function(data) {
if (data.userid) {
return onlogin();
}
});
}
$scope.account = {};
$scope.model = {};
$scope.account.tab = $location.path().split('/')[1];
return AuthAppController;
$scope.$on('auth', function(event, err, data) {
if (data != null ? data.userid : void 0) {
$timeout(onlogin, 1000);
}
});
})();
$scope.$watch('account.tab', function(tab, old) {
if (tab !== old) {
$location.path('/' + tab);
}
});
var AuthPageController = (function() {
AuthPageController.$inject = ['$routeParams', '$scope'];
// 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) {
onlogin();
}
});
}
function AuthPageController($routeParams, $scope) {
$scope.model.code = $routeParams.code;
$scope.hasActivationCode = !!$routeParams.code;
}
return AuthPageController;
AuthPageController.$inject = ['$routeParams', '$scope'];
function AuthPageController( $routeParams, $scope) {
$scope.model.code = $routeParams.code;
$scope.hasActivationCode = !!$routeParams.code;
}
})();
var configure = [
'$httpProvider', '$locationProvider', '$routeProvider',
function($httpProvider, $locationProvider, $routeProvider) {
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
$locationProvider.html5Mode(true);
$routeProvider.when('/login', {
controller: 'AuthPageController',
templateUrl: 'auth.html'
});
$routeProvider.when('/register', {
controller: 'AuthPageController',
templateUrl: 'auth.html'
});
$routeProvider.when('/forgot_password', {
controller: 'AuthPageController',
templateUrl: 'auth.html'
});
return $routeProvider.when('/reset_password/:code?', {
controller: 'AuthPageController',
templateUrl: 'auth.html'
});
}
];
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'
});
$routeProvider.when('/register', {
controller: 'AuthPageController',
templateUrl: 'auth.html'
});
$routeProvider.when('/forgot_password', {
controller: 'AuthPageController',
templateUrl: 'auth.html'
});
$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');
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;
if (data.userid) {
$scope.$emit('auth', null, data);
}
$scope.account.tab = (function() {
switch ($scope.account.tab) {
case 'register':
return 'login';
case 'forgot_password':
return 'reset_password';
case 'reset_password':
return 'login';
default:
return $scope.account.tab;
}
})();
angular.copy({}, $scope.model);
return (_ref = $scope.form) != null ? _ref.$setPristine() : void 0;
};
failure = function(form, response) {
var errors, reason, _ref;
try {
_ref = response.data, errors = _ref.errors, reason = _ref.reason;
} catch (_error) {
reason = "Oops, something went wrong on the server. Please try again later!";
}
return formRespond(form, errors, reason);
};
this.submit = function(form) {
formRespond(form);
if (!form.$valid) {
return;
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':
return 'login';
case 'forgot_password':
return 'reset_password';
case 'reset_password':
return 'login';
default:
return $scope.account.tab;
}
$scope.$broadcast('formState', form.$name, 'loading');
return session[form.$name]($scope.model, success, angular.bind(this, failure, form)).$promise.finally(function() {
return $scope.$broadcast('formState', form.$name, '');
});
};
if ($scope.account == null) {
$scope.account = {
tab: 'login'
};
})();
angular.copy({}, $scope.model);
if ($scope.form != null) {
$scope.form.$setPristine()
}
if ($scope.model == null) {
$scope.model = {};
};
function failure(form, response) {
var errors, reason;
try {
errors = response.data.errors;
reason = response.data.reason;
} catch (e) {
reason = 'Oops, something went wrong on the server. ' +
'Please try again later!';
}
$scope.$on('auth', (function() {
var preventCancel;
return preventCancel = $scope.$on('$destroy', function() {
if (timeout) {
$timeout.cancel(timeout);
}
return $scope.$emit('auth', 'cancel');
});
})());
$scope.$watchCollection('model', function(value) {
if (timeout) {
$timeout.cancel(timeout);
}
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);
}
return formRespond(form, errors, reason);
};
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');
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'
};
}
return AuthController;
if ($scope.model == null) {
$scope.model = {};
}
// 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) {
cancelTimeout(pendingTimeout);
if (value && !angular.equals(value, {})) {
pendingTimeout = $timeout(timeout, 300000);
}
});
}
angular.module('h').controller('AuthController', AuthController);
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;
// Use the Pyramid XSRF header name
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token';
identityProvider.checkAuthentication = [
'$q', 'session', function($q, session) {
authCheck = $q.defer();
session.load().$promise
.then(function (data) {
if (data.userid) {
authCheck.resolve(data.csrf);
} else {
authCheck.reject('no session');
}
})
.catch(function () {
authCheck.reject('request failure');
});
return authCheck.promise;
}
];
var configure = [
'$httpProvider', 'identityProvider', 'sessionProvider',
function($httpProvider, identityProvider, sessionProvider) {
var action;
var authCheck;
authCheck = null;
$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) {
if (data.userid) {
return authCheck.resolve(data.csrf);
} else {
return authCheck.reject('no session');
}
}, function() {
return authCheck.reject('request failure');
});
})());
}
];
identityProvider.forgetAuthentication = [
'$q', 'flash', 'session',
function($q, flash, session) {
return session.logout({}).$promise.then(function() {
identityProvider.forgetAuthentication = [
'$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) {
if (err) {
return authRequest.reject(err);
} else {
return authRequest.resolve(data.csrf);
}
});
})());
}
];
identityProvider.requestAuthentication = [
'$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);
}
});
}
];
sessionProvider.actions.load = {
method: 'GET',
withCredentials: true
};
sessionProvider.actions.profile = {
method: 'GET',
return authRequest.promise;
});
}
];
sessionProvider.actions.load = {
method: 'GET',
withCredentials: true
};
sessionProvider.actions.profile = {
method: 'GET',
params: {
__formid__: 'profile'
},
withCredentials: true
};
for (var i = 0; i < SESSION_ACTIONS.length; i++) {
var action = SESSION_ACTIONS[i];
sessionProvider.actions[action] = {
method: 'POST',
params: {
__formid__: 'profile'
__formid__: action
},
withCredentials: true
};
var results = [];
for (var i = 0; i < SESSION_ACTIONS.length; i++) {
action = SESSION_ACTIONS[i];
results.push(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);
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