private void sendInviteEmail(UserInvite invite) { if (System.Text.RegularExpressions.Regex.IsMatch(invite.ReceiverMail, RegPattern.Email) == false) { inviteService.DeleteInvite(invite); logger.Info(lang.get("exEmailFormat") + ": " + invite.Inviter.Name + "[" + invite.ReceiverMail + "]"); return; } MailClient mail = MailClient.Init(); String title = invite.Inviter.Name + lang.get("inviteMailTitle"); String msg = invite.MailBody; Result sentResult = mail.Send(invite.ReceiverMail, title, msg); if (sentResult.IsValid) { inviteService.SendDone(invite); logger.Info(lang.get("inviteSendDone") + ": " + invite.Inviter.Name + "[" + invite.ReceiverMail + "]"); } else { inviteService.SendError(invite); logger.Info(lang.get("inviteSendFailure") + ": " + invite.Inviter.Name + "[" + invite.ReceiverMail + "]"); } }
public bool InviteUser(UserInvite userInvite) { var identityClaims = (ClaimsIdentity)User.Identity; #region guard if (string.IsNullOrEmpty(userInvite.Email)) { return(false); } if (string.IsNullOrEmpty(userInvite.FirstName) && string.IsNullOrEmpty(userInvite.LastName)) { return(false); } #endregion userInvite.CreateBy = identityClaims.FindFirst("UserName").Value; userInvite.ModifyBy = identityClaims.FindFirst("UserName").Value; userInvite.CreateDate = DateTime.UtcNow; userInvite.ModifyDate = DateTime.UtcNow; UserService userService = new UserService(); userService.AddInviteUser(userInvite, identityClaims.FindFirst("Email").Value); return(true); }
public void CancelInvite() { PolicyCheckBuilder() .ExpectCheck(SecurityPolicies.CanManageUsersOnSystem) .AssertSuccess( async userService => { var userInvite = new UserInvite { Email = "*****@*****.**", Accepted = false, Role = new IdentityRole(), RoleId = Guid.Empty.ToString(), Created = DateTime.UtcNow, CreatedBy = "Test creator" }; var userAndRolesContextId = Guid.NewGuid().ToString(); await using (var userAndRolesDbContext = InMemoryUserAndRolesDbContext(userAndRolesContextId)) { await userAndRolesDbContext.AddAsync(userInvite); await userAndRolesDbContext.SaveChangesAsync(); } await using (var userAndRolesDbContext = InMemoryUserAndRolesDbContext(userAndRolesContextId)) { var userManagementService = BuildUserManagementService(userAndRolesDbContext, userService.Object); return(await userManagementService.CancelInvite(userInvite.Email)); } }); }
public async Task <UserInvite> Create(string email, string roleId, Guid createdById) { var existingInvite = await _usersAndRolesDbContext .UserInvites .AsQueryable() .SingleOrDefaultAsync(i => i.Email.ToLower().Equals(email.ToLower())); if (existingInvite != null) { return(existingInvite); } var newInvite = new UserInvite { Email = email.ToLower(), RoleId = roleId, Created = DateTime.UtcNow, CreatedById = createdById.ToString(), }; _usersAndRolesDbContext.Add(newInvite); await _usersAndRolesDbContext.SaveChangesAsync(); return(newInvite); }
public void ResendInvite_KeyIsRegenerated() { UserInvite userInvite = UserInvite.Create(this.userInvitedById, "*****@*****.**"); Guid inviteKeyCurrent = userInvite.InviteKey; userInvite.ResendInvite(); inviteKeyCurrent.Should().NotBe(userInvite.InviteKey); }
public IHttpActionResult SendUserInvite(string email) { var userdevice = UserManager.FindByName(User.Identity.Name); var user = _db.Users.First(node => node.Id == userdevice.UserId); var message = new UserInvite(user, email, ControllerContext); message.Send(); return(Ok()); }
public void Remove_UserWasNotInTheGroup_Throws() { Mock <Group> group = new Mock <Group>(); group.SetupGet(x => x.Id).Returns(Guid.Empty); UserInvite userInvite = UserInvite.Create(this.userInvitedById, "*****@*****.**"); userInvite.Remove(group.Object); }
public void Add_GrouIsNull_Throws() { Mock <Group> group = new Mock <Group>(); group.SetupGet(x => x.Id).Returns(Guid.Empty); UserInvite userInvite = UserInvite.Create(this.userInvitedById, "*****@*****.**"); userInvite.Add(null); }
/// <summary> /// 保存成员(并自动添加企业号成员) /// </summary> /// <param name="userIds">成员Id</param> /// <returns></returns> public void SaveMember(string[] userIds, out string msg) { List <UserEntity> usreList = userBLL.GetList().ToList(); List <WeChatDeptRelationEntity> departmentList = weChatOrganizeBLL.GetList().ToList(); int succeed = 0; int error = 0; foreach (var userId in userIds) { try { UserEntity userEntity = usreList.Find(t => t.UserId == userId); WeChatDeptRelationEntity weChatDeptRelationEntity = departmentList.Find(t => t.DeptId == userEntity.DepartmentId); UserCreate userCreate = new UserCreate(); userCreate.userid = userEntity.Account; userCreate.name = userEntity.RealName; userCreate.position = userEntity.PostName; userCreate.mobile = userEntity.Mobile; userCreate.gender = userEntity.Gender == 1 ? "1" : "2"; userCreate.email = userEntity.Email; userCreate.weixinid = userEntity.WeChat; string departmentId = weChatDeptRelationEntity.WeChatDeptId.ToString(); userCreate.department = new List <string>() { departmentId }; var result = userCreate.Send(); if (result.errcode == 0) { UserInvite userInvite = new UserInvite(); userInvite.userid = userCreate.userid; result = userInvite.Send(); } WeChatUserRelationEntity weChatUserRelationEntity = new WeChatUserRelationEntity(); weChatUserRelationEntity.UserRelationId = userCreate.userid; weChatUserRelationEntity.UserId = userCreate.userid; weChatUserRelationEntity.DeptId = weChatDeptRelationEntity.DeptId; weChatUserRelationEntity.DeptName = weChatDeptRelationEntity.DeptName; weChatUserRelationEntity.WeChatDeptId = departmentId.ToInt(); weChatUserRelationEntity.SyncState = result.errcode.ToString(); weChatUserRelationEntity.SyncLog = result.errmsg; service.SaveForm("", weChatUserRelationEntity); succeed++; } catch (System.Exception) { error++; } } msg = "成功:" + succeed + " ;错误:" + error; }
public UserInviteView(UserInvite userInvite) { Id = userInvite.Id; GuildId = userInvite.GuildId.ToString(); TargetChannelId = userInvite.TargetChannelId.ToString(); JoinedUserId = userInvite.JoinedUserId.ToString(); UsedInvite = userInvite.UsedInvite; InviteIssuerId = userInvite.InviteIssuerId.ToString(); JoinedAt = userInvite.JoinedAt; InviteCreatedAt = userInvite.InviteCreatedAt; }
public void Add_UserIsAlreadyAddedToTheGroup_Throws() { Mock <Group> group = new Mock <Group>(); group.SetupGet(x => x.Id).Returns(Guid.Empty); UserInvite userInvite = UserInvite.Create(this.userInvitedById, "*****@*****.**"); userInvite.Add(group.Object); userInvite.Add(group.Object); }
public void Add_UserIsAddedToTheGroup() { Mock <Group> group = new Mock <Group>(); group.SetupGet(x => x.Id).Returns(Guid.Empty); UserInvite userInvite = UserInvite.Create(this.userInvitedById, "*****@*****.**"); userInvite.Add(group.Object); userInvite.GroupIds[0].Should().Be(Guid.Empty); }
public virtual void AddMail( User inviter, List<String> mailList, String mailBody ) { foreach (String mail in mailList) { if (hasExist( inviter, mail )) continue; UserInvite ui = new UserInvite(); ui.Inviter = inviter; ui.MailBody = mailBody; ui.ReceiverMail = mail; ui.insert(); } }
/// <summary> /// Remove the invite based on the id. /// </summary> /// <param name="inviteId"></param> /// <returns>True if the invite is removed, false otherwise.</returns> public bool RemoveInvite(int inviteId) { UserInvite invite = _inviteRepository.GetById(inviteId); if (invite == null) { return(false); } _inviteRepository.Delete(invite); return(true); }
private void UserInviteClick(object sender, System.Windows.RoutedEventArgs e) { var username = UserInvite.Text; string factoryString = (string)FactoryList.SelectedItem; int factoryID = getIdFromFactoryString(factoryString); ClientServerUtil csu = ClientServerUtil.getInstance(); String message = csu.addMemberToMemberAccess(factoryID, username, factoryString); showPopUp(message); UserInvite.Clear(); }
public void Remove_UserIsRemovedFromTheGroup() { Mock <Group> group = new Mock <Group>(); group.SetupGet(x => x.Id).Returns(Guid.Empty); UserInvite userInvite = UserInvite.Create(this.userInvitedById, "*****@*****.**"); userInvite.Add(group.Object); userInvite.Remove(group.Object); userInvite.GroupIds.Should().HaveCount(0); }
public async Task <UserInvite> SendInviteEmail(UserInvite userInvite) { var path = "SendInvite"; var userInviteRequestDto = new UserInviteRequestDTO() { ConfirmationUri = CreateConfirmationUri(), UserInvite = userInvite }; var controllerResponseDTO = await Post <UserInviteRequestDTO>(path, userInviteRequestDto); return(controllerResponseDTO.Content.UserInvite); }
public void Remove_UserInviteIsInCollection_Removes() { Guid userInvitedById = Guid.NewGuid(); UserInvite userInviteA = UserInvite.Create( userInvitedById, "*****@*****.**" ); this.group.Add(userInviteA); this.group.Remove(userInviteA); this.group.Invites.Should().HaveCount(0); }
// Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate // Umbraco.Code.MapAll -Id -TourData -StartContentIds -StartMediaIds -Language -Username // Umbraco.Code.MapAll -PasswordQuestion -SessionTimeout -EmailConfirmedDate -InvitedDate // Umbraco.Code.MapAll -SecurityStamp -Avatar -ProviderUserKey -RawPasswordValue // Umbraco.Code.MapAll -RawPasswordAnswerValue -Comments -IsApproved -IsLockedOut -LastLoginDate // Umbraco.Code.MapAll -LastPasswordChangeDate -LastLockoutDate -FailedPasswordAttempts private void Map(UserInvite source, IUser target, MapperContext context) { target.Email = source.Email; target.Key = source.Key; target.Name = source.Name; target.IsApproved = false; target.ClearGroups(); var groups = _userService.GetUserGroupsByAlias(source.UserGroups.ToArray()); foreach (var group in groups) { target.AddGroup(group.ToReadOnlyGroup()); } }
public async Task <UserInvite> CreateInvite(InviteViewModel inviteVM) { var invite = new UserInvite() { Email = inviteVM.InviteEmail, PracticeId = (await _context.Practices.Where(prac => prac.SubscriberPractices.Any(sp => sp.SubscriberUserId == _userProvider.GetUserId())).SingleAsync()).Id, CreationDate = _dateProvider.GetCurrentDateTime(), Code = _inviteCodeProvider.GetNewInviteCode(), Used = false }; _context.UserInvites.Add(invite); await _context.SaveChangesAsync(); return(invite); }
public virtual void Add(UserInvite userInvite) { if (userInvite == null) { throw new ValidationException("UserInvite can't be empty"); } if (this.invites.Contains(userInvite)) { throw new ValidationException("UserInvite is already in the group"); } this.invites.Add(userInvite); this.DateModified = TimeProvider.Current.UtcNow; }
public virtual void AddMail(User inviter, List <String> mailList, String mailBody) { foreach (String mail in mailList) { if (hasExist(inviter, mail)) { continue; } UserInvite ui = new UserInvite(); ui.Inviter = inviter; ui.MailBody = mailBody; ui.ReceiverMail = mail; ui.insert(); } }
public void Add_SameUserInvite_ThrowsException() { Guid userInvitedById = Guid.NewGuid(); UserInvite userInviteA = UserInvite.Create( userInvitedById, "*****@*****.**" ); UserInvite userInviteAA = UserInvite.Create( userInvitedById, "*****@*****.**" ); this.group.Add(userInviteA); this.group.Add(userInviteAA); }
public void Create_EmailIsProvided() { Mock <UserInvite> expected = new Mock <UserInvite>(); expected.SetupGet(x => x.Email).Returns("*****@*****.**"); expected.SetupGet(x => x.DateCreated).Returns(TimeProvider.Current.UtcNow); expected.SetupGet(x => x.DateModified).Returns(TimeProvider.Current.UtcNow); expected.SetupGet(x => x.GroupIds).Returns(new List <Guid>().AsReadOnly()); expected.SetupGet(x => x.InvitedByUserId).Returns(this.userInvitedById); UserInvite actual = UserInvite.Create(this.userInvitedById, "*****@*****.**"); actual.ShouldBeEquivalentTo(expected.Object, opt => opt.Excluding( prop => prop.PropertyPath == "Id" || prop.PropertyPath == "InviteKey" )); }
/// <summary> /// Checks whether the invite code is valid or not based on the code and the creation time, if the invite is older than 1 day it will be removed (and return false). /// </summary> /// <param name="inviteCode"></param> /// <param name="invite"></param> /// <returns>True if the invite is valid, false otherwise.</returns> public bool IsValidInviteCode(string inviteCode, out UserInvite invite) { invite = _inviteRepository.TableNoTracking.FirstOrDefault(invite => invite.InviteCode == inviteCode); if (invite == null) { return(false); } //invites are only valid for a day if (invite.CreationTime.AddDays(1) < DateTime.Now) { _inviteRepository.Delete(invite); invite = null; return(false); } return(true); }
public async Task <Response> SendEmailInvite(UserInvite invite, Uri confirmationUri) { var client = new SendGridClient(SendGridOptions.APIKey); var message = new SendGridMessage(); message.SetFrom(SendGridOptions.FromEmail); message.AddTo(invite.EmailAddress); message.SetTemplateId(SendGridOptions.TemplateId); var emailTemplateData = new EmailTemplateData() { FirstName = "Josh", ConfirmationUri = confirmationUri }; message.SetTemplateData(emailTemplateData); message.SetClickTracking(true, true); return(await client.SendEmailAsync(message)); }
public static void UpdateUserInvite(SocketGuildUser user, Invite invite, bool unknown = false) { using MySqlConnection connection = MySQL.getConnection(); if (unknown) { invite = new Invite { Code = "Unknown", UserID = 1, Uses = 0 } } ; string query = "SELECT * FROM UserInvites"; IEnumerable <UserInvite> userInvites = connection.Query <UserInvite>(query); foreach (UserInvite UserInvite in userInvites) { if (UserInvite.UserID == user.Id) { // Remove it if it exists. query = $"DELETE FROM UserInvites WHERE Code={UserInvite.Code}"; connection.Execute(query); return; } } // Add it because it doesn't exist. UserInvite userInvite = new UserInvite { UserID = user.Id, Code = invite.Code }; query = $"INSERT INTO UserInvites (UserID, Code) VALUES ({userInvite.UserID}, '{userInvite.Code}')"; connection.Execute(query); }
public bool AddInviteUser(UserInvite userInvite, string inviterEmail) { using (var context = new ApplicationDbContext()) { try { //Get UserId var inviter = context.Users.FirstOrDefault(x => x.Email == inviterEmail); userInvite.InviterUserId = inviter.Id; context.UserInviites.Add(userInvite); context.SaveChanges(); //SEND EMAIL return(true); } catch (Exception e) { LogSingleton.ErrorException(e); return(false); } } }
public async Task <InviteCodeResult> GetCodeDetails(string code) { UserInvite dbInvite = await _context.UserInvites.Where(invite => invite.Code == code).SingleOrDefaultAsync(); if (dbInvite == null) { return new InviteCodeResult() { Success = false, Error = "Code not found." } } ; if (dbInvite.Used) { return new InviteCodeResult() { Success = false, Error = "Code has already been used." } } ; if (dbInvite.CreationDate.AddDays(7) < _dateProvider.GetCurrentDateTime()) { return new InviteCodeResult() { Success = false, Error = "Code expired." } } ; dbInvite.Used = true; await _context.SaveChangesAsync(); return(new InviteCodeResult() { Success = true, Error = "", PracticeId = dbInvite.PracticeId }); }
public async Task <ActionResult> AddLike(string username) { var sourceUserId = User.GetUserId(); var invitedUser = await _unitOfWork.UserRepository.GetUserByUsername(username); var sourceUser = await _unitOfWork.InviteRepository.GetUserWithInvites(sourceUserId); if (invitedUser == null) { return(NotFound()); } if (sourceUser.UserName == username) { return(BadRequest("You cannot invite yourself")); } var userInvite = await _unitOfWork.InviteRepository.GetUserInvite(sourceUserId, invitedUser.Id); if (userInvite != null) { return(BadRequest("You already invited this user")); } userInvite = new UserInvite { SourceUserId = sourceUserId, InvitedUserId = invitedUser.Id }; sourceUser.InvitedUsers.Add(userInvite); if (await _unitOfWork.Complete()) { return(Ok()); } return(BadRequest("Failed to invite user")); }
public async Task <Either <ActionResult, UserInvite> > InviteUser(string email, string inviteCreatedByUser, string roleId) { return(await _userService .CheckCanManageAllUsers() .OnSuccess <ActionResult, Unit, UserInvite>(async() => { if (string.IsNullOrWhiteSpace(email)) { return ValidationActionResult(InvalidEmailAddress); } if (_usersAndRolesDbContext.Users.Any(u => u.Email.ToLower() == email.ToLower())) { return ValidationActionResult(UserAlreadyExists); } var role = await _usersAndRolesDbContext.Roles.FirstOrDefaultAsync(r => r.Id == roleId); if (role == null) { return ValidationActionResult(InvalidUserRole); } var invite = new UserInvite { Email = email.ToLower(), Created = DateTime.UtcNow, CreatedBy = inviteCreatedByUser, Role = role }; await _usersAndRolesDbContext.UserInvites.AddAsync(invite); await _usersAndRolesDbContext.SaveChangesAsync(); SendInviteEmail(email); return invite; })); }
private void sendInviteEmail( UserInvite invite ) { if (System.Text.RegularExpressions.Regex.IsMatch( invite.ReceiverMail, RegPattern.Email ) == false) { inviteService.DeleteInvite( invite ); logger.Info( lang.get( "exEmailFormat" ) + ": " + invite.Inviter.Name + "[" + invite.ReceiverMail + "]" ); return; } MailService mail = MailUtil.getMailService(); String title = invite.Inviter.Name + lang.get( "inviteMailTitle" ); String msg = invite.MailBody; Boolean isSent = mail.send( invite.ReceiverMail, title, msg ); if (isSent) { inviteService.SendDone( invite ); logger.Info( lang.get( "inviteSendDone" ) + ": " + invite.Inviter.Name + "[" + invite.ReceiverMail + "]" ); } else { inviteService.SendError( invite ); logger.Info( lang.get( "inviteSendFailure" ) + ": " + invite.Inviter.Name + "[" + invite.ReceiverMail + "]" ); } }
public void SendError( UserInvite invite ) { invite.SendStatus = UserInviteEmailStatus.Failure; invite.update(); }
public void DeleteInvite( UserInvite invite ) { invite.delete(); }
public void SendDone( UserInvite invite ) { invite.SendStatus = UserInviteEmailStatus.Done; invite.update(); }