Authentication almost done
Missing some styling and we are good to go on promised based authentication
This commit is contained in:
@@ -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 %>' }]
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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!
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<umb-login></umb-login>
|
||||
<umb-notifications></umb-notifications>
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
}]);
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
<div id="login" class="umb-modalcolumn" ng-controller="Umbraco.Dialogs.LoginController">
|
||||
<div class="form">
|
||||
<h1>Hey {{today}}!, log in below</h1>
|
||||
<div class="control-group">
|
||||
<input type="text" ng-model="login" class="input-xlarge" placeholder="Enter your username" />
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<input type="password" ng-model="password" class="input-xlarge" placeholder="Enter your password" />
|
||||
</div>
|
||||
|
||||
<input type="button" ng-click="loginClick(login, password)" class="btn" value="Login" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user