This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
Imports System.Data
|
||||
Imports System.IdentityModel.Tokens.Jwt
|
||||
Imports System.Security.Claims
|
||||
Imports ADSSession
|
||||
Imports Extensiones
|
||||
Imports Microsoft.IdentityModel.Tokens
|
||||
|
||||
Partial Class LogIn
|
||||
Inherits System.Web.UI.Page
|
||||
@@ -28,7 +31,9 @@ Partial Class LogIn
|
||||
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
'"187.158.96.163" es la de mi casa
|
||||
'If (Context.Session("UsuarioSIG") IsNot Nothing) OrElse Not User.Identity.IsAuthenticated Then
|
||||
|
||||
'Request.Headers.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJOb21icmUiOiJhZG1pbiIsIkN2ZVVzdWFyaW8iOiIyMDA5IiwiQ3ZlRW1wcmVzYSI6IjIiLCJDdmVQZXJmaWwiOiIyIiwiTWFpbCI6ImFkbWluQGFkbWluLmNvbSIsImV4cCI6MTU5NDY3MzQ2NCwiaXNzIjoiVGVzdC5jb20iLCJhdWQiOiJUZXN0LmNvbSJ9.vmPRxGfxzR10Rf-4Luk2Ej0SVs7w2XGDGJBCyx5VSQI")
|
||||
'Response.AddHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJOb21icmUiOiJhZG1pbiIsIkN2ZVVzdWFyaW8iOiIyMDA5IiwiQ3ZlRW1wcmVzYSI6IjIiLCJDdmVQZXJmaWwiOiIyIiwiTWFpbCI6ImFkbWluQGFkbWluLmNvbSIsImV4cCI6MTU5NDY3MzQ2NCwiaXNzIjoiVGVzdC5jb20iLCJhdWQiOiJUZXN0LmNvbSJ9.vmPRxGfxzR10Rf-4Luk2Ej0SVs7w2XGDGJBCyx5VSQI")
|
||||
'Response.End()
|
||||
'End If
|
||||
Dim iplist As String() = New String() {"", ""}
|
||||
If HttpContext.Current.Request.ServerVariables("REMOTE_ADDR").ToString().Contiene(iplist) Then
|
||||
@@ -71,7 +76,7 @@ Partial Class LogIn
|
||||
End If
|
||||
|
||||
HdfImagenes.Value = strimg.ToString()
|
||||
TxtUsuario.Focus()
|
||||
txtUsuario.Focus()
|
||||
Me.Form.DefaultButton = BtnLogIn.ClientID
|
||||
If Request("p") IsNot Nothing AndAlso Request("p") <> "" Then
|
||||
Dim Salida As String = Decripta(Request("p"))
|
||||
@@ -179,6 +184,14 @@ Partial Class LogIn
|
||||
If Request("ReturnUrl") IsNot Nothing Then
|
||||
ReturnUrl = Request("ReturnUrl").ToString()
|
||||
End If
|
||||
If Not IsNothing(Request("port")) Then
|
||||
Dim strdomain = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, "")
|
||||
If Request.Url.Port <> 80 Then
|
||||
strdomain = strdomain.Replace(String.Format(":{0}", Request.Url.Port), "")
|
||||
End If
|
||||
ReturnUrl = String.Format("{0}:{1}/{2}", strdomain, Request("port"), ReturnUrl)
|
||||
|
||||
End If
|
||||
If BtnLogIn_Clickenter = 0 Then 'esta variable se recicla con cada postaback
|
||||
BtnLogIn_Clickenter = 1
|
||||
Dim ObjUsuario As New ClsSisUsuarios
|
||||
@@ -235,11 +248,29 @@ Partial Class LogIn
|
||||
dt.Dispose()
|
||||
End If
|
||||
|
||||
Dim cookie = FormsAuthentication.GetAuthCookie(Encripta(Usuario.CveUsuario), False)
|
||||
'ADSSession.ADSSessionConfig.SessionManager(ADSSession.OpcionSession.SetAspSig, ASPSIG:=Request.Cookies.Get(".ASPXSIG").Value)
|
||||
Dim cookie = FormsAuthentication.GetAuthCookie(Usuario.CveUsuario, False)
|
||||
Response.Cookies.Add(cookie)
|
||||
'RegistraScript(String.Format("iniciaSesion('{0}')", ReturnUrl.Replace("'", "\'")))
|
||||
Response.Redirect(ReturnUrl, True)
|
||||
|
||||
'Public Property CveUsuario As Integer
|
||||
'Public Property Mail As String
|
||||
'Public Property Nombre As String
|
||||
'Public Property Contraseña As String
|
||||
'Public Property CvePerfil As Integer
|
||||
'Public Property CveUsuarioModifico As Integer
|
||||
'Public Property CveEmpresa As Integer
|
||||
'Public Property CveUsuarioRegistro As Integer
|
||||
Dim userm As New UserModel()
|
||||
userm.CveUsuario = Usuario.CveUsuario
|
||||
userm.Mail = Usuario.Usuario
|
||||
userm.Nombre = Usuario.Nombre
|
||||
userm.Contraseña = Usuario.Contraseña
|
||||
userm.CvePerfil = Usuario.CveRol
|
||||
userm.CveEmpresa = 119 'Usuario.CveEmpresa
|
||||
userm.CveUsuarioModifico = Usuario.CveEmpresa
|
||||
userm.CveUsuarioRegistro = Usuario.CveEmpresa
|
||||
RegistraScript(String.Format("opennewlocation('{0}','{1}')", ReturnUrl, GenerateJSONWebToken(userm)))
|
||||
'Response.Redirect(ReturnUrl, True)
|
||||
Else
|
||||
Alert("El usuario no esta autorizado en este equipo, favor de contactar al administrador de usuarios.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
@@ -307,4 +338,28 @@ Partial Class LogIn
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Function GenerateJSONWebToken(ByVal user As UserModel) As String
|
||||
Dim securityKey = New SymmetricSecurityKey(Encoding.UTF8.GetBytes("ThisismySecretKey"))
|
||||
Dim credentials = New SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256)
|
||||
Dim claims = {New Claim("Nombre", user.Nombre), New Claim("CveUsuario", user.CveUsuario.ToString()), New Claim("CveEmpresa", user.CveEmpresa.ToString()), New Claim("CvePerfil", user.CvePerfil.ToString()), New Claim("Mail", user.Mail.ToString())}
|
||||
Dim token = New JwtSecurityToken("Test.com", "Test.com", claims, expires:=DateTime.Now.AddMinutes(120), signingCredentials:=credentials)
|
||||
Return New JwtSecurityTokenHandler().WriteToken(token)
|
||||
End Function
|
||||
Public Class UserModel
|
||||
Public Sub New()
|
||||
Me.CveUsuario = -1
|
||||
End Sub
|
||||
|
||||
|
||||
Public Property CveUsuario As Integer
|
||||
Public Property Mail As String
|
||||
Public Property Nombre As String
|
||||
Public Property Contraseña As String
|
||||
Public Property CvePerfil As Integer
|
||||
Public Property CveUsuarioModifico As Integer
|
||||
Public Property CveEmpresa As Integer
|
||||
Public Property CveUsuarioRegistro As Integer
|
||||
End Class
|
||||
End Class
|
||||
|
||||
|
||||
Reference in New Issue
Block a user