Commit 734d70bb5711ae1ecbcb81e1e776d89592d26686
1 parent
55003105
v1.20.1.0
RoleName: - Administrator RoleGroupName: - Administrator Username/psw: Administrator/Admin123 CreateAdminRolesRoleGroupsUsers létrehozza a fentieket
Showing
3 changed files
with
33 additions
and
13 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - UserManager.cs
@@ -161,7 +161,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.UserManagerNS | @@ -161,7 +161,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.UserManagerNS | ||
161 | if (adminpsw.ToUpper() == "*") { adminpsw=null; } | 161 | if (adminpsw.ToUpper() == "*") { adminpsw=null; } |
162 | try | 162 | try |
163 | { | 163 | { |
164 | - MembershipTools.Users.CreateAdminRolesAndUsers(adminun,adminpsw); | 164 | + MembershipTools.Users.CreateAdminRolesRoleGroupsUsers(adminun,adminpsw); |
165 | ColorConsole.WriteLine($"Creating admin users was successful!", ConsoleColor.Green); | 165 | ColorConsole.WriteLine($"Creating admin users was successful!", ConsoleColor.Green); |
166 | } | 166 | } |
167 | catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | 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,5 +32,5 @@ using System.Runtime.InteropServices; | ||
32 | // You can specify all the values or you can default the Build and Revision Numbers | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | // by using the '*' as shown below: | 33 | // by using the '*' as shown below: |
34 | // [assembly: AssemblyVersion("1.0.*")] | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.20.0.0")] | ||
36 | -[assembly: AssemblyFileVersion("1.20.0.0")] | 35 | +[assembly: AssemblyVersion("1.20.1.0")] |
36 | +[assembly: AssemblyFileVersion("1.20.1.0")] |
Vrh.Log4Pro.MaintenanceConsole/Tools - Membership.cs
@@ -44,9 +44,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -44,9 +44,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
44 | { | 44 | { |
45 | public const string SCHEMA_NAME = "UAdmin"; | 45 | public const string SCHEMA_NAME = "UAdmin"; |
46 | 46 | ||
47 | - public const string ROLENAME_USERADMINISTRATOR = "UserAdministrator"; | 47 | + public const string ROLENAME_USERADMINISTRATOR = "Administrator"; |
48 | public const string USERNAME_ADMINISTRATOR = "Administrator"; | 48 | public const string USERNAME_ADMINISTRATOR = "Administrator"; |
49 | - public const string PASSWORD_ADMINISTRATOR = "Admin123"; | 49 | + public const string ROLEGROUPNAME_ADMINISTRATOR = "Administrator"; |
50 | + public const string PASSWORD_ADMIN123 = "Admin123"; | ||
50 | public static readonly string[] SYSTEMUSERNAMELIST = new string[] { USERNAME_ADMINISTRATOR }; | 51 | public static readonly string[] SYSTEMUSERNAMELIST = new string[] { USERNAME_ADMINISTRATOR }; |
51 | public static readonly DateTime NEVERONLINE = new DateTime(2000, 1, 1); | 52 | public static readonly DateTime NEVERONLINE = new DateTime(2000, 1, 1); |
52 | } | 53 | } |
@@ -116,7 +117,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -116,7 +117,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
116 | } | 117 | } |
117 | #endregion ellenőrzések | 118 | #endregion ellenőrzések |
118 | 119 | ||
119 | - CreateAdminRolesAndUsers();//alapértelmezett Administrator/Admin123 user létrehozása | 120 | + CreateAdminRolesRoleGroupsUsers();//alapértelmezett Administrator/Admin123 user létrehozása |
120 | MembershipUser user = Membership.GetUser(username); | 121 | MembershipUser user = Membership.GetUser(username); |
121 | if (user == null) | 122 | if (user == null) |
122 | { | 123 | { |
@@ -138,7 +139,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -138,7 +139,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
138 | if (!Users.IsInRole(username, rn)) { System.Web.Security.Roles.AddUserToRole(username, rn); } | 139 | if (!Users.IsInRole(username, rn)) { System.Web.Security.Roles.AddUserToRole(username, rn); } |
139 | } | 140 | } |
140 | } | 141 | } |
141 | - else if (administrator) { CreateAdminRolesAndUsers(username, password); } | 142 | + else if (administrator) { CreateAdminRolesRoleGroupsUsers(username, password); } |
142 | 143 | ||
143 | string[] selectedrolenames; | 144 | string[] selectedrolenames; |
144 | if (rolenames != null && rolenames.Any()) | 145 | if (rolenames != null && rolenames.Any()) |
@@ -169,18 +170,30 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -169,18 +170,30 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
169 | return user; | 170 | return user; |
170 | } | 171 | } |
171 | #endregion Create | 172 | #endregion Create |
172 | - #region CreateAdminRolesAndUsers | ||
173 | - public static void CreateAdminRolesAndUsers(string adminun=null, string adminpsw=null) | 173 | + #region CreateAdminRolesRoleGroupsUsers |
174 | + /// <summary> | ||
175 | + /// Létrehozza az Administrator szerepet és szerepkört, | ||
176 | + /// a megnevezett usert a megadott jelszóval létrehozza, | ||
177 | + /// a user-t hozzárendeli az Administrátor szerephez és szerepkörhöz. | ||
178 | + /// </summary> | ||
179 | + /// <param name="adminun"></param> | ||
180 | + /// <param name="adminpsw"></param> | ||
181 | + public static void CreateAdminRolesRoleGroupsUsers(string adminun=null, string adminpsw=null) | ||
174 | { | 182 | { |
175 | if (string.IsNullOrWhiteSpace(adminun)) adminun = Constants.USERNAME_ADMINISTRATOR; | 183 | if (string.IsNullOrWhiteSpace(adminun)) adminun = Constants.USERNAME_ADMINISTRATOR; |
176 | - if (string.IsNullOrWhiteSpace(adminpsw)) adminpsw = Constants.PASSWORD_ADMINISTRATOR; | 184 | + if (string.IsNullOrWhiteSpace(adminpsw)) adminpsw = Constants.PASSWORD_ADMIN123; |
177 | if (!System.Web.Security.Roles.RoleExists(Constants.ROLENAME_USERADMINISTRATOR)) { System.Web.Security.Roles.CreateRole(Constants.ROLENAME_USERADMINISTRATOR); } | 185 | if (!System.Web.Security.Roles.RoleExists(Constants.ROLENAME_USERADMINISTRATOR)) { System.Web.Security.Roles.CreateRole(Constants.ROLENAME_USERADMINISTRATOR); } |
178 | 186 | ||
179 | - MembershipUser user = Membership.GetUser(Constants.USERNAME_ADMINISTRATOR); | ||
180 | - if (user == null) { user = Membership.CreateUser(Constants.USERNAME_ADMINISTRATOR, Constants.PASSWORD_ADMINISTRATOR); } | 187 | + if (!MembershipTools.RoleGroups.IsRoleGroupExist(Constants.ROLEGROUPNAME_ADMINISTRATOR)) MembershipTools.RoleGroups.Create(Constants.ROLEGROUPNAME_ADMINISTRATOR); |
188 | + MembershipTools.Assign.RolesToRoleGroups(Constants.ROLENAME_USERADMINISTRATOR, Constants.ROLEGROUPNAME_ADMINISTRATOR); | ||
189 | + | ||
190 | + MembershipUser user = Membership.GetUser(adminun); | ||
191 | + if (user == null) { user = Membership.CreateUser(adminun, adminpsw); } | ||
181 | if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_USERADMINISTRATOR)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_USERADMINISTRATOR); } | 192 | if (!System.Web.Security.Roles.IsUserInRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_USERADMINISTRATOR)) { System.Web.Security.Roles.AddUserToRole(Constants.USERNAME_ADMINISTRATOR, Constants.ROLENAME_USERADMINISTRATOR); } |
193 | + | ||
194 | + Assign.RoleGroupsToUsers(Constants.ROLEGROUPNAME_ADMINISTRATOR, adminun); | ||
182 | } | 195 | } |
183 | - #endregion CreateAdminRolesAndUsers | 196 | + #endregion CreateAdminRolesRoleGroupsUsers |
184 | #region IsInRole public method | 197 | #region IsInRole public method |
185 | /// <summary> | 198 | /// <summary> |
186 | /// Annak jelzése, hogy a <paramref name="userName"/>-ben megadott nevű felhasználó | 199 | /// Annak jelzése, hogy a <paramref name="userName"/>-ben megadott nevű felhasználó |
@@ -356,6 +369,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -356,6 +369,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
356 | MembershipDBContext.RoleGroups.Add(new DAL.RoleGroup { Name = name, }); | 369 | MembershipDBContext.RoleGroups.Add(new DAL.RoleGroup { Name = name, }); |
357 | MembershipDBContext.SaveChanges(); | 370 | MembershipDBContext.SaveChanges(); |
358 | } | 371 | } |
372 | + | ||
373 | + /// <summary> | ||
374 | + /// true-val tér vissza, ha a megnevezett rolegroup létezik | ||
375 | + /// </summary> | ||
376 | + /// <param name="name"></param> | ||
377 | + /// <returns></returns> | ||
378 | + public static bool IsRoleGroupExist(string name) { return MembershipDBContext.RoleGroups.Any(x => x.Name == name); } | ||
359 | #endregion Create method | 379 | #endregion Create method |
360 | 380 | ||
361 | #region Remove methods | 381 | #region Remove methods |