public BaseUser SignUp(string login, string email, string password, bool saveChanges) { if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password)) { throw new ArgumentException(); } Guid hash, salt; SecurityService.GeneratePasswordHash(password, out hash, out salt); var federation = DataService.PerThread.GroupSet.SingleOrDefault(x => x.Id == ConstHelper.RootGroupId); if (federation == null) { throw new BusinessLogicException("Не создана группа Федерация"); } var encryptedEmail = CryptographyService.EncryptEmail(email); var emailUser = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.EncryptedEmail == encryptedEmail); if (emailUser != null) { throw new BusinessLogicException("Указанная почта уже используется"); } var user = new User // TODO: Регистрация админов должна идти отдельной функцией { Login = login, Email = email, Password = hash, Salt = salt, IsVerified = false, RegistrationDate = DateTime.Now, LiveJournalSindication = true, LiveJournalSindicateAsDraft = false, LastActivity = DateTime.Now }; user.SubscriptionSettings = new SubscriptionSettings { SubscriptionEmail = email }; var gm = new GroupMember { EntryDate = DateTime.Now, GroupId = federation.Id, State = (byte)GroupMemberState.Approved, UserId = user.Id }; DataService.PerThread.GroupMemberSet.AddObject(gm); SubscriptionService.SubscribeToGroup(federation, user); VotingService.AnalizeGroupMemberBulletins(gm.Id); return(user); }
/// <summary> /// Добавление указанного пользователя в группу /// </summary> /// <param name="userId">идентификатор пользователя</param> /// <param name="groupId">идентификатор группы</param> /// <returns>экземпляр участника группы</returns> public GroupMember AddMember(Guid userId, Guid groupId, bool saveChanges = true) { var group = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Id == groupId); if (group == null) { throw new BusinessLogicException("Не найдена группа с указанным идентификатором"); } var gm = DataService.PerThread.GroupMemberSet.SingleOrDefault(m => m.GroupId == groupId && m.UserId == userId); if (gm == null) { gm = new GroupMember { EntryDate = DateTime.Now, GroupId = groupId, State = (byte)GroupMemberState.NotApproved, UserId = userId }; if (!group.PrivacyEnum.HasFlag(GroupPrivacy.MemberModeration) && group.State != (byte)GroupState.Blank || group.State == (byte)GroupState.Archive) { gm.State = (byte)GroupMemberState.Approved; } DataService.PerThread.GroupMemberSet.AddObject(gm); DataService.PerThread.SaveChanges(); if (group.GroupMembers.Count(x => x.State == (byte)GroupMemberState.Moderator) == 0) { GroupService.ChangeMemberStatus(userId, group.Id, GroupMemberState.Moderator); } SubscriptionService.SubscribeToGroup(group.Url, gm.UserId); } else if (gm.State != (byte)GroupMemberState.Approved && gm.State != (byte)GroupMemberState.Moderator) { if (gm.State == (byte)GroupMemberState.Banned && DateTime.Now < gm.ExitDate.Value.AddMonths(2)) { throw new BusinessLogicException("Вы не можете вступать в эту группу еще " + (gm.ExitDate.Value.AddMonths(2) - DateTime.Now).Days + ", так как были заблокированы"); } if (group.GroupMembers.Count(x => x.State == (byte)GroupMemberState.Moderator) == 0) { GroupService.ChangeMemberStatus(userId, group.Id, GroupMemberState.Moderator); } else if (!group.PrivacyEnum.HasFlag(GroupPrivacy.MemberModeration) && group.State != (byte)GroupState.Blank) { gm.State = (byte)GroupMemberState.Approved; } else { gm.State = (byte)GroupMemberState.NotApproved; } } UpdateGroupState(group.Id); return(gm); }