Commit 550031059307bafd08d253e9c3a1c50f4d0decaf
1 parent
45283d57
v1.20.0.0
- CreateAdminRolesAndUsers metódus módosítása
Showing
3 changed files
with
20 additions
and
36 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - UserManager.cs
| ... | ... | @@ -42,7 +42,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.UserManagerNS |
| 42 | 42 | |
| 43 | 43 | var menufunctions = new Menu("Log4Pro User Manager", "Select function!") |
| 44 | 44 | .AddMenuItem(new Menu.Item(CLP.Module.Log4ProUserManager.Functions.CreateSuperuser.KEY, "Create superuser", CreateSuperuser, new Menu.ExecutorParameter(cfg: config))) |
| 45 | - .AddMenuItem(new Menu.Item(CLP.Module.Log4ProUserManager.Functions.CreateAdminusers.KEY, "Create Admin and Administrator roles and users", CreateAdminusers, new Menu.ExecutorParameter(cfg: config, null))) | |
| 45 | + .AddMenuItem(new Menu.Item(CLP.Module.Log4ProUserManager.Functions.CreateAdminusers.KEY, "Create Admin and Administrator roles and users", CreateAdminuser, new Menu.ExecutorParameter(cfg: config, null))) | |
| 46 | 46 | .AddMenuItem(new Menu.Item(CLP.Module.Log4ProUserManager.Functions.DeleteUsers.KEY, "Remove user", DeleteUsers, new Menu.ExecutorParameter(cfg: config, null))) |
| 47 | 47 | .AddMenuItem(new Menu.Item(CLP.Module.Log4ProUserManager.Functions.ExecuteInitAction.KEY, "Execute init actionblock", ExecuteInitActionBlock, new Menu.ExecutorParameter(cfg: config, null))) |
| 48 | 48 | .SetMenuHeaderDisplayer(UserListDisplayer) |
| ... | ... | @@ -149,16 +149,19 @@ namespace Vrh.Log4Pro.MaintenanceConsole.UserManagerNS |
| 149 | 149 | } |
| 150 | 150 | #endregion CreateSuperuser |
| 151 | 151 | #region CreateAdminusers |
| 152 | - private static object CreateAdminusers(object parameter, object o) | |
| 152 | + private static object CreateAdminuser(object parameter, object o) | |
| 153 | 153 | { |
| 154 | 154 | var config = (parameter as Menu.ExecutorParameter).GetConfig<Log4ProUserManagerXmlProcessor>(); |
| 155 | - var adminun = ColorConsole.ReadLine($"Enter administrator name:", ConsoleColor.Yellow); | |
| 155 | + var adminun = ColorConsole.ReadLine($"Enter administrator name (* for Administrator):", ConsoleColor.Yellow); | |
| 156 | 156 | if (adminun.ToUpper() == "EX") { return null; } |
| 157 | - var adminpsw = ColorConsole.ReadLine($"Enter administrator password:", ConsoleColor.Yellow); | |
| 157 | + if (adminun.ToUpper() == "*") { adminun=null; } | |
| 158 | + | |
| 159 | + var adminpsw = ColorConsole.ReadLine($"Enter administrator password (* for Admin123):", ConsoleColor.Yellow); | |
| 158 | 160 | if (adminpsw.ToUpper() == "EX") { return null; } |
| 161 | + if (adminpsw.ToUpper() == "*") { adminpsw=null; } | |
| 159 | 162 | try |
| 160 | 163 | { |
| 161 | - MembershipTools.Users.CreateAdminRolesAndUsers(adminpsw); | |
| 164 | + MembershipTools.Users.CreateAdminRolesAndUsers(adminun,adminpsw); | |
| 162 | 165 | ColorConsole.WriteLine($"Creating admin users was successful!", ConsoleColor.Green); |
| 163 | 166 | } |
| 164 | 167 | catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| ... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
| 32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | 33 | // by using the '*' as shown below: |
| 34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.19.5.0")] | |
| 36 | -[assembly: AssemblyFileVersion("1.19.5.0")] | |
| 35 | +[assembly: AssemblyVersion("1.20.0.0")] | |
| 36 | +[assembly: AssemblyFileVersion("1.20.0.0")] | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Tools - Membership.cs
| ... | ... | @@ -44,12 +44,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 44 | 44 | { |
| 45 | 45 | public const string SCHEMA_NAME = "UAdmin"; |
| 46 | 46 | |
| 47 | - public const string ROLENAME_ADMINISTRATOR = "Administrator"; | |
| 48 | - public const string ROLENAME_ADMIN = "Admin"; | |
| 47 | + public const string ROLENAME_USERADMINISTRATOR = "UserAdministrator"; | |
| 49 | 48 | public const string USERNAME_ADMINISTRATOR = "Administrator"; |
| 50 | - public const string USERNAME_ADMIN = "Admin"; | |
| 51 | 49 | public const string PASSWORD_ADMINISTRATOR = "Admin123"; |
| 52 | - public static readonly string[] SYSTEMUSERNAMELIST = new string[] { ROLENAME_ADMIN, USERNAME_ADMINISTRATOR }; | |
| 50 | + public static readonly string[] SYSTEMUSERNAMELIST = new string[] { USERNAME_ADMINISTRATOR }; | |
| 53 | 51 | public static readonly DateTime NEVERONLINE = new DateTime(2000, 1, 1); |
| 54 | 52 | } |
| 55 | 53 | #endregion Constants |
| ... | ... | @@ -118,7 +116,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 118 | 116 | } |
| 119 | 117 | #endregion ellenőrzések |
| 120 | 118 | |
| 121 | - CreateAdminRolesAndUsers(username,password); | |
| 119 | + CreateAdminRolesAndUsers();//alapértelmezett Administrator/Admin123 user létrehozása | |
| 122 | 120 | MembershipUser user = Membership.GetUser(username); |
| 123 | 121 | if (user == null) |
| 124 | 122 | { |
| ... | ... | @@ -140,11 +138,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 140 | 138 | if (!Users.IsInRole(username, rn)) { System.Web.Security.Roles.AddUserToRole(username, rn); } |
| 141 | 139 | } |
| 142 | 140 | } |
| 143 | - else if (administrator) | |
| 144 | - { | |
| 145 | - if (!System.Web.Security.Roles.IsUserInRole(username, Constants.ROLENAME_ADMINISTRATOR)) { System.Web.Security.Roles.AddUserToRole(username, Constants.ROLENAME_ADMINISTRATOR); } | |
| 146 | - if (!System.Web.Security.Roles.IsUserInRole(username, Constants.ROLENAME_ADMIN)) { System.Web.Security.Roles.AddUserToRole(username, Constants.ROLENAME_ADMIN); } | |
| 147 | - } | |
| 141 | + else if (administrator) { CreateAdminRolesAndUsers(username, password); } | |
| 148 | 142 | |
| 149 | 143 | string[] selectedrolenames; |
| 150 | 144 | if (rolenames != null && rolenames.Any()) |
| ... | ... | @@ -178,26 +172,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 178 | 172 | #region CreateAdminRolesAndUsers |
| 179 | 173 | public static void CreateAdminRolesAndUsers(string adminun=null, string adminpsw=null) |
| 180 | 174 | { |
| 181 | - if (string.IsNullOrWhiteSpace(adminpsw)) adminun = Constants.USERNAME_ADMIN; | |
| 182 | - MembershipUser user; | |
| 183 | - if (!System.Web.Security.Roles.RoleExists(Constants.ROLENAME_ADMINISTRATOR)) { System.Web.Security.Roles.CreateRole(Constants.ROLENAME_ADMINISTRATOR); } | |
| 184 | - if (!System.Web.Security.Roles.RoleExists(Constants.ROLENAME_ADMIN)) { System.Web.Security.Roles.CreateRole(Constants.ROLENAME_ADMIN); } | |
| 175 | + if (string.IsNullOrWhiteSpace(adminun)) adminun = Constants.USERNAME_ADMINISTRATOR; | |
| 176 | + if (string.IsNullOrWhiteSpace(adminpsw)) adminpsw = Constants.PASSWORD_ADMINISTRATOR; | |
| 177 | + if (!System.Web.Security.Roles.RoleExists(Constants.ROLENAME_USERADMINISTRATOR)) { System.Web.Security.Roles.CreateRole(Constants.ROLENAME_USERADMINISTRATOR); } | |
| 185 | 178 | |
| 186 | - user = Membership.GetUser(Constants.USERNAME_ADMIN); | |
| 187 | - if (user == null) | |
| 188 | - { | |
| 189 | - user = Membership.CreateUser(Constants.USERNAME_ADMIN, Constants.PASSWORD_ADMINISTRATOR); | |
| 190 | - } | |
| 191 | - if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMIN, Constants.ROLENAME_ADMINISTRATOR)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMIN, Constants.ROLENAME_ADMINISTRATOR); } | |
| 192 | - if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMIN, Constants.ROLENAME_ADMIN)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMIN, Constants.ROLENAME_ADMIN); } | |
| 193 | - | |
| 194 | - user = Membership.GetUser(Constants.USERNAME_ADMINISTRATOR); | |
| 195 | - if (user == null) | |
| 196 | - { | |
| 197 | - user = Membership.CreateUser(Constants.USERNAME_ADMINISTRATOR, Constants.PASSWORD_ADMINISTRATOR); | |
| 198 | - } | |
| 199 | - if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_ADMINISTRATOR)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_ADMINISTRATOR); } | |
| 200 | - if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_ADMIN)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_ADMIN); } | |
| 179 | + MembershipUser user = Membership.GetUser(Constants.USERNAME_ADMINISTRATOR); | |
| 180 | + if (user == null) { user = Membership.CreateUser(Constants.USERNAME_ADMINISTRATOR, Constants.PASSWORD_ADMINISTRATOR); } | |
| 181 | + if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_USERADMINISTRATOR)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_USERADMINISTRATOR); } | |
| 201 | 182 | } |
| 202 | 183 | #endregion CreateAdminRolesAndUsers |
| 203 | 184 | #region IsInRole public method | ... | ... |