示例#1
0
        public static List <ErrorModel> CanUserJoinChatroom(JoinChatroomRequestModel request)
        {
            var errors = new List <ErrorModel>();

            if (request.User.Role == Models.User_Model.RoleLevel.Blocked)
            {
                errors.Add(new ErrorModel("User has been blocked."));
                return(errors);
            }

            Chatroom c = ChatroomService.GetChatroom(request.ChatroomId, request.ParentChatroomId);

            if (c.HasPassword && !c.CheckPasswordHash(GetStringSha256Hash(request.Password)))
            {
                errors.Add(new ErrorModel("Incorrect Password."));
            }
            else if (c.IsAtCapacity)
            {
                errors.Add(new ErrorModel("Chatroom is full."));
            }
            else if (c.IsOnBlacklist(request.User.Username))
            {
                errors.Add(new ErrorModel("User blocked from chatroom."));
            }
            else if (c.DoesHandleExist(request.UserHandle))
            {
                errors.Add(new ErrorModel("User Handle already exists in Chatroom."));
            }

            return(errors);
        }