Change static module name to habitrpgStatic.

The way the tests are written now, the habitrpg module definition in static.js
was clobbering the one in app.js. In other words, most of the tests weren't
testing what they thought they were testing.
This commit is contained in:
Andrew Bloomgarden 2014-01-12 15:00:47 -08:00
parent 518f200a8f
commit 77801e458e
6 changed files with 103 additions and 90 deletions

View file

@ -11,10 +11,22 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'public/bower_components/jquery/jquery.js',
'public/bower_components/angular/angular.js',
'public/bower_components/angular-loading-bar/build/loading-bar.min.js',
'public/bower_components/angular-resource/angular-resource.min.js',
'public/bower_components/angular-sanitize/angular-sanitize.js',
'public/bower_components/bootstrap/docs/assets/js/bootstrap.js',
'public/bower_components/angular-bootstrap/ui-bootstrap.js',
'public/bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
'public/bower_components/angular-ui-router/release/angular-ui-router.js',
'public/bower_components/angular-ui/build/angular-ui.js',
'public/bower_components/angular-ui-utils/ui-utils.min.js',
'public/bower_components/Angular-At-Directive/src/at.js',
'public/bower_components/Angular-At-Directive/src/caret.js',
'public/bower_components/angular-mocks/angular-mocks.js',
'public/bower_components/angular-bindonce/bindonce.js',
'public/bower_components/ngInfiniteScroll/ng-infinite-scroll.js',
'public/bower_components/marked/lib/marked.js',
'public/bower_components/js-emoji/emoji.js',
'public/bower_components/habitrpg-shared/dist/habitrpg-shared.js',

View file

@ -17,7 +17,7 @@ window.env.t = function(string){
window.habitrpg = angular.module('habitrpg',
['ngResource', 'ngSanitize', 'userServices', 'groupServices', 'memberServices', 'challengeServices',
'authServices', 'notificationServices', 'guideServices',
'authServices', 'notificationServices', 'guideServices', 'authCtrl',
'ui.bootstrap', 'ui.keypress', 'ui.router', 'chieffancypants.loadingBar', 'At', 'pasvaz.bindonce', 'infinite-scroll'])
// @see https://github.com/angular-ui/ui-router/issues/110 and https://github.com/HabitRPG/habitrpg/issues/1705
@ -231,4 +231,4 @@ window.habitrpg = angular.module('habitrpg',
}
}];
$httpProvider.responseInterceptors.push(interceptor);
}])
}])

View file

