Пример #1
0
        private ErrorResponse ValidateRequest(EnterSsRequest data)
        {
            if (!ApiValidator.ValidatePhone(data.Phone, out ErrorResponse error))
            {
                return(error);
            }

            ApiValidator.ValidatePinCode(data.PinCode, out error);
            return(error);
        }
Пример #2
0
        public async Task <IActionResult> Handle(HttpRequest request, EnterSsRequest data)
        {
            AuthByKeyResult authResult = this.GetAuthenticationKey(request);

            if (!authResult.Result)
            {
                return(new JsonErrorResult(authResult.ErrorResponse));
            }

            ErrorResponse validationError = this.ValidateRequest(data);

            if (validationError != null)
            {
                return(new JsonErrorResult(validationError));
            }

            byte[] securedKey = Guid.NewGuid().ToByteArray();

            try
            {
                using (SqlConnection conn = sqlServer.GetConnection())
                {
                    await conn.OpenAsync();

                    using (SqlCommand cmd = sqlServer.GetSpCommand("dbo.Employee_EnterSecuredSession", conn))
                    {
                        cmd.AddBinaryParam("@PermanentKey", 16, authResult.Key.ToArray());
                        cmd.AddBinaryParam("@SecuredKey", 16, securedKey);
                        cmd.AddCharParam("@Phone", 10, data.Phone);
                        cmd.AddCharParam("@PinCode", 4, data.PinCode);

                        SqlParameter retValParam = cmd.AddReturnValue();

                        await cmd.ExecuteNonQueryAsync();

                        int retVal = retValParam.GetInt32OrDefault();
                        if (retVal < 0)
                        {
                            ErrorResponse errorResponse = this.GetErrorResponse(retVal);
                            return(new JsonErrorResult(errorResponse));
                        }

                        EnterSsResponse response = new EnterSsResponse();
                        response.SecuredKey = AuthKey.Create(securedKey).ToString() + authResult.Key.ToString();
                        return(new JsonResult(response));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new JsonErrorResult(this.GetExceptionResponse(ex)));
            }
        }
Пример #3
0
 public async Task <ApiResponse <EnterSsResponse> > EnterSecuredSession(EnterSsRequest data)
 {
     data.ClientInfo = this._clientInfo;
     return(await new ApiMethod <EnterSsRequest, EnterSsResponse>(
                this._httpClient, this._controllerUriPart, "EnterSs", AuthHeaderKind.Regular).Call(data));
 }
Пример #4
0
 public async Task <IActionResult> EnterSecuredSession(EnterSsRequest data)
 {
     return(await GetHandler <EnterSecuredSession>().Handle(this.Request, data));
 }