From 0a82d1fe67c2225a4634f972e3ca43352c246e52 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 9 Dec 2011 14:49:39 +0000 Subject: [PATCH] automatic login after admin user creation git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1212452 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/webapp/js/archiva/main.js | 50 ++++++++++++------- .../src/main/webapp/js/redback/user.js | 3 +- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 2622f4a0a..94fc3f63e 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -133,31 +133,42 @@ function($) { $('#topbar-menu-container').html($("#topbar-menu")); $('#sidebar-content').html($("#main-menu")); - - $.ajax("restServices/redbackServices/userService/isAdminUserExists", { - type: "GET", - dataType: 'json', - success: function(data) { - var adminExists = JSON.parse(data); - if (adminExists == false) { - $("#create-admin-link").show(); + checkCreateAdminLink=function(){ + $.ajax("restServices/redbackServices/userService/isAdminUserExists", { + type: "GET", + dataType: 'json', + success: function(data) { + var adminExists = JSON.parse(data); + if (adminExists == false) { + $("#create-admin-link").show(); + } else { + $("#create-admin-link").hide(); + } } - } - }); + }); + } + checkCreateAdminLink(); hideElementWithKarma(); - var user = userLogged(); - if (!user) { - $("#login-link").show(); - $("#register-link").show(); - $("#change-password-link").hide(); - } else { - $("#change-password-link").show(); - $("#logout-link").show(); - decorateMenuWithKarma(user); + checkSecurityLinks=function(){ + var user = userLogged(); + $.log("checkSecurityLinks, user:"+user); + + if (!user) { + $("#login-link").show(); + $("#register-link").show(); + $("#change-password-link").hide(); + } else { + $("#change-password-link").show(); + $("#logout-link").show(); + $("#register-link").hide(); + $("#login-link").hide(); + decorateMenuWithKarma(user); + } } + checkSecurityLinks(); /** @@ -199,6 +210,7 @@ function($) { } screenChange=function(){ + $("#main-content").html(""); clearUserMessages(); } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js index 4454dc801..f3d20330e 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/user.js @@ -79,7 +79,7 @@ $(function() { if (!valid) { return; } - + var currentAdminUser = this; $.ajax("restServices/redbackServices/userService/createAdminUser", { data: "{\"user\": " + ko.toJSON(this)+"}", contentType: 'application/json', @@ -89,6 +89,7 @@ $(function() { var created = JSON.parse(result); if (created == true) { displaySuccessMessage("admin user created"); + loginCall(currentAdminUser.username(), currentAdminUser.password(),function(){screenChange();checkCreateAdminLink();checkSecurityLinks();}); return this; } else { displayErrorMessage("admin user not created"); -- 2.39.5