Exemple #1
0
        public static AuthVM TokenToAuth(this UsuarioVM user)
        {
            if (user == null)
            {
                return(null);
            }

            AuthVM auth = new AuthVM()
            {
                Identity = user.Id.ToString(),
                Function = user.Id_funcao.ToString(),
                Token    = ToToken(user.Id.ToString())
            };

            return(auth);
        }
Exemple #2
0
        public AuthVM Auth(LoginVM login)
        {
            var procedure  = "sp_usuario";
            var parameters = new List <MySqlParameter>
            {
                new MySqlParameter {
                    MySqlDbType = MySqlDbType.VarChar, ParameterName = "@login", Value = login.Login
                },
                new MySqlParameter {
                    MySqlDbType = MySqlDbType.VarChar, ParameterName = "@senha", Value = login.Senha
                },
                new MySqlParameter {
                    MySqlDbType = MySqlDbType.VarChar, ParameterName = "@auth", Value = "", Direction = ParameterDirection.Output
                }
            };

            MySqlConnection connection = new MySqlConnection(DbConn.ConnectionString);

            connection.Open();

            MySqlCommand command = new MySqlCommand(procedure, connection);

            command.Parameters.AddRange(parameters.ToArray());
            command.CommandTimeout = 5;
            command.CommandType    = CommandType.StoredProcedure;
            command.ExecuteNonQuery();

            int userId = int.Parse(command.Parameters["@auth"].Value.ToString());

            command.Dispose();
            //Modelo 1
            //UsuarioVM user = userId > 0 ? Find(userId) : null;
            //TokenVM token = user != null ? user.ViewToToken() : null;

            //Modelo 2
            UsuarioVM user = userId > 0 ? Find(userId) : null;
            AuthVM    auth = user.TokenToAuth();

            return(auth);
        }
Exemple #3
0
        public AuthVM Auth(LoginVM obj)
        {
            AuthVM view = _repository.Auth(obj);

            return(view);
        }