This commit is contained in:
171
LogIn.aspx.vb
171
LogIn.aspx.vb
@@ -39,6 +39,25 @@ Partial Class LogIn
|
||||
If HttpContext.Current.Request.ServerVariables("REMOTE_ADDR").ToString().Contiene(iplist) Then
|
||||
Response.Redirect("http://www.adsistemas.mx/login.aspx") 'si alguien lo ve es correcto la pagina vieja de adsistemas
|
||||
End If
|
||||
Dim token As String = GetTokenAngular()
|
||||
If (token.Length > 0) Then
|
||||
If Not IsNothing(Request("port")) Then
|
||||
Dim ReturnUrl As String = "/"
|
||||
If Request("ReturnUrl") IsNot Nothing Then
|
||||
ReturnUrl = Request("ReturnUrl").ToString()
|
||||
End If
|
||||
|
||||
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}/auth/login?token={3}&returnUrl=/{2}", strdomain, Request("port"), HttpUtility.UrlEncode(ReturnUrl), HttpUtility.UrlEncode(token))
|
||||
'S ies angular retiro el https para que no marque error la pagina
|
||||
ReturnUrl = ReturnUrl.Replace("https", "http")
|
||||
ReturnUrl = ReturnUrl.Replace("HTTPS", "HTTP")
|
||||
RegistraScript(String.Format("opennewlocation('{0}','{1}')", ReturnUrl, ""))
|
||||
End If
|
||||
End If
|
||||
If Not Page.IsPostBack Then
|
||||
|
||||
Dim strimg As New StringBuilder
|
||||
@@ -185,16 +204,6 @@ 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)
|
||||
'S ies angular retiro el https para que no marque error la pagina
|
||||
ReturnUrl = ReturnUrl.Replace("https", "http")
|
||||
ReturnUrl = ReturnUrl.Replace("HTTPS", "HTTP")
|
||||
End If
|
||||
If BtnLogIn_Clickenter = 0 Then 'esta variable se recicla con cada postaback
|
||||
BtnLogIn_Clickenter = 1
|
||||
Dim ObjUsuario As New ClsSisUsuarios
|
||||
@@ -209,68 +218,110 @@ Partial Class LogIn
|
||||
End If
|
||||
|
||||
ADSSessionConfig.sessionUser = Usuario
|
||||
ADSSessionConfig.sessionDpage = False
|
||||
ObjUsuario.Dispose()
|
||||
If Usuario IsNot Nothing Then
|
||||
If Not Usuario.AutorizadoxIP OrElse (HddAdsCodex.Text.Length > 0 AndAlso Usuario.CodigoAutorizado = HddAdsCodex.Text) Then
|
||||
ADSSessionConfig.sessionDpage = False
|
||||
ObjUsuario.Dispose()
|
||||
If Usuario IsNot Nothing Then
|
||||
If Not Usuario.AutorizadoxIP OrElse (HddAdsCodex.Text.Length > 0 AndAlso Usuario.CodigoAutorizado = HddAdsCodex.Text) Then
|
||||
|
||||
CreaObjetoEmpresa(Usuario)
|
||||
ADSSessionConfig.sessionUser.MultipleEmpresa = True
|
||||
CreaObjetoEmpresa(Usuario)
|
||||
ADSSessionConfig.sessionUser.MultipleEmpresa = True
|
||||
|
||||
Dim x As New ADSSessionObj(Usuario.CveUsuario, Usuario.CveEmpresa)
|
||||
Dim _sessionid = Encripta(String.Format("{0}|{1}", Usuario.CveUsuario, x.SessionID))
|
||||
x = ADSSessionConfig.SessionManager(OpcionSession.agregarSession, x)
|
||||
Dim x As New ADSSessionObj(Usuario.CveUsuario, Usuario.CveEmpresa)
|
||||
Dim _sessionid = Encripta(String.Format("{0}|{1}", Usuario.CveUsuario, x.SessionID))
|
||||
x = ADSSessionConfig.SessionManager(OpcionSession.agregarSession, x)
|
||||
|
||||
If Usuario.CvePlataforma = 6 And Usuario.CveRol = 10 Then
|
||||
'PLATAFORMA PORTAL CLIENTE
|
||||
'FormsAuthentication.RedirectFromLoginPage(_sessionid, False)
|
||||
'Response.Redirect("/PortalCliente/PortalCliente.aspx", True)
|
||||
If Usuario.CvePlataforma = 6 And Usuario.CveRol = 10 Then
|
||||
'PLATAFORMA PORTAL CLIENTE
|
||||
'FormsAuthentication.RedirectFromLoginPage(_sessionid, False)
|
||||
'Response.Redirect("/PortalCliente/PortalCliente.aspx", True)
|
||||
|
||||
ReturnUrl = "/PortalCliente/PortalCliente.aspx"
|
||||
ElseIf Usuario.CvePlataforma = 7 And Usuario.CveRol = 11 Then
|
||||
'PLATAFORMA PORTAL PROVEEDOR
|
||||
'FormsAuthentication.RedirectFromLoginPage(Encripta(Usuario.CveUsuario), False)
|
||||
'Response.Redirect("/PortalProveedor/PortalProveedor.aspx", True)
|
||||
ReturnUrl = "/PortalCliente/PortalCliente.aspx"
|
||||
ElseIf Usuario.CvePlataforma = 7 And Usuario.CveRol = 11 Then
|
||||
'PLATAFORMA PORTAL PROVEEDOR
|
||||
'FormsAuthentication.RedirectFromLoginPage(Encripta(Usuario.CveUsuario), False)
|
||||
'Response.Redirect("/PortalProveedor/PortalProveedor.aspx", True)
|
||||
|
||||
ReturnUrl = "/PortalProveedor/PortalProveedor.aspx"
|
||||
ElseIf Usuario.CveRol = 1200 And Usuario.Acceso > 0 Then
|
||||
'PLATAFORMA GPS
|
||||
Usuario.CvePlataforma = 3
|
||||
'FormsAuthentication.RedirectFromLoginPage(Encripta(Usuario.CveUsuario), False)
|
||||
'Response.Redirect("/PortalGPS/InicioGPS.aspx", True)
|
||||
ReturnUrl = "/PortalGPS/InicioGPS.aspx"
|
||||
Else
|
||||
'PLATAFORMA SIG
|
||||
CType(Session("UsuarioSIG"), Usuario).CvePlataforma = 1
|
||||
Dim dt As Data.DataTable = GlobalDTUsuarios(Usuario.CveUsuario)
|
||||
If dt IsNot Nothing Then
|
||||
If dt.Rows.Count >= 1 Then
|
||||
If dt.Rows.Count > 1 Then
|
||||
Usuario.MultipleEmpresa = True
|
||||
End If
|
||||
'FormsAuthentication.RedirectFromLoginPage(Encripta(Usuario.CveUsuario), False)
|
||||
End If
|
||||
End If
|
||||
dt.Dispose()
|
||||
End If
|
||||
|
||||
Dim cookie = FormsAuthentication.GetAuthCookie(Usuario.CveUsuario, False)
|
||||
Response.Cookies.Add(cookie)
|
||||
RegistraScript(String.Format("opennewlocation('{0}','{1}')", ReturnUrl, ""))
|
||||
'Response.Redirect(ReturnUrl, True)
|
||||
ReturnUrl = "/PortalProveedor/PortalProveedor.aspx"
|
||||
ElseIf Usuario.CveRol = 1200 And Usuario.Acceso > 0 Then
|
||||
'PLATAFORMA GPS
|
||||
Usuario.CvePlataforma = 3
|
||||
'FormsAuthentication.RedirectFromLoginPage(Encripta(Usuario.CveUsuario), False)
|
||||
'Response.Redirect("/PortalGPS/InicioGPS.aspx", True)
|
||||
ReturnUrl = "/PortalGPS/InicioGPS.aspx"
|
||||
Else
|
||||
Alert("El usuario no esta autorizado en este equipo, favor de contactar al administrador de usuarios.", TipoMensaje.MsgAdvertencia)
|
||||
'PLATAFORMA SIG
|
||||
CType(Session("UsuarioSIG"), Usuario).CvePlataforma = 1
|
||||
Dim dt As Data.DataTable = GlobalDTUsuarios(Usuario.CveUsuario)
|
||||
If dt IsNot Nothing Then
|
||||
If dt.Rows.Count >= 1 Then
|
||||
If dt.Rows.Count > 1 Then
|
||||
Usuario.MultipleEmpresa = True
|
||||
End If
|
||||
'FormsAuthentication.RedirectFromLoginPage(Encripta(Usuario.CveUsuario), False)
|
||||
End If
|
||||
End If
|
||||
dt.Dispose()
|
||||
End If
|
||||
'If Usuario.Acceso > 0 Then
|
||||
|
||||
'Else
|
||||
' Alert("Usuario con acceso limitado.", TipoMensaje.MsgAdvertencia)
|
||||
'End If
|
||||
Dim cookie = FormsAuthentication.GetAuthCookie(Usuario.CveUsuario, False)
|
||||
Response.Cookies.Add(cookie)
|
||||
Dim routeangular As String
|
||||
Dim puerto As String = ""
|
||||
|
||||
If Not IsNothing(Request("port")) Then
|
||||
puerto = String.Format(":{0}", Request("port"))
|
||||
Else
|
||||
puerto = String.Format(":{0}", If(System.Configuration.ConfigurationManager.AppSettings("EsProduccion").ToString() = "1", 84, 4200))
|
||||
End If
|
||||
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
|
||||
Dim token As String = GetTokenAngular()
|
||||
routeangular = String.Format("{0}{1}/auth/login?token={3}{4}&returnUrl=/{2}", strdomain, puerto, HttpUtility.UrlEncode(ReturnUrl), HttpUtility.UrlEncode(token), If(puerto.Length > 0, "cerrar=1&", ""))
|
||||
'S ies angular retiro el https para que no marque error la pagina
|
||||
routeangular = routeangular.Replace("https", "http")
|
||||
routeangular = routeangular.Replace("HTTPS", "HTTP")
|
||||
If Not IsNothing(Request("port")) Then
|
||||
ReturnUrl = routeangular
|
||||
routeangular = ""
|
||||
End If
|
||||
RegistraScript(String.Format("opennewlocation('{0}','{1}')", ReturnUrl, routeangular))
|
||||
'Response.Redirect(ReturnUrl, True)
|
||||
Else
|
||||
Alert("Usuario y/o Contraseña incorrectos.", TipoMensaje.MsgAdvertencia)
|
||||
Alert("El usuario no esta autorizado en este equipo, favor de contactar al administrador de usuarios.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
'If Usuario.Acceso > 0 Then
|
||||
|
||||
'Else
|
||||
' Alert("Usuario con acceso limitado.", TipoMensaje.MsgAdvertencia)
|
||||
'End If
|
||||
Else
|
||||
Alert("Usuario y/o Contraseña incorrectos.", TipoMensaje.MsgAdvertencia)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
Private Function GetTokenAngular() As String
|
||||
If Not IsNothing(Context.Session("UsuarioSIG")) Then
|
||||
|
||||
Dim usuario As Usuario = DirectCast(Context.Session("UsuarioSIG"), Usuario)
|
||||
Dim tokenDescriptor = New Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor With {
|
||||
.Subject = New System.Security.Claims.ClaimsIdentity(New System.Security.Claims.Claim() {New System.Security.Claims.Claim("CvePlataforma", usuario.CvePlataforma.ToString()),
|
||||
New System.Security.Claims.Claim("CveUsuario", usuario.CveUsuario.ToString()), New System.Security.Claims.Claim("CveEmpresa", usuario.CveEmpresa.ToString()),
|
||||
New System.Security.Claims.Claim("CveRol", usuario.CveRol.ToString()), New System.Security.Claims.Claim("Fecha", Date.Now.ToLongDateString())}),
|
||||
.Expires = Date.UtcNow.AddHours(3),
|
||||
.SigningCredentials = New Microsoft.IdentityModel.Tokens.SigningCredentials(
|
||||
New Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.ASCII.GetBytes("*_AsistenciaDesarrolloSistemas-SIGAPI_*17-06-2020")),
|
||||
Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature)}
|
||||
Dim tokenHandler = New System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler()
|
||||
Dim newtoken = tokenHandler.CreateToken(tokenDescriptor)
|
||||
Dim stokenn As String = tokenHandler.WriteToken(newtoken)
|
||||
Return stokenn
|
||||
Else
|
||||
Return ""
|
||||
End If
|
||||
|
||||
End Function
|
||||
Private Sub CreaObjetoEmpresa(ByRef UsuarioActual As Usuario)
|
||||
|
||||
Dim ObjEmpresa As New ClsSisEmpresas()
|
||||
|
||||
Reference in New Issue
Block a user