Skip to content

Commit

Permalink
Change static module name to habitrpgStatic.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aughr committed Jan 16, 2014
1 parent 518f200 commit 77801e4
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 84 deletions.
12 changes: 12 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -231,4 +231,4 @@ window.habitrpg = angular.module('habitrpg',
}
}];
$httpProvider.responseInterceptors.push(interceptor);
}])
}])
155 changes: 78 additions & 77 deletions public/js/controllers/authCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};
$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;
};

runAuth = function(id, token) {
User.authenticate(id, token, function(err) {
$window.location.href = '/';
//$rootScope.modals.login = false;
});
};
$scope.logout = function() {
localStorage.clear();
window.location.href = '/logout';
};

$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);
}
runAuth = function(id, token) {
User.authenticate(id, token, function(err) {
$window.location.href = '/';
//$rootScope.modals.login = false;
});
};
};

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.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.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);
}
};
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.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);
});
$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);
});
}
}
}
]);
4 changes: 2 additions & 2 deletions public/js/static.js
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions test/spec/authCtrlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe('Auth Controller', function() {

beforeEach(module('habitrpg'));
beforeEach(module('habitrpgStatic'));

describe('AuthCtrl', function(){
var scope, ctrl, user, $httpBackend, $window;
Expand Down Expand Up @@ -35,4 +35,4 @@ describe('Auth Controller', function() {
});
});

});
});
2 changes: 1 addition & 1 deletion views/static/front.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77801e4

Please sign in to comment.