예제 #1
0
        public static UserInvitationDto MapToDto(UserInvitation source)
        {
            UserInvitationDto target = new UserInvitationDto();

            target.Id        = source.Id;
            target.Date      = source.Date;
            target.GroupName = source.Group.Name;
            target.Username  = source.User.UserName;
            return(target);
        }
예제 #2
0
        public async Task <IActionResult> AcceptInvitationAsync(UserInvitationDto userInvitationDto)
        {
            var userId = await _userCommandService.AcceptInvitationAsync(userInvitationDto);

            var user = await _userQueryService.GetUserByIdAsync(userId);

            await _channelCommandService.AddUserToDefaultChannelsAsync(userId, user.WorkspaceId);

            await _conversationCommandService.StartSelfConversationAsync(userId, user.WorkspaceId);

            return(Ok());
        }
예제 #3
0
        public HttpResponseMessage PostInvitations(string username, [FromBody] UserInvitationDto invitation)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (username == GetUserName())
            {
                Request.CreateResponse(HttpStatusCode.BadRequest, "cannot invite yourself :)");
            }

            GroupDto group = m_GroupService.GetByName(invitation.GroupName);

            if (group == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "group not found."));
            }

            UserDto user = m_UserService.GetByUserName(username);

            if (user == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "user not found"));
            }

            if (group.AdminName != GetUserName())
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "you are not creator of the group."));
            }

            List <string> participants = m_GroupService.GetParticipants(group.GroupName);

            if (participants.Contains(username))
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, "user already in group"));
            }

            bool isInvited = m_UserService.IsInvited(username, invitation.GroupName);

            if (isInvited)
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, "user already invited to this group"));
            }

            m_UserService.Invite(username, invitation.GroupName);

            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
예제 #4
0
        public HttpResponseMessage DeleteInvitation(string username, int id)
        {
            if (username != GetUserName() || id <= 0)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            UserInvitationDto invitation = m_UserService.GetInvitation(id);

            if (invitation == null || invitation.Username != username)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "invitation not found"));
            }

            m_UserService.DeleteInvitation(id);

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
예제 #5
0
        public async Task <int> AcceptInvitationAsync(UserInvitationDto userInvitationDto)
        {
            if (userInvitationDto.Email == null)
            {
                throw new ArgumentNullException(nameof(userInvitationDto.Email));
            }

            if (userInvitationDto.Password == null)
            {
                throw new ArgumentNullException(nameof(userInvitationDto.Password));
            }

            if (!Guid.TryParse(userInvitationDto.Code, out Guid code))
            {
                throw new ArgumentException("Invalid code.");
            }

            var invitation = await _context.UserInvitations.SingleOrDefaultAsync(ui =>
                                                                                 ui.UserEmail == userInvitationDto.Email &&
                                                                                 ui.InvitationCode == code &&
                                                                                 ui.Acceptted == false &&
                                                                                 ui.Cancelled == false);

            if (invitation == null)
            {
                throw new Exception("Invalid invitation.");
            }

            var userId = await RegisterAsync(userInvitationDto.Email, userInvitationDto.Password,
                                             userInvitationDto.Name, invitation.WorkspaceId);

            invitation.Accept();
            await _context.SaveChangesAsync();

            return(userId);
        }