Prueba para consumir la api del login
This commit is contained in:
@@ -5124,7 +5124,7 @@ Public Class ClsPaginas
|
|||||||
PaginaDict.Add("/Contabilidad/OCDetalleAlmacen.aspx".ToUpper(), -1)
|
PaginaDict.Add("/Contabilidad/OCDetalleAlmacen.aspx".ToUpper(), -1)
|
||||||
|
|
||||||
|
|
||||||
|
PaginaDict.Add("/testApi.aspx".ToUpper(), -1)
|
||||||
|
|
||||||
'PaginaDict.Add("/Compras/Efacturas.aspx".ToUpper(), 2007)
|
'PaginaDict.Add("/Compras/Efacturas.aspx".ToUpper(), 2007)
|
||||||
'PaginaDict.Add("/Compras/Compras.aspx".ToUpper(), 2008)
|
'PaginaDict.Add("/Compras/Compras.aspx".ToUpper(), 2008)
|
||||||
|
|||||||
9
App_Code/Models/Request/RequestLogin.vb
Normal file
9
App_Code/Models/Request/RequestLogin.vb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Imports Microsoft.VisualBasic
|
||||||
|
|
||||||
|
Namespace Models.Request
|
||||||
|
Public Class RequestLogin
|
||||||
|
Public Property UserName As String
|
||||||
|
Public Property Password As String
|
||||||
|
End Class
|
||||||
|
|
||||||
|
End Namespace
|
||||||
10
App_Code/Models/Response/ResponseGenericModel.vb
Normal file
10
App_Code/Models/Response/ResponseGenericModel.vb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
Imports Microsoft.VisualBasic
|
||||||
|
|
||||||
|
Namespace Models.Response
|
||||||
|
Public Class ResponseGenericModel(Of T)
|
||||||
|
Public Property IsSuccess As Boolean
|
||||||
|
Public Property Msg As String
|
||||||
|
Public Property Result As T
|
||||||
|
End Class
|
||||||
|
|
||||||
|
End Namespace
|
||||||
93
App_Code/Models/Response/ResponseLogin.vb
Normal file
93
App_Code/Models/Response/ResponseLogin.vb
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
Imports Microsoft.VisualBasic
|
||||||
|
Imports Newtonsoft.Json
|
||||||
|
|
||||||
|
|
||||||
|
Namespace Models.Response
|
||||||
|
Public Class ResponseLogin
|
||||||
|
Public Property CveUsuario As Long
|
||||||
|
Public Property Usuario As String
|
||||||
|
Public Property Nombre As String
|
||||||
|
Public Property Correo As String
|
||||||
|
Public Property CveEmpresa As Long
|
||||||
|
Public Property Empresa As String
|
||||||
|
Public Property CvePlataforma As Long
|
||||||
|
Public Property Estatus As Boolean
|
||||||
|
Public Property CveRol As Integer
|
||||||
|
Public Property Rol As String
|
||||||
|
Public Property CveToken As Long
|
||||||
|
Public Property AccessToken As String
|
||||||
|
Public Property RefreshToken As String
|
||||||
|
Public Property UsuarioModulos As List(Of UsuarioModulo)
|
||||||
|
Public Property UsuarioEmpresas As List(Of UsuarioEmpresa)
|
||||||
|
Public Property EmpresaFuncionalidades As List(Of EmpresaFuncionalidad)
|
||||||
|
End Class
|
||||||
|
|
||||||
|
Public Class UsuarioModulo
|
||||||
|
Public Property CveModulo As Long
|
||||||
|
Public Property Modulo As String
|
||||||
|
Public Property CveUsuario As Long
|
||||||
|
Public Property Agrupacion As String
|
||||||
|
Public Property Descripcion As String
|
||||||
|
Public Property Liga As String
|
||||||
|
Public Property CveModuloAcceso As Long
|
||||||
|
Public Property CveProcesoAcceso As Long
|
||||||
|
Public Property Permitir As Long
|
||||||
|
Public Property Estilo As String
|
||||||
|
Public Property Padre As String
|
||||||
|
Public Property CvePadre As Long
|
||||||
|
Public Property Usuario As String
|
||||||
|
Public Property CveRol As Long
|
||||||
|
Public Property Rol As String
|
||||||
|
Public Property CvePlataforma As Long
|
||||||
|
Public Property Parametros As String
|
||||||
|
End Class
|
||||||
|
|
||||||
|
Public Class UsuarioEmpresa
|
||||||
|
Public Property Tipo_CentroCosto As Long
|
||||||
|
Public Property CveEmpresa As Long
|
||||||
|
Public Property Empresa As String
|
||||||
|
Public Property CveUsuario As Long
|
||||||
|
Public Property Usuario As String
|
||||||
|
Public Property Contraseña As String
|
||||||
|
Public Property CveCliente As Long
|
||||||
|
Public Property Cliente As String
|
||||||
|
Public Property CveProveedor As Long
|
||||||
|
Public Property Proveedor As String
|
||||||
|
Public Property FechaUltimoAcceso As DateTime
|
||||||
|
Public Property Nombre As String
|
||||||
|
Public Property CveRol As Long
|
||||||
|
Public Property Rol As String
|
||||||
|
Public Property Telefono As String
|
||||||
|
Public Property Correo As String
|
||||||
|
Public Property Estatus As Boolean
|
||||||
|
Public Property FechaIng As DateTime
|
||||||
|
Public Property EsSupervisorRH As Boolean
|
||||||
|
Public Property CveSupervisa As Long
|
||||||
|
Public Property CveAutoriza As Long
|
||||||
|
Public Property CvePersonal As Long
|
||||||
|
Public Property CveVendedor As Long
|
||||||
|
Public Property CvePlataforma As Long
|
||||||
|
Public Property ComprasProgramadas As Long
|
||||||
|
Public Property ProveedoresResponsables As Long
|
||||||
|
Public Property CveSubProyecto As Long
|
||||||
|
Public Property CveUsuarioIng As Long
|
||||||
|
Public Property CveEncuestaCRM As Long
|
||||||
|
|
||||||
|
<JsonIgnore>
|
||||||
|
Public Property EmpresaFuncionalidades As List(Of EmpresaFuncionalidad)
|
||||||
|
|
||||||
|
Public Function Funcionalidad(ByVal CveFuncionalidad As Long) As String
|
||||||
|
Return If(EmpresaFuncionalidades IsNot Nothing AndAlso EmpresaFuncionalidades.FirstOrDefault(Function(x) x.CveFuncionalidad = CveFuncionalidad) IsNot Nothing, EmpresaFuncionalidades.FirstOrDefault(Function(x) x.CveFuncionalidad = CveFuncionalidad).Valor, "")
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
|
||||||
|
Public Class EmpresaFuncionalidad
|
||||||
|
Public Property CveEmpresa As Long
|
||||||
|
Public Property CveFuncionalidad As Long
|
||||||
|
Public Property Valor As String
|
||||||
|
Public Property Descripción As String
|
||||||
|
Public Property Funcionalidad As String
|
||||||
|
End Class
|
||||||
|
|
||||||
|
End Namespace
|
||||||
|
|
||||||
25
testApi.aspx
Normal file
25
testApi.aspx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="testApi.aspx.vb" Inherits="testApi" %>
|
||||||
|
|
||||||
|
<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content2" ContentPlaceHolderID="Css" runat="Server">
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content3" ContentPlaceHolderID="E" runat="Server">
|
||||||
|
Prueba api de Login
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content4" ContentPlaceHolderID="HB" runat="Server">
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content5" ContentPlaceHolderID="H" runat="Server">
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content6" ContentPlaceHolderID="HA" runat="Server">
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content7" ContentPlaceHolderID="C" runat="Server">
|
||||||
|
<div class="row">
|
||||||
|
<label class="col-md-12">
|
||||||
|
<asp:Label runat="server" ID="LblMsg" Font-Bold="true"></asp:Label>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</asp:Content>
|
||||||
|
<asp:Content ID="Content8" ContentPlaceHolderID="JS" runat="Server">
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
51
testApi.aspx.vb
Normal file
51
testApi.aspx.vb
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
Option Strict On
|
||||||
|
Option Explicit On
|
||||||
|
Imports System.Data
|
||||||
|
Imports System.IO
|
||||||
|
Imports System.Net
|
||||||
|
Imports Extensiones
|
||||||
|
Imports Models.Request
|
||||||
|
Imports Models.Response
|
||||||
|
Imports Newtonsoft.Json
|
||||||
|
|
||||||
|
Partial Class testApi
|
||||||
|
Inherits ClsPaginas
|
||||||
|
|
||||||
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
||||||
|
|
||||||
|
If Not IsPostBack Then
|
||||||
|
Dim responseGenericModel = New ResponseGenericModel(Of ResponseLogin)()
|
||||||
|
Dim origResponse As HttpWebResponse
|
||||||
|
Dim origRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://sig.adssistemas.mx:90/api/usuario/Login"), HttpWebRequest)
|
||||||
|
'origRequest.Headers.Add("Authorization", "Barer c3NhX2RzdDpBc3AzY3RfMTIzNA==") Esto se usara cuando se tenga que mandar el token (todos excepto el login)
|
||||||
|
origRequest.AllowAutoRedirect = False
|
||||||
|
origRequest.Method = "POST"
|
||||||
|
origRequest.ContentType = "application/json"
|
||||||
|
origRequest.Accept = "application/json"
|
||||||
|
origRequest.Expect = "application/json"
|
||||||
|
Try
|
||||||
|
Dim requestLogin = New RequestLogin() With {
|
||||||
|
.UserName = "RPimienta",
|
||||||
|
.Password = "capillafc"
|
||||||
|
}
|
||||||
|
|
||||||
|
Dim requestJson = JsonConvert.SerializeObject(requestLogin)
|
||||||
|
|
||||||
|
origRequest.GetRequestStream.Write(System.Text.Encoding.UTF8.GetBytes(requestJson), 0, System.Text.Encoding.UTF8.GetBytes(requestJson).Count)
|
||||||
|
origResponse = DirectCast(origRequest.GetResponse(), HttpWebResponse)
|
||||||
|
Dim Stream As Stream = origResponse.GetResponseStream()
|
||||||
|
Dim sr As New StreamReader(Stream, Encoding.GetEncoding("utf-8"))
|
||||||
|
Dim str As String = sr.ReadToEnd()
|
||||||
|
responseGenericModel = JsonConvert.DeserializeObject(Of ResponseGenericModel(Of ResponseLogin))(str)
|
||||||
|
If responseGenericModel.IsSuccess Then
|
||||||
|
LblMsg.Text = $"Bienvenido {responseGenericModel.Result.Nombre}"
|
||||||
|
End If
|
||||||
|
|
||||||
|
Catch ex As WebException
|
||||||
|
Alert(ex.Response.ToString())
|
||||||
|
End Try
|
||||||
|
End If
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
||||||
Reference in New Issue
Block a user