Skip to content

Commit

Permalink
More client side authentication work and work on annotations
Browse files Browse the repository at this point in the history
    modified:   ../app/controllers/audio_events_controller.rb
    	-- more attempts at fixing bug #57

    modified:   ../app/assets/javascripts/angular/controllers/annotation_viewer.js
    modified:   ../app/assets/javascripts/angular/controllers/login.js
    modified:   ../app/assets/javascripts/angular/directives/auth.js
    modified:   ../app/assets/javascripts/angular/directives/directives.js
    modified:   ../app/assets/javascripts/angular/services/services.js
    modified:   ../app/assets/stylesheets/_login_control.css.scss
    modified:   ../app/views/layouts/application.html.erb
    	-- added support for more types of authentication providers

    modified:   ../config/initializers/devise.rb
    	-- removed basic auth for images

    modified:   ../lib/assets/javascripts/jquery.drawabox.js
    	-- deleted unecessary comma

    modified:   ../lib/assets/javascripts/functions.js
    	-- added uri encoder

    ../app/serializers/
    new file:   ../config/initializers/active_model_serializers.rb
    modified:   ../config/initializers/active_model_serializers.rb
    modified:   ../Gemfile
    modified:   ../Gemfile.lock
    	-- added active_model_serializers gem for easier json formatting

    modified:   ../app/models/audio_event.rb
    	-- removed uncessaaey json formatting
  • Loading branch information
atruskie committed Dec 6, 2012
1 parent afe7c4f commit 02e1b7b
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
function AnnotationViewerCtrl($scope, $element, $attrs, $transclude) {



}

