diff --git a/src/Umbraco.Web.UI.Client/gruntFile.js b/src/Umbraco.Web.UI.Client/gruntFile.js index 29faf2debf..8a486d2df6 100644 --- a/src/Umbraco.Web.UI.Client/gruntFile.js +++ b/src/Umbraco.Web.UI.Client/gruntFile.js @@ -112,7 +112,7 @@ module.exports = function (grunt) { files: [{ dest: '<%= distdir %>/js', src : '*.js', expand: true, cwd: 'src/sample files/' }] }, vs: { - files: [{ dest: '<%= vsdir %>/assets', src : '**', expand: true, cwd: '<%= distdir %>' }] + files: [{ dest: '<%= vsdir %>', src : '**', expand: true, cwd: '<%= distdir %>' }] } }, diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js index eeb9aaaabe..5d1941da3a 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/auth.resource.js @@ -13,20 +13,26 @@ function authResource($q, $http, umbDataFormatter, umbRequestHelper) { /** internal method to get the api url */ function getIsAuthUrl() { return Umbraco.Sys.ServerVariables.authenticationApiBaseUrl + "GetCurrentUser"; - } + } + + var _currentUser; + return { - + currentUser: _currentUser, + /** Logs the user in if the credentials are good */ performLogin: function (username, password) { var deferred = $q.defer(); //send the data $http.post(getLoginUrl(username, password)). - success(function (data, status, headers, config) { + success(function (data, status, headers, config) { + _currentUser = data; deferred.resolve(data); }). error(function (data, status, headers, config) { + _currentUser = data; deferred.reject('Login failed for user ' + username); }); diff --git a/src/Umbraco.Web.UI.Client/src/common/security/retryqueue.js b/src/Umbraco.Web.UI.Client/src/common/security/retryqueue.js index f734eecb87..7b7d54f9c4 100644 --- a/src/Umbraco.Web.UI.Client/src/common/security/retryqueue.js +++ b/src/Umbraco.Web.UI.Client/src/common/security/retryqueue.js @@ -1,7 +1,10 @@ angular.module('umbraco.security.retryQueue', []) // This is a generic retry queue for security failures. Each item is expected to expose two functions: retry and cancel. -.factory('securityRetryQueue', ['$q', '$log', function($q, $log) { +.factory('securityRetryQueue', ['$q', '$log', function ($q, $log) { + + $log.log("loaded queue"); + var retryQueue = []; var service = { // The security service puts its own handler in here! diff --git a/src/Umbraco.Web.UI.Client/src/common/security/security.service.js b/src/Umbraco.Web.UI.Client/src/common/security/security.service.js index ce4a3ad280..61a510ca68 100644 --- a/src/Umbraco.Web.UI.Client/src/common/security/security.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/security/security.service.js @@ -2,10 +2,19 @@ angular.module('umbraco.security.service', [ 'umbraco.security.retryQueue', // Keeps track of failed requests that need to be retried once the user logs in + 'umbraco.resources', 'umbraco.services' ]) - -.factory('security', ['$http', '$q', '$location', 'securityRetryQueue', 'dialogService', function($http, $q, $location, queue, $dialog) { +.factory('security', ['$http', '$q', '$location', 'securityRetryQueue', 'authResource', 'dialogService', '$log', + function ($http, $q, $location, queue, authResource, dialogService, $log) { + + // Register a handler for when an item is added to the retry queue + queue.onItemAddedCallbacks.push(function (retryItem) { + if (queue.hasMore()) { + service.showLogin(); + } + }); + // Redirect to the given url (defaults to '/') function redirect(url) { @@ -21,14 +30,12 @@ angular.module('umbraco.security.service', [ throw new Error('Trying to open a dialog that is already open!'); } - alert("here a dialog would appear"); - - //loginDialog = $dialog.dialog(); - //loginDialog.open('security/login/form.tpl.html', 'LoginFormController').then(onLoginDialogClose); + loginDialog = dialogService.open({template: 'views/common/dialogs/login.html', show: true, callback: onLoginDialogClose}); } + function closeLoginDialog(success) { - if (loginDialog) { - loginDialog.close(success); + if (loginDialog) { + loginDialog = null; } } @@ -42,12 +49,6 @@ angular.module('umbraco.security.service', [ } } - // Register a handler for when an item is added to the retry queue - queue.onItemAddedCallbacks.push(function(retryItem) { - if ( queue.hasMore() ) { - service.showLogin(); - } - }); // The public API of the service var service = { @@ -91,11 +92,9 @@ angular.module('umbraco.security.service', [ requestCurrentUser: function() { if ( service.isAuthenticated() ) { return $q.when(service.currentUser); - } else { - return $http.get('/current-user').then(function(response) { - service.currentUser = response.data.user; - return service.currentUser; - }); + } else { + service.currentUser = authResource.currentUser; + return service.currentUser; } }, diff --git a/src/Umbraco.Web.UI.Client/src/index.html b/src/Umbraco.Web.UI.Client/src/index.html index 577bdc1b51..cd60633009 100644 --- a/src/Umbraco.Web.UI.Client/src/index.html +++ b/src/Umbraco.Web.UI.Client/src/index.html @@ -21,7 +21,6 @@ - diff --git a/src/Umbraco.Web.UI.Client/src/routes.js b/src/Umbraco.Web.UI.Client/src/routes.js index 8b6d809ba4..42779d20fa 100644 --- a/src/Umbraco.Web.UI.Client/src/routes.js +++ b/src/Umbraco.Web.UI.Client/src/routes.js @@ -32,4 +32,10 @@ app.config(function ($routeProvider) { }).config(function ($locationProvider) { //$locationProvider.html5Mode(false).hashPrefix('!'); //turn html5 mode off // $locationProvider.html5Mode(true); //turn html5 mode on -}); \ No newline at end of file + }); + +app.run(['security', function (security) { + // Get the current user when the application starts + // (in case they are still logged in from a previous session) + security.requestCurrentUser(); +}]); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js new file mode 100644 index 0000000000..691e605207 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.controller.js @@ -0,0 +1,24 @@ +angular.module("umbraco").controller("Umbraco.Dialogs.LoginController", function ($scope, userService) { + alert("login"); + + /** + * @ngdoc function + * @name signin + * @methodOf MainController + * @function + * + * @description + * signs the user in + */ + $scope.loginClick = function (login, password) { + alert("wat"); + + userService.authenticate(login, password) + .then(function (data) { + $scope.authenticated = data.authenticated; + $scope.user = data.user; + }, function (reason) { + alert(reason); + }); + }; +}); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html new file mode 100644 index 0000000000..bcdb8d27ba --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html @@ -0,0 +1,13 @@ +
+
+

Hey {{today}}!, log in below

+
+ +
+
+ +
+ + +
+
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js index f6b8e95856..11944f3f4f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/main.controller.js @@ -20,25 +20,6 @@ function MainController($scope, $routeParams, $rootScope, $timeout, notification $scope.login = ""; $scope.password = ""; - /** - * @ngdoc function - * @name signin - * @methodOf MainController - * @function - * - * @description - * signs the user in - */ - $scope.signin = function () { - - userService.authenticate($scope.login, $scope.password) - .then(function (data) { - $scope.authenticated = data.authenticated; - $scope.user = data.user; - }, function (reason) { - alert(reason); - }); - }; $scope.signout = function () { userService.signout(); @@ -58,7 +39,6 @@ function MainController($scope, $routeParams, $rootScope, $timeout, notification }; $scope.closeDialogs = function (event) { - $rootScope.$emit("closeDialogs"); if (navigationService.ui.stickyNavigation && $(event.target).parents(".umb-modalcolumn").size() == 0) { diff --git a/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml b/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml index c33119f2e6..85b8c0e593 100644 --- a/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml +++ b/src/Umbraco.Web.UI/umbraco/Views/Default.cshtml @@ -59,7 +59,6 @@ - diff --git a/src/Umbraco.Web.UI/umbraco/index.html b/src/Umbraco.Web.UI/umbraco/index.html new file mode 100644 index 0000000000..cd60633009 --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/index.html @@ -0,0 +1,30 @@ + + + + + + + + Umbraco + + + + +
+ + + +
+
+
+
+
+
+ + + + + + + + diff --git a/src/Umbraco.Web.UI/umbraco/js/loader.js b/src/Umbraco.Web.UI/umbraco/js/loader.js index 6875f70a4d..6f3bad9ded 100644 --- a/src/Umbraco.Web.UI/umbraco/js/loader.js +++ b/src/Umbraco.Web.UI/umbraco/js/loader.js @@ -10,9 +10,10 @@ yepnope({ 'js/app_dev.js', - 'js/umbraco.mocks.js', + 'js/umbraco.httpbackend.js', 'js/umbraco.directives.js', 'js/umbraco.filters.js', + 'js/umbraco.resources.js', 'js/umbraco.services.js', 'js/umbraco.security.js', 'js/umbraco.controllers.js',