public Group Create(string name, bool usePermissions) { if (this.Exists(name, null)) { var ex = new StrixMembershipException(string.Format("A group with name {0} already exists", name)); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } var currentUserId = StrixPlatform.User.Id; if (currentUserId == null) { throw new StrixMembershipException("No active user"); } var group = new Group(Guid.NewGuid(), name); group.UsePermissions = usePermissions; group = this._dataSource.Save(group); if (group == null) { Logger.Log(string.Format("An error occurred while creating group {0}", group.Name), LogLevel.Error); } else { var args = new Dictionary<string, object>(); args.Add("Id", group.Id); args.Add("GroupName", group.Name); StrixPlatform.RaiseEvent<GeneralEvent>(new GeneralEvent("GroupCreateEvent", args)); } return group; }
private static void CheckPassword(string password) { if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentNullException("password"); } if (password.Length < StrixMembership.Configuration.Password.MinRequiredPasswordLength) { var ex = new StrixMembershipException(); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } var specialChars = 0; for (int index = 0; index < password.Length; ++index) { if (!char.IsLetterOrDigit(password[index])) { ++specialChars; } } if (specialChars < StrixMembership.Configuration.Password.MinRequiredNonAlphanumericCharacters) { var ex = new StrixMembershipException("The password does not have enough non-alphanumeric characters."); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } }
public Group Create(string name, bool usePermissions) { if (this.Exists(name, null)) { var ex = new StrixMembershipException(string.Format("A group with name {0} already exists", name)); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } var currentUserId = StrixPlatform.User.Id; if (currentUserId == null) { throw new StrixMembershipException("No active user"); } var group = new Group(Guid.NewGuid(), name); group.UsePermissions = usePermissions; group = this._dataSource.Save(group); if (group == null) { Logger.Log(string.Format("An error occurred while creating group {0}", group.Name), LogLevel.Error); } else { var args = new Dictionary <string, object>(); args.Add("Id", group.Id); args.Add("GroupName", group.Name); StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("GroupCreateEvent", args)); } return(group); }
public Group Update(Guid id, string name, bool usePermissions) { if (this.Exists(name, id)) { var ex = new StrixMembershipException(string.Format("A group with name {0} already exists", name)); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } var currentUserId = StrixPlatform.User.Id; if (currentUserId == null) { throw new StrixMembershipException("No active user"); } var group = this.Get(id); if (group != null) { if (group.Name.ToLower() != name.ToLower()) { group.Name = name; } group.UsePermissions = usePermissions; var args = new Dictionary <string, object>(); args.Add("Id", group.Id); args.Add("GroupName", group.Name); StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("GroupUpdateEvent", args)); } return(group); }
private void CheckEmailAvailable(string email, Guid?id = null) { if (string.IsNullOrWhiteSpace(email)) { throw new ArgumentNullException("email"); } var available = !this.Query().Any(u => u.Email.ToLower() == email.ToLower() && (id == null || (id.HasValue && id.Value != u.Id))); if (!available) { var ex = new StrixMembershipException(string.Format("Email {0} is already in use.", email)); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } }
public Group Update(Guid id, string name, bool usePermissions) { if (this.Exists(name, id)) { var ex = new StrixMembershipException(string.Format("A group with name {0} already exists", name)); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } var currentUserId = StrixPlatform.User.Id; if (currentUserId == null) { throw new StrixMembershipException("No active user"); } var group = this.Get(id); if (group != null) { if (group.Name.ToLower() != name.ToLower()) { group.Name = name; } group.UsePermissions = usePermissions; var args = new Dictionary<string, object>(); args.Add("Id", group.Id); args.Add("GroupName", group.Name); StrixPlatform.RaiseEvent<GeneralEvent>(new GeneralEvent("GroupUpdateEvent", args)); } return group; }
private void CheckEmailAvailable(string email, Guid? id = null) { if (string.IsNullOrWhiteSpace(email)) { throw new ArgumentNullException("email"); } var available = !this.Query().Any(u => u.Email.ToLower() == email.ToLower() && (id == null || (id.HasValue && id.Value != u.Id))); if (!available) { var ex = new StrixMembershipException(string.Format("Email {0} is already in use.", email)); Logger.Log(ex.Message, ex, LogLevel.Fatal); throw ex; } }