Exemple #1
0
        public string Login(string usuario, string contrasenia, out bool FirstPassword)
        {
            this.IsCorrect = false;
            FirstPassword  = false;

            var token = "Usuario o contraseña incorrecta";

            try
            {
                var result = this.dal.Login(usuario, contrasenia, out FirstPassword);

                if (!string.IsNullOrEmpty(result))
                {
                    var apiToken = new ApiToken();

                    token = apiToken.CreateApiToken(result);

                    IsCorrect = true;
                }
            }
            catch (Exception ex)
            {
                token = ex.Message;
            }

            return(token);
        }
Exemple #2
0
        protected Token GetToken(string ApiToken)
        {
            var token = new Token
            {
                Message   = "Ejecución correcta",
                IsCorrect = true
            };

            if (!string.IsNullOrEmpty(ApiToken))
            {
                var apiToken = new ApiToken();

                var values = apiToken.CheckApiToken(ApiToken);

                if (apiToken.IsCorrect)
                {
                    var elements = values.Split('|');

                    if (elements.Length.Equals(3))
                    {
                        token.IdUser  = int.Parse(elements[0].ToString());
                        token.IdPlant = int.Parse(elements[2].ToString());
                    }
                    else
                    {
                        token.Message   = "Token incorrecto [TKN101]";
                        token.IsCorrect = false;
                    }
                }
                else
                {
                    token.Message   = apiToken.ErrorMessage;
                    token.IsCorrect = false;
                }
            }
            else
            {
                token.Message   = "Token incorrecto [TKN100]";
                token.IsCorrect = false;
            }

            return(token);
        }