protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { pent.pentagSQL pentSQL = new pent.pentagSQL(); string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["pentagonov2ConnectionString"].ConnectionString; if (Session["userID"] == null) { //string url = Request.RawUrl; Response.Redirect("login.aspx?pag=vos"); } txt_viewer.Text = Session["userName"].ToString(); area_nameLabel.Text = pentSQL.getUsersAreaDesc(Session["Area"].ToString(), ConnectionString); AreaId.Text = Session["Area"].ToString(); } txt_fecha.Text = DateTime.Today.ToShortDateString(); }
private bool dataLogin(string Usuario, string Contrasena) { bool auth = false; string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["pentagonov2ConnectionString"].ConnectionString; LDAPaccess authLdap = new LDAPaccess(); pent.pentagSQL pentSQL = new pent.pentagSQL(); tbl_userTableAdapter usuarioAdapter = new tbl_userTableAdapter(); DataTable dtUsuario = new DataTable(); dtUsuario = usuarioAdapter.GetDataByUser(Usuario, Contrasena); auth = authLdap.autenticado(Usuario, Contrasena); if (auth) { string[] userInfo = { "", "" }; userInfo = authLdap.datosLdapUser(txtUser.Text); Session["email"] = userInfo[0]; Session["user_Name"] = userInfo[1]; dtUsuario = usuarioAdapter.GetDataByNetUser(Usuario); if (dtUsuario.Rows.Count == 1) { Session["userID"] = Convert.ToInt32(dtUsuario.Rows[0]["usr_id"]); Session["userName"] = Convert.ToString(dtUsuario.Rows[0]["usr_username"]); Session["userRol"] = Convert.ToInt32(dtUsuario.Rows[0]["rol_id"]); Session["Area"] = pentSQL.getUsersArea(Convert.ToInt32(dtUsuario.Rows[0]["usrInfo_id"]), ConnectionString); if (Convert.ToString(Session["email"]) == "") { tbl_userInfoTableAdapter usrInfo = new tbl_userInfoTableAdapter(); Session["email"] = Convert.ToString(usrInfo.getEmailByUser(Convert.ToInt32(dtUsuario.Rows[0]["usrInfo_id"]))); usrInfo.Dispose(); } auth = true; usuarioAdapter.updateLastAccess(DateTime.Now, Convert.ToInt32(dtUsuario.Rows[0]["usr_id"])); } else { Session["userID"] = 0; Session["userName"] = Usuario; Session["userRol"] = 4; } } else { if (dtUsuario.Rows.Count == 1) { Session["userID"] = Convert.ToInt32(dtUsuario.Rows[0]["usr_id"]); Session["userName"] = Convert.ToString(dtUsuario.Rows[0]["usr_username"]); Session["userRol"] = Convert.ToInt32(dtUsuario.Rows[0]["rol_id"]); pentagSQL bd = new pentagSQL(); string userInfoID = bd.getSingleValueByID("usrInfo_id", Session["userName"].ToString(), "tbl_user", "usr_username", ConnectionString); string nameUser = bd.getSingleValueByID("usrInfo_name", userInfoID, "tbl_userInfo", "usrInfo_id", ConnectionString); Session["user_Name"] = nameUser; tbl_userInfoTableAdapter usrInfo = new tbl_userInfoTableAdapter(); Session["email"] = Convert.ToString(usrInfo.getEmailByUser(Convert.ToInt32(dtUsuario.Rows[0]["usrInfo_id"]))); Session["Area"] = pentSQL.getUsersArea(Convert.ToInt32(dtUsuario.Rows[0]["usrInfo_id"]), ConnectionString); usrInfo.Dispose(); auth = true; usuarioAdapter.updateLastAccess(DateTime.Now, Convert.ToInt32(dtUsuario.Rows[0]["usr_id"])); } } usuarioAdapter.Dispose(); dtUsuario.Dispose(); return(auth); }