Example #1
0
        public async Task <IActionResult> Invite([FromForm] InviteUserDto dto)
        {
            if (ModelState.IsValid)
            {
                await _votingService.InviteAsync(dto);

                return(RedirectToAction("Get", new { id = dto.VotingId }));
            }

            return(View(dto));
        }
Example #2
0
 public RpsData <string> GetInviteCode(ParamUserBase param)
 {
     if (param.GameType == GameTypeEnum.小程序)
     {
         InviteUserDto inviteUserDto = new InviteUserDto();
         inviteUserDto.UserId       = param.Id;
         inviteUserDto.DateTimeTick = DateTime.Now.Ticks;
         var str    = JsonConvert.SerializeObject(inviteUserDto);
         var result = SecurityHelper.EncryptAES(str, _configHelper.Config.WXCEncryptionKey);
         return(RpsData <string> .Ok(result));
     }
     return(RpsData <string> .Error("无权获取"));
 }
Example #3
0
        public async Task InviteUserAsync(InviteUserDto dto)
        {
            var entity = await CheckDuplicationClientIdAsync(dto.Email);

            if (entity == null)
            {
                entity = new User {
                    UserName = dto.Email
                };

                _context.Users.Add(entity);

                await _context.SaveChangesAsync();
            }
        }
        public async Task ShouldInviteNewMember(string email, bool isTeacher)
        {
            var dto = new InviteUserDto
            {
                Email     = email,
                IsTeacher = isTeacher,
            };

            var json     = fixture.Serialize(dto);
            var response = await fixture.RequestSender.PostAsync($"organizations/invitations", json);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            string responseString = await response.Content.ReadAsStringAsync();

            int.TryParse(responseString, out int invitationIdFromResponse).Should().BeTrue();
            var invitation = await fixture.ExecuteDbContext(db => db.Invitations.Where(x => x.Email == email).SingleAsync());

            invitation.Id.Should().Be(invitationIdFromResponse);
            invitation.InvitedBy.Should().Be(fixture.UserId);
            invitation.IsTeacher.Should().Be(isTeacher);
        }
Example #5
0
        public async Task InviteAsync(InviteUserDto dto)
        {
            //достать сущьность головонния из репозитория потом добавить в нее участников голосования пользователя который достанем из репозитория пользователей сохраним изменения
            Voting voting = await _unitOfWork.VotingRepository.GetAsync(new GetOptions
            {
                Id = dto.VotingId,
                IncludeParticipants = true
            });

            User findUser = await _unitOfWork.UserRepository.FindUser(dto.SerchUser);

            if (voting != null && findUser != null &&
                voting.Participants.All(user => user.UserId != findUser.Id))
            {
                voting.Participants.Add(new UserVoting
                {
                    User   = findUser,
                    Voting = voting
                });
                await _unitOfWork.SaveChangesAsync();
            }
        }
Example #6
0
        public IActionResult InviteUser([FromBody] InviteUserDto data)
        {
            var userId = ClaimsReader.GetUserId(Request);

            if (!CheckAdminPriviliges(userId, data.GroupId))
            {
                return(BadRequest());
            }

            var targetId = context.Users.SingleOrDefault(a => a.Login.Equals(data.UserIdentifier) || a.Email.Equals(data.UserIdentifier)).Id;
            var group    = context.Groups.Include(a => a.Users).SingleOrDefault(a => a.Id == data.GroupId);

            if (group.Users.Any(a => a.UserId == targetId))
            {
                return(BadRequest($"Relacja pomiędzy tą grupą oraz użytkownikiem z identyfikatorem {data.UserIdentifier} już istnieje"));
            }

            var connection = new UserGroup
            {
                UserId   = targetId,
                GroupId  = group.Id,
                Relation = GroupRelation.Invited
            };

            context.UserGroups.Add(connection);

            try
            {
                context.SaveChanges();

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        /// <summary>
        /// Sends an invitation to the specified user
        /// </summary>
        /// <param name="userInfo">Information about the invited user</param>
        public async Task InviteUserAsync(InviteUserDto userInfo)
        {
            Verify.NotNull(userInfo, "userInfo");
            Verify.RaiseWhenFailed();
            Verify.NotNullOrEmpty(userInfo.InvitedEmail, "userInfo.InvitedEmail");
            Verify.IsEmail(userInfo.InvitedEmail, "userInfo.InvitedEmail");
            Verify.NotNullOrEmpty(userInfo.InvitedUserName, "userInfo.InvitedUserName");
            Verify.RaiseWhenFailed();

            using (var ctx = DataAccessFactory.CreateContext <ISubscriptionDataOperations>())
            {
                var email = await ctx.GetUserByEmailAsync(userInfo.InvitedEmail);

                if (email != null)
                {
                    throw new EmailReservedException(userInfo.InvitedEmail);
                }

                var user = await ctx.GetUserByUserNameAsync(Principal.SubscriptionId, userInfo.InvitedUserName);

                if (user != null)
                {
                    throw new UserNameReservedException(userInfo.InvitedUserName);
                }

                var invitations = await ctx.GetUserInvitationByEmailAsync(userInfo.InvitedEmail);

                if (invitations.Any(i => i.State != UserInvitationState.REVOKED))
                {
                    throw new EmailAlreadyInvitedException(userInfo.InvitedEmail);
                }

                invitations = await ctx.GetUserInvitationByUserAsync(Principal.SubscriptionId, userInfo.InvitedUserName);

                if (invitations.Any(i => i.State != UserInvitationState.REVOKED))
                {
                    throw new UserAlreadyInvitedException(userInfo.InvitedEmail);
                }

                // --- Administer invitation
                var invitationCode = String.Format("{0:N}{1:N}{2:N}", Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid());
                await ctx.InsertUserInvitationAsync(new UserInvitationRecord
                {
                    InvitedUserName   = userInfo.InvitedUserName,
                    InvitedEmail      = userInfo.InvitedEmail,
                    InvitationCode    = invitationCode,
                    CreatedUtc        = DateTimeOffset.UtcNow,
                    ExpirationDateUtc = DateTimeOffset.UtcNow.AddHours(72),
                    SubscriptionId    = Principal.SubscriptionId,
                    UserId            = Principal.UserId,
                    LastModifiedUtc   = null,
                    State             = UserInvitationState.SENT,
                    Type = UserInvitationType.USER
                });

                // --- Send the email with the invitation link
                var invitationLink = string.Format("{0}/{1}", SubscriptionConfig.InvitationLinkPrefix, invitationCode);
                var sender         = ServiceManager.GetService <IEmailSender>();
                sender.SendEmail(SmtpConfig.EmailFromAddr, SmtpConfig.EmailFromName,
                                 new[] { userInfo.InvitedEmail },
                                 "SeemplectCloud invitation",
                                 "Click here to confirm your invitation: " + invitationLink);
            }
        }
Example #8
0
        public async Task <IActionResult> InviteUser(InviteUserDto dto)
        {
            var result = await organizationOrchestrator.InviteUser(dto);

            return(ActionResult(result));
        }
Example #9
0
 public Task <OperationResult <int> > InviteUser(InviteUserDto inviteUserDto)
 {
     return(organizationService.CreateRegistrationInvitation(inviteUserDto.Email, inviteUserDto.IsTeacher));
 }
 public async Task InviteUserAsync(InviteUserDto userInfo)
 {
     var srvObj = HttpServiceFactory.CreateService <ISubscriptionService>();
     await srvObj.InviteUserAsync(userInfo);
 }