Esempio n. 1
0
        public HttpResponseMessage accountEnter([FromBody] EnterRequest nEnterRequest)
        {
            AccountInfo accountInfo_ = AccountAspect.getAccountId(nEnterRequest.mAccountName, nEnterRequest.mPassword, nEnterRequest.mAccountType);
            EnterResult enterResult_ = new EnterResult();

            enterResult_.mErrorCode = ConstAspect.mFail;
            enterResult_.mAuthority = 0;
            enterResult_.mRoleItem  = null;
            if ((null == accountInfo_) || (accountInfo_.mAccountId <= 0) || (accountInfo_.mAccountId != nEnterRequest.mAccountId))
            {
                enterResult_.mErrorCode = ConstAspect.mAccount;
                return(ConstAspect.toJson(enterResult_));
            }
            enterResult_.mAuthority = accountInfo_.mAuthority;
            RoleItem roleItem_ = RoleAspect.getRoleInfo(nEnterRequest.mOperatorName, nEnterRequest.mVersionNo, nEnterRequest.mAccountId, nEnterRequest.mRoleId, nEnterRequest.mServerId);

            if (null == roleItem_)
            {
                enterResult_.mErrorCode = ConstAspect.mRole;
                return(ConstAspect.toJson(enterResult_));
            }
            enterResult_.mErrorCode = ConstAspect.mSucess;
            enterResult_.mRoleItem  = roleItem_;
            if (nEnterRequest.mStart)
            {
                RoleAspect.updateRoleStart(nEnterRequest.mOperatorName, nEnterRequest.mVersionNo, nEnterRequest.mAccountId, nEnterRequest.mServerId, nEnterRequest.mRoleId);
            }
            return(ConstAspect.toJson(enterResult_));
        }
Esempio n. 2
0
        public async Task <OperationResult <EnterResponse> > Enter(EnterRequest request)
        {
            try
            {
                var response = await _client.PostAsJsonAsync("api/Room/Enter", request);

                if (!response.IsSuccessStatusCode)
                {
                    return(OperationResult <EnterResponse> .Error(response.ReasonPhrase));
                }

                var content = await response.Content.ReadAsStringAsync();

                var enterResponse = JsonSerializer.Deserialize <OperationResult <EnterResponse> >(content, SerializerOptions.Default);
                if (!enterResponse.IsOk)
                {
                    return(OperationResult <EnterResponse> .Error(enterResponse.ErrorMsg));
                }

                return(OperationResult <EnterResponse> .Ok(enterResponse.Result));
            }
            catch (Exception e)
            {
                return(OperationResult <EnterResponse> .Error(e.Message));
            }
        }
Esempio n. 3
0
        public ActionResult EnterRoom(EnterRequest enterRequest)
        {
            if (!ModelState.IsValid)
                return View(enterRequest);

            authSvc.Authenticate(enterRequest.Name);
            chatRoom.AddParticipant(enterRequest.Name);

            return RedirectToRoute(RouteName.Room);
        }
Esempio n. 4
0
        public async Task <ActionResult <OperationResult <EnterResponse> > > Enter(EnterRequest request)
        {
            await _roomService.ClearExpired();

            var invitation = await _invitationService.Get(request.Invite);

            if (invitation == null)
            {
                return(OperationResult <EnterResponse> .Error("Invitation not found (or expired)."));
            }

            if (invitation.ExpireAt < DateTime.UtcNow)
            {
                return(OperationResult <EnterResponse> .Error("Invitation expired."));
            }

            ColorEnum color = ColorHelper.RandomColor();

            User user = await _roomService.TryEnter(request.UserName, (int)color, invitation.RoomId);

            if (user == null)
            {
                return(OperationResult <EnterResponse> .Error("Can't enter to room."));
            }

            User owner = await _userService.Get(user.Room.OwnerId);

            return(OperationResult <EnterResponse> .Ok(new EnterResponse
            {
                RoomId = user.RoomId,
                RoomOwnerPublicId = owner.PublicId,
                UserId = user.Id,
                UserPublicId = user.PublicId,
                RoomExpireAt = user.ExpireAt,
                RoomTopic = user.Room.Topic,
                OnlyOwnerCanInvite = user.Room.OnlyOwnerCanInvite
            }));
        }
Esempio n. 5
0
 public override void EnterExchange(IRpcController controller, EnterRequest request, Action <EnterResponse> done)
 {
     throw new NotImplementedException();
 }
            void will_show_the_enter_form_with_errors_when_the_request_is_invalid()
            {
                var controller = CreateControllerWithMoqs();
                var model = new EnterRequest() { Name = "aName" };
                controller.ModelState.AddModelError("aKey", "aMessage");

                var viewResult = controller.EnterRoom(model) as ViewResult;

                Assert.Empty(viewResult.ViewName);
                Assert.Same(model, viewResult.ViewData.Model);
            }