using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AeroNet
{
///
/// Summary description for Login.
///
public class Login : Common
{
protected System.Web.UI.WebControls.Label lblText;
protected System.Web.UI.WebControls.Button LoginBtn;
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 password;
protected System.Web.UI.WebControls.CheckBox RememberLogin;
protected System.Web.UI.WebControls.RequiredFieldValidator rvfPass;
protected string exit;
private void LoginBtn_Click(object sender, System.EventArgs e)
{
// Попытка входа в систему делается только в случае, если все поля формы на
// странице верны
if (Page.IsValid == true)
{
// Сохранение старого ShoppingCartID
ShoppingCartDB shoppingCart = new ShoppingCartDB();
String tempCartID = shoppingCart.GetShoppingCartId();
// Попытка проверки соответствия удостоверений пользователя с применением
// CustomersDB
CustomersDB accountSystem = new CustomersDB();
String customerId = accountSystem.Login(email.Text, Security.Encrypt(password.Text));
if (customerId != null)
{
// Перемещение всех имеющихся в покупательской корзине элементов в постоянную
// покупательскую корзину
shoppingCart.MigrateCart(tempCartID, customerId);
// Поиск подробностей учетной записи клиента
CustomerDetails customerDetails = accountSystem.GetCustomerDetails(customerId);
// Размещение полного имени пользователя в cookie для целей персонализации
Response.Cookies["FullName"].Value = customerDetails.FullName;
// Cookie становится постоянным только в том случае, если пользователь выбирает
// в соответствующем пункте тип входа в систему "постоянный"
if (RememberLogin.Checked == true)
{
Response.Cookies["FullName"].Expires = DateTime.Now.AddMonths(1);
}
// Перенаправление браузера обратно на исходную страницу
FormsAuthentication.RedirectFromLoginPage(customerId, RememberLogin.Checked);
}
else
{
lblText.Text = "
Пользователь не найден. Возможно Вы неправильно указали имя или пароль.
";
}
}
}
private void Page_Load(object sender, System.EventArgs e)
{
//Загрузить верхнее меню
TopMenu();
//Получить ReturnUrl из строки запроса
try
{
if (Request.QueryString["ReturnUrl"] == null)
{
exit = "Catalog.aspx";
}
else
{
exit = Request.QueryString["ReturnUrl"];
}
}
catch
{
Response.Redirect("error.aspx",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.LoginBtn.Click += new System.EventHandler(this.LoginBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}