private static void ParseGroupXml(XDoc groupDoc, out uint?id, out string name, out ServiceBE authService, out RoleBE role, out UserBE[] userList) { name = groupDoc["groupname"].AsText ?? groupDoc["name"].AsText; string authserviceidstr = groupDoc["service.authentication/@id"].AsText; string rolestr = groupDoc["permissions.group/role"].AsText; authService = null; role = null; id = null; if (!groupDoc["@id"].IsEmpty) { uint id_temp; if (!uint.TryParse(groupDoc["@id"].Contents, out id_temp)) { throw new GroupIdAttributeInvalidArgumentException(); } id = id_temp; } if (!string.IsNullOrEmpty(authserviceidstr)) { uint serviceid; if (!uint.TryParse(authserviceidstr, out serviceid)) { throw new ServiceAuthIdAttrInvalidArgumentException(); } authService = ServiceBL.GetServiceById(serviceid); if (authService == null) { throw new ServiceDoesNotExistInvalidArgumentException(serviceid); } } if (!string.IsNullOrEmpty(rolestr)) { role = PermissionsBL.GetRoleByName(rolestr); if (role == null) { throw new RoleDoesNotExistInvalidArgumentException(rolestr); } } else { role = PermissionsBL.RetrieveDefaultRoleForNewAccounts(); } if (!groupDoc["users"].IsEmpty) { userList = ReadUserListXml(groupDoc["users"]); } else { userList = new UserBE[] { } }; }
public static UserBE CreateNewUser(UserBE newUser) { if (newUser == null) { return(null); } //throw exception if licensing does not allow creation of another user DekiContext.Current.LicenseManager.IsUserCreationAllowed(true); if (newUser.RoleId == 0) { RoleBE defaultRole = PermissionsBL.RetrieveDefaultRoleForNewAccounts(); if (defaultRole != null) { newUser.RoleId = defaultRole.ID; } } ValidateUser(newUser); newUser.CreateTimestamp = DateTime.UtcNow; uint userId = DbUtils.CurrentSession.Users_Insert(newUser); if (userId == 0) { return(null); } newUser.ID = userId; PageBE userHomepage = null; try { // User homepages are created upon user creation (an attempt to create user homepages may also be done upon login) userHomepage = PageBL.CreateUserHomePage(newUser); } catch (Exception e) { _log.WarnExceptionFormat(e, "Error creating user page for {0}", newUser); } if (userHomepage != null) { var rcUser = UserBL.GetUserById(userHomepage.UserID) ?? DekiContext.Current.User ?? newUser; RecentChangeBL.AddUserCreatedRecentChange(DekiContext.Current.Now, userHomepage, rcUser, DekiResources.USER_ADDED(newUser.Name)); } DekiContext.Current.Instance.EventSink.UserCreate(DekiContext.Current.Now, newUser); return(newUser); }