/// <summary> /// Add new user /// </summary> /// <param name="user">Blog user</param> /// <returns>Saved user</returns> public BlogUser Add(BlogUser user) { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.CreateNewUsers)) throw new System.UnauthorizedAccessException(); if (user == null || string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Email) || string.IsNullOrEmpty(user.Password)) { throw new ApplicationException("Error adding new user; Missing required fields"); } if (!Security.IsAuthorizedTo(Rights.CreateNewUsers)) throw new ApplicationException("Not authorized"); // create user var usr = Membership.CreateUser(user.UserName, user.Password, user.Email); if (usr == null) throw new ApplicationException("Error creating new user"); UpdateUserProfile(user); UpdateUserRoles(user); user.Password = ""; return user; }
static bool UpdateUserRoles(BlogUser user) { try { // remove all user roles and add only checked string[] currentRoles = Roles.GetRolesForUser(user.UserName); if (currentRoles.Length > 0) Roles.RemoveUserFromRoles(user.UserName, currentRoles); if (user.Roles.Count > 0) { string[] roles = user.Roles.Where(ur => ur.IsChecked).Select(r => r.RoleName).ToArray(); if(roles.Length > 0) Roles.AddUsersToRoles(new string[] { user.UserName }, roles); else Roles.AddUsersToRoles(new string[] { user.UserName }, new string[] { BlogConfig.AnonymousRole }); } return true; } catch (Exception ex) { Utils.Log("Error updating user roles", ex); return false; } }
static bool UpdateUserProfile(BlogUser user) { if (user == null || string.IsNullOrEmpty(user.UserName)) return false; var pf = AuthorProfile.GetProfile(user.UserName) ?? new AuthorProfile(user.UserName); try { pf.DisplayName = user.Profile.DisplayName; pf.FirstName = user.Profile.FirstName; pf.MiddleName = user.Profile.MiddleName; pf.LastName = user.Profile.LastName; pf.EmailAddress = user.Email; // user.Profile.EmailAddress; DateTime date; if (user.Profile.Birthday.Length == 0) user.Profile.Birthday = "1/1/1001"; if (DateTime.TryParse(user.Profile.Birthday, out date)) pf.Birthday = date; pf.PhotoUrl = user.Profile.PhotoUrl.Replace("\"", ""); pf.Private = user.Profile.Private; pf.PhoneMobile = user.Profile.PhoneMobile; pf.PhoneMain = user.Profile.PhoneMain; pf.PhoneFax = user.Profile.PhoneFax; pf.CityTown = user.Profile.CityTown; pf.RegionState = user.Profile.RegionState; pf.Country = user.Profile.Country; pf.AboutMe = user.Profile.AboutMe; pf.Save(); UpdateProfileImage(pf); } catch (Exception ex) { Utils.Log("Error editing profile", ex); return false; } return true; }
/// <summary> /// Save user profile /// </summary> /// <param name="user">Blog user</param> /// <returns>True on success</returns> public bool SaveProfile(BlogUser user) { return UpdateUserProfile(user); }
/// <summary> /// Update user /// </summary> /// <param name="user">User to update</param> /// <returns>True on success</returns> public bool Update(BlogUser user) { if (!Security.IsAuthorizedTo(Rights.EditOwnUser)) throw new System.UnauthorizedAccessException(); if (user == null || string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Email)) throw new ApplicationException("Error adding new user; Missing required fields"); // update user var usr = Membership.GetUser(user.UserName); if (usr == null) return false; usr.Email = user.Email; Membership.UpdateUser(usr); //change user password if (!string.IsNullOrEmpty(user.OldPassword) && !string.IsNullOrEmpty(user.Password)) ChangePassword(usr, user.OldPassword, user.Password); UpdateUserProfile(user); UpdateUserRoles(user); return true; }
/// <summary> /// Save user profile /// </summary> /// <param name="user">Blog user</param> /// <returns>True on success</returns> public bool SaveProfile(BlogUser user) { if (Self(user.UserName) && !Security.IsAuthorizedTo(Rights.EditOwnUser)) throw new UnauthorizedAccessException(); if (!Self(user.UserName) && !Security.IsAuthorizedTo(Rights.EditOtherUsers)) throw new UnauthorizedAccessException(); return UpdateUserProfile(user); }
public bool SaveProfile(BlogUser user) { return true; }
public bool Update(BlogUser user) { return true; }
public BlogUser Add(BlogUser user) { return new BlogUser(); }
static bool UpdateUserRoles(BlogUser user) { try { // remove all user roles and add only checked string[] currentRoles = Roles.GetRolesForUser(user.UserName); if (currentRoles.Length > 0) Roles.RemoveUserFromRoles(user.UserName, currentRoles); bool contributorChange = false; bool authorChange = false; if (user.Roles.Count > 0) { List<string> roles = user.Roles.Where(ur => ur.IsChecked).Select(r => r.RoleName).ToList(); if (!currentRoles.Contains("Contributor") && roles.Contains("Contributor")) contributorChange = true; if (!currentRoles.Contains("Author") && roles.Contains("Author")) authorChange = true; if (!currentRoles.Contains("Administrators") && roles.Contains("Administrators")) roles.Remove("Administrators"); if (roles.Count > 0) Roles.AddUsersToRoles(new string[] { user.UserName }, roles.ToArray()); else Roles.AddUsersToRoles(new string[] { user.UserName }, new string[] { BlogConfig.AnonymousRole }); } if (contributorChange) { var id = RDN.Library.Classes.Account.User.GetMemberId(user.UserName); var member = RDN.Library.Cache.SiteCache.GetPublicMember(id); var emailData = new Dictionary<string, string> { { "derbyname",member.DerbyName}, {"link",RollinNewsConfig.DEFAULT_LOGIN_URL} }; EmailServer.SendEmail(RollinNewsConfig.DEFAULT_EMAIL, RollinNewsConfig.DEFAULT_EMAIL_FROM_NAME, user.Email, EmailServer.DEFAULT_SUBJECT_ROLLIN_NEWS + " Added As Contributor", emailData, EmailServerLayoutsEnum.RNAddedAsEditor); } if (authorChange) { var id = RDN.Library.Classes.Account.User.GetMemberId(user.UserName); var member = RDN.Library.Cache.SiteCache.GetPublicMember(id); var emailData = new Dictionary<string, string> { { "derbyname",member.DerbyName}, {"link",RollinNewsConfig.DEFAULT_LOGIN_URL} }; EmailServer.SendEmail(RollinNewsConfig.DEFAULT_EMAIL, RollinNewsConfig.DEFAULT_EMAIL_FROM_NAME, user.Email, EmailServer.DEFAULT_SUBJECT_ROLLIN_NEWS + " Added As Author", emailData, EmailServerLayoutsEnum.RNAddedAsTrustedEditor); } return true; } catch (Exception ex) { ErrorDatabaseManager.AddException(ex, ex.GetType(), additionalInformation: Newtonsoft.Json.JsonConvert.SerializeObject(user)); return false; } }