Code Behind Page Page /Login.aspx.cs (C#)
Used by Page /Login.aspx (C#)
1: using System;  
2: using System.Web;  
3: using System.Web.Security;  
4: using System.Web.UI.WebControls;  
5: using Microsoft.ApplicationBlocks.Data;  
6: using QuizNetOnline.Logic;  
7: using System.Text.RegularExpressions;  
8: using System.Configuration;  
9:   
10:   
11: namespace QuiznetOnline.Web.UI  
12: {  
13:     public partial class Login : QuiznetOnline.Web.UI.BusinessClasses.BasePage  
14:     {  
15:   
16:         protected override void Page_Load(object sender, EventArgs e)  
17:         {  
18:               
19:             if (!Page.IsPostBack)  
20:             {  
21:                 base.Page_Load(sender, e);  
22:                 Master.ShowLogin(false);  
23:   
24:                 if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsLocalHost"]) == true)  
25:                     WebLogin.UserName = "??????????????????????";  
26:                       
27:   
28:                 if (Request.Cookies["QuiznetOnlineCookie"] != null)  
29:                 {  
30:                     HttpCookie cookie = Request.Cookies.Get("QuiznetOnlineCookie");  
31:                     if (cookie != null)  
32:                     {  
33:                         string emailID = cookie.Values["Email"] ?? "";  
34:                         WebLogin.UserName = emailID;  
35:                     }  
36:                 }  
37:             }  
38:         }  
39:   
40:         static bool IsValidEmail(string strIn)  
41:         {  
42:             // Return true if strIn is in valid e-mail format.  
43:             return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");  
44:         }  
45:   
46:         protected void WebLogin_Authenticate(object sender, AuthenticateEventArgs e)  
47:         {  
48:             // Authenticate with the membership user name corresponding to the supplied  
49:             // e-mail address  
50:             if (!IsValidEmail(WebLogin.UserName))  
51:             {  
52:                 WebLogin.InstructionText = "Enter a valid e-mail address.";  
53:                 WebLogin.InstructionTextStyle.ForeColor = System.Drawing.Color.Red;  
54:                 e.Authenticated = false;  
55:             }  
56:   
57:             string username = Membership.GetUserNameByEmail(WebLogin.UserName);  
58:             username = username ?? WebLogin.UserName;  
59:             if ((username != null) || (Convert.ToBoolean(ConfigurationManager.AppSettings["IsLocalHost"]) == true))  
60:             {  
61:                 if (Request["Impersonate"] != null && Crypto.Decrypt(Request["Impersonate"].ToString(), new Crypto()) == "???????????")  
62:                     e.Authenticated = true;  
63:                 //Impersonatation from Admin Form  
64:                 else if(Convert.ToBoolean(ConfigurationManager.AppSettings["IsLocalHost"]) == true)  
65:                 {  
66:                     e.Authenticated = Membership.ValidateUser(username, "????????????");  
67:                 }  
68:                 else  
69:                     e.Authenticated = Membership.ValidateUser(username, WebLogin.Password);  
70:                   
71:                 QuizNetSystem quizNetSystem=new QuizNetSystem();  
72:                 quizNetSystem.UpdateNewsLetterEmail(username,true,new SqlWrapper());  
73:             }  
74:   
75:             ((UserWeb)Session["userWeb"]).UserName = username;  
76:               
77:         }  
78:   
79:         protected void WebLogin_LoggedIn(object sender, EventArgs e)  
80:         {  
81:             HttpCookie quiznetOnlineCookie;  
82:   
83:             CheckBox rm = (CheckBox)WebLogin.FindControl("RememberMe");  
84:             if (rm.Checked)  
85:             {  
86:                 Response.Cookies.Remove("QuiznetOnlineCookie");  
87:                 quiznetOnlineCookie = new HttpCookie("QuiznetOnlineCookie");  
88:                 quiznetOnlineCookie.Values.Add("Email", this.WebLogin.UserName.ToString());  
89:                 quiznetOnlineCookie.Values.Add("Password", Crypto.Encrypt(this.WebLogin.Password.ToString(), new Crypto()));  
90:                 quiznetOnlineCookie.Expires = DateTime.Now.AddMonths(6);  
91:                 Response.Cookies.Add(quiznetOnlineCookie);  
92:             }        
93:             else  
94:             {  
95:                 // If there's an updated cookie then get it, otherwise get the old one  
96:                 if (string.IsNullOrEmpty(Response.Cookies["QuiznetOnlineCookie"].Value) && Response.Cookies["QuiznetOnlineCookie"].Expires == DateTime.MinValue)  
97:                 {  
98:                     Response.Cookies["QuiznetOnlineCookie"].Expires = DateTime.Now.AddYears(-30);  
99:                 }  
100:             }  
101:         }  
102:     }  
103: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.