using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AeroNet
{
///
/// Summary description for RegUser.
///
public class RegUser : Subscribe
{
protected System.Web.UI.WebControls.Label lblText;
protected System.Web.UI.WebControls.TextBox EMail;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvLogin;
protected System.Web.UI.WebControls.RegularExpressionValidator revLogin;
protected System.Web.UI.WebControls.TextBox PWD;
protected System.Web.UI.WebControls.RequiredFieldValidator rvfPass;
protected System.Web.UI.WebControls.Button btnSend;
bool isUser = false;
public int uid;
///
/// Проверка существования пользователя в базе данных
///
/// Логин (Email)
/// Пароль
/// Идентификационный номер пользователя
public int CheckUser(string email,string pass)
{
int uid = 0;
string strSQL = "SELECT UserID FROM V_Users WHERE Email ='"+email+"' AND Password ='"+pass+"'";
SqlConnection Conn = new SqlConnection(connString);
SqlCommand Command = new SqlCommand(strSQL,Conn);
Conn.Open();
try
{
SqlDataReader Reader;
Reader = Command.ExecuteReader();
if(Reader.Read())
{
uid = Reader.GetInt32(0);
}
Reader.Close();
}
catch
{
Response.Redirect("error.aspx",true);
}
finally
{
Conn.Close();
}
return uid;
}
///
/// Проверка логина и пароля
///
public void Check()
{
System.Collections.Specialized.NameValueCollection colForm = Request.Form;
uid = CheckUser(colForm["Email"],colForm["PWD"] );
if (uid == 0)
{
lblText.Text = "
Пользователь не найден. Возможно Вы неправильно указали имя или пароль.
";
}
else
{
isUser = true;
Session["UserID"] = uid;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
//Загрузить верхнее меню
TopMenu();
Exit = Request.QueryString["exit"];
if (Page.IsPostBack)
{
Check();
}
else
{
if ((Request.Form["Email"]!=null) && (Request.Form["PWD"]!=null))
{
Check();
if (isUser)
{
Response.Redirect(Exit+"uid="+UserID,true);
}
}
}
}
private void btnSend_Click(object sender, System.EventArgs e)
{
if (isUser)
{
Response.Redirect(Exit+"uid="+UserID,true);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}