1
I would like to call my code a function in javascript that is found in my html. It follows below my codes
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="webReport0800net.login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Relatórios CSC - Login</title>
<script src="js/dhtmlx.js" type="text/javascript"></script>
<link href="css/dhtmlx.css" rel="stylesheet" type="text/css" />
<link href="css/roboto.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function ValidaUsuario() {
if (document.getElementById("<%=usuTextBox.ClientID%>").value == "") {
dhtmlx.message(
{ type: "error", text: "Login inválido! Favor informar seu ID GR" }
)
//alert("Informe o nome.");
document.getElementById("<%=usuTextBox.ClientID%>").focus();
return false;
} else {
//REGEX para aceitar apens texto no formado dos IDs da GRSA
var ck_id1 = /^[Ff]{1}[Ee]{1}[Gg]{1}[Rr]{1}\d{4}$/;
var ck_id2 = /^[Gg]{1}[Rr]{1}\d{6}$/;
var tempNome = document.getElementById("<%=usuTextBox.ClientID%>").value;
var matchNome1 = tempNome.match(ck_id1);
var matchNome2 = tempNome.match(ck_id2);
if (matchNome1 == null && matchNome2 == null) {
dhtmlx.message(
{ type: "error", text: "ID informado é inválido! Favor informar seu ID GR" }
)
document.getElementById("<%=usuTextBox.ClientID %>").focus();
return false;
}
else {
if (document.getElementById("<%=senhaTextBox.ClientID%>").value == "") {
dhtmlx.message(
{ type: "error", text: "Favor digitar a sua senha de rede!" }
)
document.getElementById("<%=senhaTextBox.ClientID%>").focus();
return false;
}
}
}
function Erro() {
dhtmlx.message(
{ type: "error", text: "Usuário e/ou senha incorretos!!" }
)
}
return true;
}
</script>
<style type="text/css">
body
{
background-color: #bea879
}
.div_p
{
position:absolute;
top:13%;
left:35%;
background-color: #eeece0;
width: 350px;
-webkit-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
-box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
-moz-border-radius:15px;
-box-border-radius:15px;
-webkit-border-radius:15px;
border-radius:15px;
}
.div_logo_gr
{
position:relative;
padding-top:5%;
padding-left:28%;
}
.div_text
{
text-align:center;
color:Blue;
}
.div_form_login
{
position:relative;
padding-top:5%;
padding-left:30%;
}
.modal_loader
{
position: fixed;
z-index: 999;
padding-top: 15px;
background-color:Transparent;
filter: alpha(opacity=60);
opacity: 0.6;
-moz-opacity: 0.8;
}
.div_logo_csc
{
position:relative;
padding-left:33%;
padding-bottom:5%;
}
</style>
</head>
<body>
<div class=div_p>
<div class=div_logo_gr>
<img src="img/logo-gr-compass.jpg" />
</div>
<br />
<div class=div_text>
Relatórios gerenciais CSC. Acesso ao sistema
</div>
<div class=div_text>
Use seu ID e senha de rede para o acesso
</div>
<div class=div_form_login>
<form id="login" runat="server">
<asp:ScriptManager ID="loginFormScriptManager" EnablePageMethods="true" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="loginFormUpdateProgress" runat="server" AssociatedUpdatePanelID="loginFormUpdatePanel">
<ProgressTemplate>
<div class=modal_loader>
<div class="center">
<img alt="" src="img/loader.gif" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<div>
<asp:UpdatePanel ID="loginFormUpdatePanel" runat="server">
<ContentTemplate>
<div>
<b>Login</b>
</div>
<div>
<asp:TextBox ID="usuTextBox" runat="server"></asp:TextBox>
</div>
<div style="margin-top:7px;">
<b>Senha</b>
</div>
<div>
<asp:TextBox ID="senhaTextBox" runat="server" TextMode="Password"></asp:TextBox>
</div>
<div style="margin-top:7px;">
<asp:CheckBox ID="lembrarUsuarioCheckBox" runat="server" Font-Bold="True"
Text="Lembrar Usuário / Senha" />
</div>
<div style="margin-top:7px;">
<asp:Button ID="validaButton" runat="server" Text="Acessar"
OnClientClick=" return ValidaUsuario()" onclick="validaButton_Click" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</div>
<br />
<div class=div_logo_csc>
<img src="img/logo_csc.jpg" />
</div>
</div>
</body>
</html>
CODE BEHIND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Net;
namespace webReport0800net
{
public partial class login : System.Web.UI.Page
{
string retornoLogon;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
usuTextBox.Text = string.Empty;
senhaTextBox.Text = string.Empty;
}
}
protected void validaButton_Click(object sender, EventArgs e)
{
string adPath = "LDAP://DC=gr,DC=sa"; //Path to your LDAP directory server
LdapAuthentication adAuth = new LdapAuthentication(adPath);
try
{
retornoLogon = adAuth.IsAuthenticated("gr.sa", usuTextBox.Text, senhaTextBox.Text);
if(!retornoLogon.Contains("Ocorreu") || !retornoLogon.Contains("Erro"))
{
string groups = adAuth.GetGroups();
//Create the ticket, and add the groups.
bool isCookiePersistent = lembrarUsuarioCheckBox.Checked;
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
usuTextBox.Text, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, groups);
//Encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
//Create a cookie, and then add the encrypted ticket to the cookie as data.
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
if (true == isCookiePersistent)
authCookie.Expires = authTicket.Expiration;
//Add the cookie to the outgoing cookies collection.
Response.Cookies.Add(authCookie);
//You can redirect now.
if (Request.QueryString["ReturnUrl"] != null)
{
Response.Redirect(FormsAuthentication.GetRedirectUrl(usuTextBox.Text, false));
}
else
{
System.Threading.Thread.Sleep(5000);
//PerfilClass.MyLogin = usuTextBox.Text.ToString().ToUpper();
//PerfilClass.MyNome = retornoLogon.ToString().ToUpper();
//PerfilClass.MyHost = Environment.MachineName.ToString().ToUpper();
//foreach (var item in Dns.GetHostAddresses(Environment.MachineName))
//{
// if (item.ToString().Substring(0,3) == "172")
// {
// PerfilClass.MyIP = item.ToString();
// break;
// }
//}
//Response.Redirect("~/menu.aspx");
return;
}
}
}
catch (Exception ex)
{
//Já tentei todas linhas abaixo mas não funciona.
//Quando debugo as linhas são interpretadas sem error
ScriptManager.RegisterStartupScript(this, typeof(Page), "UpdateMsg", "$(document).ready(function(){EnableControls();alert('Overrides successfully Updated.');DisableControls();});", true);
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "mensagem", "Erro()", true);
ClientScript.RegisterClientScriptBlock(this.GetType(), "showmessagebox", "Erro();", true);
Page.ClientScript.RegisterStartupScript(this.GetType(),"Erro", "Erro();", true);
}
}
}
}