using System.Data.OleDb;
partial class Login : System.Web.UI.Page
{
private void Page_Load(System.Object sender, System.EventArgs e)
{
if (!string.IsNullOrEmpty(Request.Form["btnLogin"]))
{
string sToken = GetToken(Request.Form["selUserName"]);
if (!string.IsNullOrEmpty(sToken))
{
Response.Cookies["token"].Value = sToken;
Response.Redirect("../ReportPortal/login.aspx");
}
}
}
public string GetToken(string sUserName)
{
string sSql = "exec GetSecurityTokenForUser @UserName='" + sUserName + "'";
return GetSingleSqlValue(sSql);
}
private OleDbConnection GetConnection()
{
string sFilePath = Server.MapPath("xmla.udl");
string sConnectionString = "File Name=" + sFilePath;
OleDbConnection cn = new OleDbConnection(sConnectionString);
try
{
cn.Open();
}
catch (Exception ex)
{
throw new Exception("Could not connect to the database. Please double click " + sFilePath + " and point it to ReportPortal database. Make sure to save the connection and check the option to 'Allow saving password'.");
}
return cn;
}
public string GetSingleSqlValue(string sSql)
{
string sRet = null;
OleDbConnection cn = GetConnection();
OleDbCommand cmd = new OleDbCommand(sSql, cn);
try
{
sRet = (string) cmd.ExecuteScalar();
}
catch (Exception ex)
{
throw new Exception(ex.Message + "; SQL: " + sSql);
}
cn.Close();
return sRet;
}
public string GetUserList()
{
string sSql = "SELECT UserId, UserName FROM AppUser";
OleDbCommand cmd = new OleDbCommand(sSql, GetConnection());
OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while (dr.Read())
{
string sUserName = (string)dr.GetValue(dr.GetOrdinal("UserName"));
sb.Append("<option value=" + sUserName + ">" + sUserName + "</option>\n");
}
dr.Close();
return sb.ToString();
}
}