public IHttpActionResult Autenticar([FromBody] LoginTO login)
        {
            TokenResponse response = new TokenResponse();

            try
            {
                List <string> retorno = Usuario.Autenticar(login.Email, login.Senha);
                if (retorno.Count > 0)
                {
                    response.UserID = Convert.ToInt32(retorno[0]);
                    response.Token  = retorno[1];
                    Usuario u = Usuario.ConsultarUsuarioPorId(response.UserID);
                    response.Usuario       = new UsuarioTO();
                    response.Usuario.Id    = u.Id;
                    response.Usuario.Email = u.Email;
                    response.Usuario.Nome  = u.Nome;
                    response.Usuario.Tipo  = (int)u.Tipo;
                }
            }
            catch (EntidadesException eex)
            {
                response.Status   = (int)eex.Codigo;
                response.Detalhes = eex.Message;
            }
            catch (Exception ex)
            {
                response.Status   = -1;
                response.Detalhes = ex.Message;
            }
            return(Ok(response));
        }
예제 #2
0
        public async Task <IActionResult> DoLoginAsync([FromBody] LoginTO login, [FromRoute] string tipo)
        {
            if (string.IsNullOrWhiteSpace(login.email) || string.IsNullOrWhiteSpace(login.password))
            {
                return(BadRequest(new { message = "Informe o usuario e senha" }));
            }

            try
            {
                TokenResult token;
                if (tipo.ToUpper().Equals("USUARIO"))
                {
                    token = await _authNegocio.DoLoginUsuarioAsync(login.email, login.password);
                }
                else if (tipo.ToUpper().Equals("EMPRESA"))
                {
                    token = await _authNegocio.DoLoginEmpresaAsync(login.email, login.password);
                }
                else
                {
                    return(NotFound("Tipo não encontrado"));
                }
                return(Ok(token));
            }
            catch (System.Exception e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }
예제 #3
0
        public override void InsertLogin(LoginTO loginTO)
        {
            // Write config file
            var configFile  = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var configValue = string.Format("{0}@{1}@{2}"
                                            , loginTO.StationName
                                            , loginTO.StationNumber
                                            , loginTO.MacAddress);

            configFile.AppSettings.Settings[SETTINGS_KEY_NAME].Value = configValue;
            configFile.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
        }
예제 #4
0
        public void WriteLogin(LoginTO loginTO)
        {
            var lastTO = GetLastLogin();

            loginTO.MacAddress = GetMacAddress();

            if (lastTO == null)
            {
                DefaultDAO.InsertLogin(loginTO);
            }
            else if (!loginTO.CompareLogin(lastTO))
            {
                DefaultDAO.DisableLogin(lastTO);

                DefaultDAO.InsertLogin(loginTO);
            }
        }
예제 #5
0
        public override void DisableLogin(LoginTO loginTO)
        {
            var queryString = string.Format(
                "UPDATE {0}.C_STATION_LOCATION "
                + "   SET DEL_FLAG = 1           "
                + " WHERE 0 = 0                  "
                + "   AND MAC_ADDRESS    = '{1}' "
                + "   AND STATION_NUMBER =  {2}  "
                + "   AND STATION_NAME   = '{3}' "
                , SchemaDB
                , loginTO.MacAddress
                , loginTO.StationNumber
                , loginTO.StationName)
            ;

            DbCommandNonquery(queryString);
        }
예제 #6
0
        public override void InsertLogin(LoginTO loginTO)
        {
            var queryString = string.Format(
                "INSERT INTO {0}.C_STATION_LOCATION ( "
                + "    MAC_ADDRESS,                     "
                + "    STATION_NUMBER,                  "
                + "    STATION_NAME,                    "
                + "    DEL_FLAG                         "
                + ") VALUES(                            "
                + " '{1}',                              "
                + "  {2},                               "
                + " '{3}',                              "
                + "   0                                 "
                + ")                                    "
                , SchemaDB
                , loginTO.MacAddress
                , loginTO.StationNumber
                , loginTO.StationName)
            ;

            DbCommandNonquery(queryString);
        }
예제 #7
0
 public static bool CompareLogin(this LoginTO oneTO, LoginTO twoTO)
 {
     return(oneTO.StationName == twoTO.StationName &&
            oneTO.StationNumber == twoTO.StationNumber &&
            oneTO.MacAddress == twoTO.MacAddress);
 }
예제 #8
0
 public virtual void DisableLogin(LoginTO loginTO)
 {
 }
예제 #9
0
 public virtual void InsertLogin(LoginTO loginTO)
 {
 }