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 bac585c86e..895613d5b2 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 @@ -3,13 +3,19 @@ * @name umbraco.resources.authResource * @description Loads in data for authentication **/ -function authResource($q, $http, umbRequestHelper) { +function authResource($q, $http, umbRequestHelper, angularHelper) { return { //currentUser: currentUser, /** Logs the user in if the credentials are good */ performLogin: function (username, password) { + + if (!username || !password) { + return angularHelper.rejectedPromise({ + errorMsg: 'Username or password cannot be empty' + }); + } return umbRequestHelper.resourcePromise( $http.post( diff --git a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js index 9a8b8e2278..db9ecf564a 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js @@ -31,6 +31,25 @@ angular.module('umbraco.services').factory('legacyJsLoader', legacyJsLoader); function angularHelper($log, $q) { return { + /** + * @ngdoc function + * @name umbraco.services.angularHelper#rejectedPromise + * @methodOf umbraco.services.angularHelper + * @function + * + * @description + * In some situations we need to return a promise as a rejection, normally based on invalid data. This + * is a wrapper to do that so we can save one writing a bit of code. + * + * @param {object} objReject The object to send back with the promise rejection + */ + rejectedPromise: function (objReject) { + var deferred = $q.defer(); + //return an error object including the error message for UI + deferred.reject(objReject); + return deferred.promise; + }, + /** * @ngdoc function * @name safeApply diff --git a/src/Umbraco.Web.UI.Client/src/less/login.less b/src/Umbraco.Web.UI.Client/src/less/login.less index 0e5cd397fe..0a02377bcd 100644 --- a/src/Umbraco.Web.UI.Client/src/less/login.less +++ b/src/Umbraco.Web.UI.Client/src/less/login.less @@ -32,4 +32,13 @@ color: @white; font-size: 18px; font-weight: normal +} + +.login-overlay .alert.alert-error{ + display: inline-block; + width: 270px; + padding-right: 6px; + padding-left: 6px; + margin-top: 10px; + text-align: center; } \ 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 index d67220187c..d6150fef26 100644 --- 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 @@ -11,10 +11,17 @@ */ var d = new Date(); var weekday = new Array("Super Sunday", "Manic Monday", "Tremendous Tuesday", "Wonderfull Wednesday", "Thunder Thursday", "Friendly Friday", "Shiny Saturday"); + $scope.today = weekday[d.getDay()]; - $scope.loginClick = function (login, password) { + $scope.errorMsg = ""; + + $scope.loginSubmit = function (login, password) { + if ($scope.loginForm.$invalid) { + return; + } + userService.authenticate(login, password) .then(function (data) { //We need to load in the legacy tree js. @@ -23,7 +30,25 @@ $scope.submit(true); }); }, function (reason) { - alert(reason); + $scope.errorMsg = reason.errorMsg; + + //set the form inputs to invalid + $scope.loginForm.username.$setValidity("auth", false); + $scope.loginForm.password.$setValidity("auth", false); }); + + //setup a watch for both of the model values changing, if they change + // while the form is invalid, then revalidate them so that the form can + // be submitted again. + $scope.loginForm.username.$viewChangeListeners.push(function () { + if ($scope.loginForm.username.$invalid) { + $scope.loginForm.username.$setValidity('auth', true); + } + }); + $scope.loginForm.password.$viewChangeListeners.push(function () { + if ($scope.loginForm.password.$invalid) { + $scope.loginForm.password.$setValidity('auth', true); + } + }); }; }); \ 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 index f7b61e64a8..32ad4c97f4 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/login.html @@ -1,13 +1,19 @@ -