AnnotationViewerCtrl.$inject = ['$scope', '$element', '$attrs', '$transclude'];
44 changes: 32 additions & 12 deletions app/assets/javascripts/angular/controllers/login.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
function LoginCtrl($scope, $http, authService, PersonaAuthenticator) {
function LoginCtrl($scope, $http, authService, AuthenticationProviders) {

$scope.requireMoreInformation = null;
$scope.additionalInformation = null;


$scope.submit = function (provider) {

switch (provider) {
case "persona":
PersonaAuthenticator.login();
break;
default:
throw "Provider not matched";
var authProvider = AuthenticationProviders[provider];

if (!authProvider) {
throw "LoginCtrl:submit: Unknown Provider!"
}

// console.info(result);
if (authProvider.requires) {

if (!$scope.additionalInformation || $scope.additionalInformation == "" /* && validation check */) {
$scope.requireMoreInformation = authProvider.requires;
$scope.requireMoreInformation.providerId = provider;
return;
}


authProvider.login($scope.additionalInformation);

$scope.requireMoreInformation = null;
$scope.additionalInformation = undefined;
}
else {
$scope.requireMoreInformation = null;

authProvider.login();
}
};

$scope.logout = function() {

//$http.post(path).success(function () {
// authService.loginConfirmed();
//});
}
}
LoginCtrl.$inject = ['$scope', '$http', 'authService', 'PersonaAuthenticator'];

LoginCtrl.$inject = ['$scope', '$http', 'authService', 'AuthenticationProviders'];
11 changes: 8 additions & 3 deletions app/assets/javascripts/angular/directives/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ angular.module('angular-auth', ['http-auth-interceptor'])
login.hide();

scope.$on('event:auth-loginRequired', function () {
login.slideDown('slow', function () {
main.hide();
});
if (login.is(':animated')) {
// noop
}
else {
login.slideDown('slow', function () {
main.hide();
});
}
});
scope.$on('event:auth-loginConfirmed', function () {
main.show();
Expand Down
65 changes: 44 additions & 21 deletions app/assets/javascripts/angular/directives/directives.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

(function() {
(function () {
var bawds = angular.module('bawApp.directives', []);

bawds.directive('addRedBox', function() {
return function(scope, element, attrs){
bawds.directive('addRedBox', function () {
return function (scope, element, attrs) {
element.append("<div style='background-color: red; height: 100px; width: 100px'></div>");
}
});

bawds.directive('bawRecordInformation', function(){
bawds.directive('bawRecordInformation', function () {

return {
restrict: 'AE',
Expand All @@ -21,8 +20,8 @@
replace: false,
/*compile: function(tElement, tAttrs, transclude) {
},*/
link: function(scope, iElement, iAttrs, controller) {
},*/
link: function (scope, iElement, iAttrs, controller) {
scope.name = scope[iAttrs.ngModel];


Expand All @@ -31,12 +30,12 @@
}
});

bawds.directive('bawDebugInfo', function() {
bawds.directive('bawDebugInfo', function () {
return {
restrict: 'AE',
replace: true,
template: '<div><a href ng-click="showOrHideDebugInfo= !showOrHideDebugInfo">Debug info {{showOrHideDebugInfo}}</a><pre ui-toggle="showOrHideDebugInfo" class="ui-hide" ng-bind="print()"></pre></div>',
link: function(scope, element, attrs) {
link: function (scope, element, attrs) {
if (!scope.print) {
//console.warn("baw-debug-info missing parent scope, no print function");
scope.print = bawApp.print;
Expand All @@ -45,12 +44,12 @@
}
});

bawds.directive('bawJsonBinding', function() {
bawds.directive('bawJsonBinding', function () {

return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
link: function (scope, element, attr, ngModel) {

ngModel.$parsers.push(angular.fromJson);
ngModel.$formatters.push(angular.toJson)
Expand All @@ -59,18 +58,18 @@
});


bawds.directive('isGuid', function() {
bawds.directive('isGuid', function () {
return {

require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
link: function (scope, elm, attrs, ctrl) {
var isList = typeof attrs.ngList !== "undefined";

// push rather than unshift... we want to test last
ctrl.$parsers.push(function(viewValue) {
ctrl.$parsers.push(function (viewValue) {
var valid = true;
if (isList) {
for(var i = 0; i < viewValue.length && valid; i++) {
for (var i = 0; i < viewValue.length && valid; i++) {
valid = GUID_REGEXP.test(viewValue[i]);
}
}
Expand All @@ -93,7 +92,7 @@
});


bawds.directive('bawAnnotationViewer', function() {
bawds.directive('bawAnnotationViewer', function () {
return {
restrict: 'AE',
scope: {
Expand All @@ -105,16 +104,40 @@
// compile: function(element, attributes, transclude) {
// // transform DOM
// },
link: function(scope, element, attributes, controller) {
var $element = $(element);
link: function (scope, element, attributes, controller) {
var $element = $(element);
// assign a unique id to scope
scope.id = Number.Unique();
var $canvas = $($element.find(".annotation-viewer img + div")[0]);


scope.$canvas = $($element.find(".annotation-viewer img + div")[0]);

// init drawabox
$canvas.drawabox();
scope.model.audio_events = scope.model.audio_events || [];
scope.$canvas.drawabox({
"newBox": function(){
console.log("newBox");
},
"boxSelected": function(){
console.log("boxSelected")
},
"boxResizing": function(){
console.log("boxResizing")
},
"boxResized": function(){
console.log("boxResized")
},
"boxMoving": function(){
console.log("boxMoving")}
,
"boxMoved": function(){
console.log("boxMoved")
},
"boxDeleted": function(){
console.log("boxDeleted")
}
});


}
}
});
Expand Down
46 changes: 35 additions & 11 deletions app/assets/javascripts/angular/services/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@
authService.loginConfirmed();
},
loginFailure:function loginFailure(data, status, headers, config) {
$http.defaults.headers.common = null;
$http.defaults.headers.common["Authorization"] = null;
console.error("Login failure: ", data, status, headers, config);
},
logoutSuccess:function logoutSuccess(data, status, headers, config) {

$http.defaults.headers.common = null;
$http.defaults.headers.common["Authorization"] = null;
$rootScope.authorisationToken = null;

console.log("login successful", data);
console.log("logout successful", data);
},
logoutFailure:function logoutFailure(data, status, headers, config) {
console.error("Login failure: ", data, status, headers, config);
}
}
}]);

bawss.factory('PersonaAuthenticator', ['$rootScope', 'authService', '$http', 'Authenticator', function($rootScope, authService, $http, Authenticator) {
bawss.factory('AuthenticationProviders', ['$rootScope', 'authService', '$http', 'Authenticator', function($rootScope, authService, $http, Authenticator) {
// Navigator is the persona global object
navigator.id.watch({
onlogin: function(assertion) {
Expand All @@ -102,17 +102,41 @@
});

return {
login: function login() { navigator.id.request(); },
logout: function logout() { navigator.id.logout(); }
}
}]);
"persona" : {
login: function login() { navigator.id.request(); },
logout: function logout() { navigator.id.logout(); },
requires: null
},
"google" : {
login: function login() {
popUpWindow('https://www.google.com/accounts/o8/id', 300, 200);

},
logout: function logout() { },
requires: null
},
"openid" : {
login: function login(url) {
var popPath = "/security/auth/open_id?openid_url=" + window.fixedEncodeURIComponent(url);
popUpWindow(popPath, 700, 500);

bawss.factory('GoogleAuthenticator', function() {
return {

// Authenticator.loginSuccess
// Authenticator.loginFailure

},
logout: function logout() {

},
requires: {
text: "Enter your OpenID URL",
type: "url"
}
}
}
});
}]);




})();
5 changes: 0 additions & 5 deletions app/assets/stylesheets/_login_control.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,10 @@ body.waiting-for-angular div#initializing-panel {
}

& label {
cursor: pointer;
font-weight: bold;
padding-left: 10px;
}

& input[type="submit"] {
cursor: pointer;
display: block;
margin: auto;
padding: auto;
}
}
2 changes: 2 additions & 0 deletions app/controllers/audio_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def edit
# POST /audio_events
# POST /audio_events.json
def create


@audio_event = AudioEvent.new(params[:audio_event])
#@audio_event.audio_event_tags.each{ |aet| aet.build() }

Expand Down
34 changes: 21 additions & 13 deletions app/models/audio_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,29 @@ def low_frequency_must_be_lte_high_frequency
end
end



# json formatting
def as_json(options={})
super(
:include =>
[
:audio_event_tags,
:audio_recording => {:only => [:id, :uuid]}
],
:except => :audio_recording_id
)
end
#def as_json(options={})
# super(
# :include =>
# [
# :audio_event_tags,
# :audio_recording => {:only => [:id, :uuid]}
# ],
# :except => :audio_recording_id
# )
#end

#def active_model_serializer
# AudioEventSerializer
#end



# other stuff
def download_format(options)
#as_json(:only => )
end
#def download_format(options)
# #as_json(:only => )
#end

end
Loading

0 comments on commit 02e1b7b

Please sign in to comment.