public UserModel AuthenticateAgainstDomain(string domainName, string password) { try { var directoryEntry = new DirectoryEntry(LDAP, domainName, password); var searchAdForUser = new DirectorySearcher(directoryEntry) { Filter = "(&(objectClass=user)(anr=" + domainName + "))" }; var retrievedUser = searchAdForUser.FindOne(); var ldapEmailAddress = retrievedUser.Properties["mail"][0].ToString(); var existingUser = this.userRepository.Find(new UserSpecification().WithEmailAddress(ldapEmailAddress)); if(existingUser == null) { existingUser = new User { EmailAddress = ldapEmailAddress }; } this.userRepository.Save(existingUser); var userModel = new UserModel() { Title = retrievedUser.Properties["title"][0].ToString(), Mobile = retrievedUser.Properties["mobile"][0].ToString(), EmailAddress = ldapEmailAddress, Name = retrievedUser.Properties["givenname"][0].ToString(), Surname = retrievedUser.Properties["sn"][0].ToString() }; return userModel; } catch (DirectoryServicesCOMException ex) { throw new Exception(ex.Message); } }
private void LogSupportTicket(UserModel user, string message, SupportType supportType) { this.supportApi.CreateSupportTicketOnTrello(new SupportTicketModel() { Message = String.Format("Support Ticket Logged From Bot: {0}", message), Subject = String.Format("Support Ticket from {0}", user.DisplayName), Status = 1, Type = (int)supportType }); }
private BotMessage FineRecipients(List<string> userIds, UserModel issuer, string reason, SlackMessage message) { foreach(var slackId in userIds) { var userModel = this.userApi.GetUserBySlackId(slackId); IssueFineResult result = this.fineApi.IssueFine(issuer.Id, userModel.Id, reason); if (result.HasErrors) { return this.GetErrorResponse(result, message); } } reactionApi.AddReaction(ConfigurationManager.AppSettings["BotKey"], "ok_hand", message.GetChannelId(), message.GetTimeStamp()); return new BotMessage{ Text = ""}; }
public void SecondOldestPendingFine_SecondsCorrectFine() { // Arrange: IRepository<User, UserDataModel, Guid> userRepository = MockRepository.GenerateMock<IRepository<User, UserDataModel, Guid>>(); IRepository<Payment, PaymentDataModel, Guid> paymentRepository = MockRepository.GenerateMock<IRepository<Payment, PaymentDataModel, Guid>>(); IFineMapper fineMapper = MockRepository.GenerateMock<IFineMapper>(); IUserMapper userMapper = MockRepository.GenerateMock<IUserMapper>(); IPaymentMapper paymentMapper = MockRepository.GenerateMock<IPaymentMapper>(); IExcelExportService<FineExportModel> excelExportService = MockRepository.GenerateMock<IExcelExportService<FineExportModel>>(); var fine = new Fine{AwardedDate = DateTime.Now}; var user = new User{Fines = new List<Fine>{fine, new Fine{AwardedDate = DateTime.Now.AddMinutes(1)}}}; userRepository.Stub(x => x.FindAll(null)).IgnoreArguments().Return(new List<User> { user }); var userModel = new UserModel(); userMapper.Stub(x => x.MapToModelShallow(user)).Return(userModel); FineApi fineApi = new FineApi(userRepository, paymentRepository, fineMapper, userMapper, paymentMapper, excelExportService, null, null, null, null, null); // Pre-Assert: fine.Pending.Should().Be.True(); // Act: fineApi.SecondOldestPendingFine(Guid.NewGuid()); // Assert: fine.Pending.Should().Be.False(); userRepository.AssertWasCalled(x => x.Save(user)); fineMapper.AssertWasCalled(x => x.MapToModelWithUser(fine, userModel)); }
private void LogSupportTicketWithType(Match match, UserModel user) { SupportType supportType; var couldParseEnum = Enum.TryParse(match.Groups[1].Value, true, out supportType); if(!couldParseEnum) { supportType = SupportType.General; } var message = match.Groups[2].Value; this.LogSupportTicket(user, message, supportType); }
public List<UserModel> GetAllDomainUsers(string domainName, string password) { var domainUsers = new List<UserModel>(); try { var directoryEntry = new DirectoryEntry(LDAP, domainName, password); var directorySearcher = new DirectorySearcher(directoryEntry) { Filter = "(&(objectClass=user)(objectCategory=person))" }; directorySearcher.PropertiesToLoad.Add("samaccountname"); directorySearcher.PropertiesToLoad.Add("mail"); directorySearcher.PropertiesToLoad.Add("usergroup"); directorySearcher.PropertiesToLoad.Add("displayname"); var searchResultsCollection = directorySearcher.FindAll(); for (var counter = 0; counter < searchResultsCollection.Count; counter++) { var result = searchResultsCollection[counter]; if (!result.Properties.Contains("samaccountname") || !result.Properties.Contains("mail") || !result.Properties.Contains("displayname")) continue; var userModel = new UserModel { EmailAddress = result.Properties["mail"][0].ToString(), DisplayName = result.Properties["displayname"][0].ToString() }; domainUsers.Add(userModel); } } catch (DirectoryServicesCOMException ex) { throw new Exception(ex.Message); } catch (Exception ex) { throw new Exception(ex.Message); } return domainUsers; }
public UserModel MapSlackModelToLdapModel(UserModel ldapModel, UserModel slackModel) { //@Kurt, can you suggest a better way? ldapModel.SlackId = slackModel.SlackId; ldapModel.Id = slackModel.Id; ldapModel.DisplayName = slackModel.DisplayName; ldapModel.AwardedFineCount = slackModel.AwardedFineCount; ldapModel.PendingFineCount = slackModel.PendingFineCount; ldapModel.Fines = slackModel.Fines; ldapModel.Image = slackModel.Image; return ldapModel; }
public void UpdateUser(UserModel userModel) { var user = this.userRepository.Get(userModel.Id); user.DisplayName = userModel.DisplayName; this.userRepository.Save(user); }
public FineWithUserModel MapToModelWithUser(Fine fine, UserModel shallowUserModel, Payment payment) { return new FineWithUserModel { IssuerId = fine.IssuerId, Reason = fine.Reason, PaymentImageBytes = payment != null ? this.MapPaymentImage(payment.PaymentImage) : null, SeconderId = fine.SeconderId, Pending = fine.Pending, AwardedDate = fine.AwardedDate, User = shallowUserModel }; }
public FineWithUserModel MapToModelWithUser(Fine fine, UserModel shallowUserModel) { return this.MapToModelWithUser(fine, shallowUserModel, null); }