public RespuestaSesion ValidarAcceso(string url, string usuario) { try { RespuestaSesion respuestaSesion = new RespuestaSesion(); IDAOSistema iDaoSistema = new DAOSistema(); RespuestaBD resp = iDaoSistema.ValidarAcceso(url, usuario); if (resp.EXISTE_ERROR) { respuestaSesion.Activa = false; respuestaSesion.Mensaje = resp.MENSAJE; respuestaSesion.Code = resp.respuesta; } else { respuestaSesion.Activa = true; respuestaSesion.Mensaje = "Acceso permitido"; respuestaSesion.Code = "0"; } return(respuestaSesion); } catch (Exception ex) { throw new Exception(new Util().ObtenerMsjExcepcion(ex)); } }
public RespuestaSesion ValidarToken(string token) { try { RespuestaSesion respuestaSesion = new RespuestaSesion(); IDAOSistema iDaoSistema = new DAOSistema(); RespuestaBD resp = iDaoSistema.ValidarToken(token); if (resp.EXISTE_ERROR) { respuestaSesion.Activa = false; respuestaSesion.Mensaje = resp.MENSAJE; respuestaSesion.Code = resp.respuesta; } else { respuestaSesion.Activa = true; respuestaSesion.Mensaje = "Token ok"; respuestaSesion.Code = "0"; } return(respuestaSesion); } catch (Exception ex) { throw new Exception(new Util().ObtenerMsjExcepcion(ex)); } }
public List <E.VMItemModulo> ObtenerItemsUsuario(string usuario) { try { List <E.VMItemModulo> items = new DAOSistema(this.usuario, this.pass).ObtenerItemsUsuario( usuario ); return(items); } catch (Exception ex) { throw new Exception(ex.Message); } }
public string IniciarSesion(string usuario, string llave, string ip, string sistema, bool cerrarSesiones) { try { Exception excep = new Exception(""); if (llave.Length > 0) { byte[] usr = Convert.FromBase64String(usuario); byte[] pws = Convert.FromBase64String(llave); llave = Encriptacion.EncriptarContraseña(Encriptacion.Desencriptar(pws), Encriptacion.Desencriptar(usr)); //Obtiene llave del usuario IDAOSistema iDaoSis = new DAOSistema(); RespuestaBD resp = iDaoSis.IniciarSesion(Encriptacion.Desencriptar(usr), llave, ip, sistema, cerrarSesiones); if (resp.EXISTE_ERROR) { excep = new Exception(resp.MENSAJE); excep.Data.Add("code", resp.respuesta); throw excep; } else { return(this.GenerarToken(Encriptacion.Desencriptar(usr))); } } else { excep = new Exception("Constraseña no especificada"); excep.Data.Add("code", 1); throw excep; } } catch (Exception ex) { Exception excep = new Exception(new Util().ObtenerMsjExcepcion(ex)); if (ex.Data["code"] == null) { excep.Data.Add("code", 1);//Error no especificado } else { excep.Data.Add("code", ex.Data["code"]); } throw excep; } }
public void CerrarSesion(string usuario) { try { IDAOSistema iDaoSis = new DAOSistema(); RespuestaBD resp = iDaoSis.CerrarSesion(usuario); if (resp.EXISTE_ERROR) { throw new Exception(resp.MENSAJE); } } catch (Exception ex) { throw new Exception(new Util().ObtenerMsjExcepcion(ex)); } }
public string GenerarToken(string usuario) { try { //Genera token string bufer = "USUARIO=" + usuario + ";Time=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string token = Convert.ToBase64String(Encriptacion.Encriptar(bufer, usuario)); string nombre = string.Empty; string correo = string.Empty; string extension = string.Empty; //Busca informacion de usuario IDAOUsuario iDaoUsuario = new DAOUsuario(); RespuestaBD resp = iDaoUsuario.ObtenerListaUsuarios(null, usuario); if (!resp.EXISTE_ERROR) { if (resp.dataSet.Tables[0].Rows.Count > 0) { DataRow r = resp.dataSet.Tables[0].Rows[0]; nombre = (string)r["fc_nombre"] + " " + (string)r["fc_apellido_p"] + " " + (string)r["fc_apellido_m"]; correo = (string)r["fc_correo"]; extension = (string)r["fc_extension_usuario"]; } } string cadRespuesta = nombre + ";" + correo + ";" + extension + ";" + usuario + ";" + token; RespuestaSesion respuestaSesion = new RespuestaSesion(); IDAOSistema iDaoSistema = new DAOSistema(); resp = iDaoSistema.RegistrarToken(token, DateTime.Now.AddMinutes(15), usuario); if (resp.EXISTE_ERROR) { throw new Exception("No es posible registrar el Token"); } return(Convert.ToBase64String(Encriptacion.Encriptar(cadRespuesta)));//Retorna cadena encriptada } catch (Exception ex) { throw new Exception(new Util().ObtenerMsjExcepcion(ex)); } }