コード例 #1
0
ファイル: RootController.cs プロジェクト: tamifist/KinderChat
        public AuthenticationResponse Authentication(ISession session, AuthenticationRequest request)
        {
            var respone = request.CreateResponse <AuthenticationResponse>();

            if (string.IsNullOrEmpty(request.AccessToken) ||
                string.IsNullOrEmpty(request.DeviceId))
            {
                respone.Success = false;
                return(respone);
            }

            if (!_accessTokenFastValidator.Validate(request.AccessToken, request.DeviceId, request.UserId))
            {
                respone.Success = false;
                respone.Error   = Errors.AccessTokenInvalid;
                return(respone);
            }

            if (_devicesRepository.GetDevices(request.UserId).All(d => d != request.DeviceId))
            {
                respone.Success = false;
                respone.Error   = Errors.DeviceRegistrationRequired;
                return(respone);
            }

            session.AssignUser(request.AccessToken, request.DeviceId, request.UserId);

            respone.ServerInfo = GetServerInfo();
            _childrenControllers.ForEach(c => c.OnAuthenticating(session, respone));

            _server.OnSessionAuthenticated(session);

            Task.Delay(500).ContinueWith(r => _childrenControllers.ForEach(c => c.OnAuthenticated(session)));
            return(respone);
        }
コード例 #2
0
        public AuthenticationResponse Authenticate(ISession session, AuthenticationRequest request)
        {
            var response = request.CreateResponse <AuthenticationResponse>();

            response.Result = AuthenticationResponseType.Success;

            using (var uow = UnitOfWorkFactory.Create())
            {
                var user = uow.UsersRepository.FirstMatching(UserSpecification.NameAndPassword(request.Name, request.Password));
                if (user == null)
                {
                    response.Result = AuthenticationResponseType.InvalidNameOrPassword;
                    return(response);
                }
                else
                {
                    if (user.IsBanned)
                    {
                    }
                    else if (user.Huid != request.Huid)
                    {
                        user.ChangeHuid(request.Huid);
                    }
                }

                uow.Commit();

                if (response.Result == AuthenticationResponseType.Success)
                {
                    Enumerable.Count(user.Friends);
                    session.SetUser(user);
                    response.User = user.ProjectedAs <UserDto>();
                }
            }
            return(response);
        }