Example #1
0
        private async Task <object> LoginInternal()
        {
            var request = this.BindAndValidateModel <ActiveDirectoryUserLoginRequest>();

            request.UserName = request.UserName.Trim();

            _requestThrottleManagerInstance.RequiresThrottling(
                this, ThrottlingProperties.Path,
                ThrottlingPeriod.Minute, requestCountLimit: 20,
                requestKeys: request.UserName);

            _requestThrottleManagerInstance.RequiresThrottling(
                this, ThrottlingProperties.Path,
                ThrottlingPeriod.Hour, requestCountLimit: 100,
                requestKeys: request.UserName);

            var environmentToken = (string)Context.Parameters.EnvironmentToken;

            var result = await _accountServiceInstance.Login(request, environmentToken);

            if (result == null)
            {
                ModelValidationResult.Errors.Add(nameof(request.UserName), "user or password incorrect");
                throw new BadModelException(ModelValidationResult);
            }

            return(result);
        }
Example #2
0
        private async Task <object> RegisterInternal()
        {
            var phone = this.Bind <long>();

            requestThrottleManager.RequiresThrottling(
                this, ThrottlingProperties.Path,
                ThrottlingPeriod.Day, requestCountLimit: 20,
                requestKeys: phone.ToString());

            requestThrottleManager.RequiresThrottling(
                this, ThrottlingProperties.Path | ThrottlingProperties.RemoteIp,
                ThrottlingPeriod.Minute, requestCountLimit: 50);

            requestThrottleManager.RequiresThrottling(
                this, ThrottlingProperties.Path | ThrottlingProperties.RemoteIp,
                ThrottlingPeriod.Hour, requestCountLimit: 300);

            try
            {
                var environmentToken = (string)Context.Parameters.EnvironmentToken;
                await accountService.Register(phone, environmentToken);
            }
            catch (SecurityException ex)
            {
                ModelValidationResult.Errors.Add(nameof(phone), ex.Message);
                throw new BadModelException(ModelValidationResult);
            }
            catch (ArgumentException ex)
            {
                ModelValidationResult.Errors.Add("wrong data: ", ex.Message);
                throw new BadModelException(ModelValidationResult);
            }
            return(HttpStatusCode.OK);
        }