@ -4,93 +4,94 @@
The authentication controller (login & facebook)
*/
habitrpg.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL',
function($scope, $rootScope, User, $http, $location, $window, API_URL) {
var runAuth;
var showedFacebookMessage;
angular.module('authCtrl', [])
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','API_URL',
function($scope, $rootScope, User, $http, $location, $window, API_URL) {
var runAuth;
var showedFacebookMessage;
$scope.useUUID = false;
$scope.toggleUUID = function() {
if (showedFacebookMessage === false) {
alert("Until we add Facebook, use your UUID and API Token to log in (found at https://habitrpg.com > Options > Settings).");
showedFacebookMessage = true;
}
$scope.useUUID = !$scope.useUUID;
};
$scope.logout = function() {
localStorage.clear();
window.location.href = '/logout';
};
runAuth = function(id, token) {
User.authenticate(id, token, function(err) {
$window.location.href = '/';
//$rootScope.modals.login = false;
});
};
$scope.register = function() {
/*TODO highlight invalid inputs
we have this as a workaround for https://github.com/HabitRPG/habitrpg-mobile/issues/64
*/
if ($scope.registrationForm.$invalid) {
return;
}
$http.post(API_URL + "/api/v2/register", $scope.registerVals).success(function(data, status, headers, config) {
runAuth(data.id, data.apiToken);
}).error(function(data, status, headers, config) {
if (status === 0) {
$window.alert("Server not currently reachable, try again later");
} else if (!!data && !!data.err) {
$window.alert(data.err);
} else {
$window.alert("ERROR: " + status);
}
});
};
function errorAlert(data, status, headers, config) {
if (status === 0) {
$window.alert("Server not currently reachable, try again later");
} else if (!!data && !!data.err) {
$window.alert(data.err);
} else {
$window.alert("ERROR: " + status);
}
}
$scope.auth = function() {
var data = {
username: $scope.loginUsername,
password: $scope.loginPassword
$scope.useUUID = false;
$scope.toggleUUID = function() {
if (showedFacebookMessage === false) {
alert("Until we add Facebook, use your UUID and API Token to log in (found at https://habitrpg.com > Options > Settings).");
showedFacebookMessage = true;
}
$scope.useUUID = !$scope.useUUID;
};
if ($scope.useUUID) {
runAuth($scope.loginUsername, $scope.loginPassword);
} else {
$http.post(API_URL + "/api/v2/user/auth/local", data)
.success(function(data, status, headers, config) {
runAuth(data.id, data.token);
}).error(errorAlert);
}
};
$scope.playButtonClick = function(){
if (User.authenticated()) {
window.location.href = '/#/tasks';
} else {
$('#login-modal').modal('show');
}
}
$scope.logout = function() {
localStorage.clear();
window.location.href = '/logout';
};
$scope.passwordReset = function(email){
$http.post(API_URL + '/api/v2/user/reset-password', {email:email})
.success(function(){
alert('New password sent.');
})
.error(function(data){
alert(data.err);
runAuth = function(id, token) {
User.authenticate(id, token, function(err) {
$window.location.href = '/';
//$rootScope.modals.login = false;
});
};
$scope.register = function() {
/*TODO highlight invalid inputs
we have this as a workaround for https://github.com/HabitRPG/habitrpg-mobile/issues/64
*/
if ($scope.registrationForm.$invalid) {
return;
}
$http.post(API_URL + "/api/v2/register", $scope.registerVals).success(function(data, status, headers, config) {
runAuth(data.id, data.apiToken);
}).error(function(data, status, headers, config) {
if (status === 0) {
$window.alert("Server not currently reachable, try again later");
} else if (!!data && !!data.err) {
$window.alert(data.err);
} else {
$window.alert("ERROR: " + status);
}
});
};
function errorAlert(data, status, headers, config) {
if (status === 0) {
$window.alert("Server not currently reachable, try again later");
} else if (!!data && !!data.err) {
$window.alert(data.err);
} else {
$window.alert("ERROR: " + status);
}
}
$scope.auth = function() {
var data = {
username: $scope.loginUsername,
password: $scope.loginPassword
};
if ($scope.useUUID) {
runAuth($scope.loginUsername, $scope.loginPassword);
} else {
$http.post(API_URL + "/api/v2/user/auth/local", data)
.success(function(data, status, headers, config) {
runAuth(data.id, data.token);
}).error(errorAlert);
}
};
$scope.playButtonClick = function(){
if (User.authenticated()) {
window.location.href = '/#/tasks';
} else {
$('#login-modal').modal('show');
}
}
$scope.passwordReset = function(email){
$http.post(API_URL + '/api/v2/user/reset-password', {email:email})
.success(function(){
alert('New password sent.');
})
.error(function(data){
alert(data.err);
});
}
}
}
]);

View file

@ -1,7 +1,7 @@
"use strict";
window.habitrpg = angular.module('habitrpg', ['notificationServices', 'userServices', 'chieffancypants.loadingBar'])
window.habitrpgStatic = angular.module('habitrpgStatic', ['notificationServices', 'userServices', 'chieffancypants.loadingBar', 'authCtrl'])
.constant("API_URL", "")
.constant("STORAGE_USER_ID", 'habitrpg-user')
.constant("STORAGE_SETTINGS_ID", 'habit-mobile-settings')
.constant("MOBILE_APP", false)
.constant("MOBILE_APP", false)

View file

@ -2,7 +2,7 @@
describe('Auth Controller', function() {
beforeEach(module('habitrpg'));
beforeEach(module('habitrpgStatic'));
describe('AuthCtrl', function(){
var scope, ctrl, user, $httpBackend, $window;
@ -35,4 +35,4 @@ describe('Auth Controller', function() {
});
});
});
});

View file

@ -7,7 +7,7 @@ block title
title=env.t('titleFront')
block content
div(ng-app='habitrpg')
div(ng-app='habitrpgStatic')
#wrap(ng-controller='AuthCtrl')
//-include ./header
.jumbotron.masthead