Пример #1
0
        public IHttpActionResult Auth(LoginRequest credentials)
        {
            string errorDescription = string.Empty;

            try
            {
                var username = credentials.UserName;
                var password = credentials.Password;

                if (IsValidCredentials(username, password))
                {
                    return(Ok(GenerateToken()));
                }
                else
                {
                    errorDescription = "Invalid Credentials";
                    _logFileManager.WriteLine(LogType.Warning, errorDescription);
                    return(Content(HttpStatusCode.Unauthorized, errorDescription));
                };
            }
            catch (Exception ex)
            {
                errorDescription = ex.Message;
                _logFileManager.WriteLine(LogType.Fail, errorDescription);
                return(BadRequest(errorDescription));
            }
        }
Пример #2
0
        public IHttpActionResult Read()
        {
            try
            {
                Guid   idOperation = Guid.NewGuid();
                object obj         = new
                {
                    IdOperation  = idOperation,
                    IpClient     = _clientFeatures.IP,
                    DateResponse = DateTime.Now.ToString(FormatTemplate.LongDate),
                    Sender       = "Expertia"
                };

                _logFileManager.WriteLine(LogType.Info, string.Format("Success: {0}", idOperation.ToString()));
                return(Ok(obj));
            }
            catch (Exception ex)
            {
                _logFileManager.WriteLine(LogType.Fail, string.Format("Fail: {0}", ex.Message));
                return(InternalServerError());
            }
        }
Пример #3
0
        /// <summary>
        /// Método de Validación
        /// </summary>
        /// <param name="actionContext"></param>
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            Guid idOperation = Guid.NewGuid();

            object obj = new
            {
                IdOperation  = idOperation,
                IpClient     = _clientFeatures.IP,
                DateResponse = DateTime.Now.ToString(FormatTemplate.LongDate),
                Sender       = "Expertia"
            };

            if (actionContext.Request.Headers.Authorization != null)
            {
                try
                {
                    var authToken = actionContext.Request.Headers.Authorization.Parameter;

                    if (!IsAuthorizedUser(authToken))
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, obj);
                        _logFileManager.WriteLine(LogType.Warning, string.Format("{0}: {1}", LogLineMessage.Unauthorized, idOperation.ToString()));
                    }
                }
                catch
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.BadRequest, obj);
                    _logFileManager.WriteLine(LogType.Fail, string.Format("{0}: {1}", LogLineMessage.BadRequest, idOperation.ToString()));
                }
            }
            else
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, obj);
                _logFileManager.WriteLine(LogType.Warning, string.Format("{0}: {1}", LogLineMessage.Unauthorized, idOperation.ToString()));
            }
        }