ASP.NET Page /UserLogin/PasswordReset.aspx.cs (C#)
1: using System;  
2: using System.Configuration;  
3: using System.Web;  
4: using System.Web.Security;  
5: using System.Web.UI.WebControls;  
6: using QuizNetOnline.Logic;  
7:   
8: namespace QuiznetOnline.Web.UI.UserLogin  
9: {  
10:     public partial class PasswordReset : QuiznetOnline.Web.UI.BusinessClasses.BasePage  
11:     {  
12:         private string _email = string.Empty;  
13:         private MembershipUser _user = null;  
14:   
15:         protected override void Page_Load(object sender, EventArgs e)  
16:         {  
17:             if (!IsPostBack)  
18:             {  
19:                 base.Page_Load(sender, e);  
20:   
21:                 Master.ShowHideMenu(false);  
22:                 // Set the default button to the password control's submit button  
23:                 Form.DefaultButton = AppPasswordRecovery.FindControl("UserNameContainerID").FindControl("SubmitButton").UniqueID;  
24:             }  
25:         }  
26:         protected void AppPasswordRecovery_VerifyingUser(object sender, LoginCancelEventArgs e)  
27:         {  
28:             _email = string.Empty;  
29:             _user = null;  
30:   
31:             // Get the user by email  
32:             _email = AppPasswordRecovery.UserName;  
33:             MembershipUserCollection users = Membership.FindUsersByEmail(_email);  
34:             if (users.Count == 1)  
35:             {  
36:                 foreach (MembershipUser u in users)  
37:                 {  
38:                     _user = u;  
39:                 }  
40:             }  
41:   
42:             if (_user != null)  
43:             {  
44:                 AppPasswordRecovery.UserName = _user.UserName;  
45:             }  
46:         }  
47:   
48:         protected void AppPasswordRecovery_SendingMail(object sender, MailMessageEventArgs e)  
49:         {  
50:             UriBuilder ub = new UriBuilder(Request.Url)  
51:                 {  
52:                     Query = string.Empty  
53:                 };  
54:   
55:             // If the app settings contains a URI host name, override URI  
56:             string uriHostName = ConfigurationManager.AppSettings["uriHostName"];  
57:             if (!string.IsNullOrEmpty(uriHostName))  
58:             {  
59:                 ub.Host = uriHostName;  
60:             }  
61:   
62:             // Generate the url for the confirmation page  
63:             const string DELIM = "---";  
64:             ub.Path = ResolveUrl("~/UserLogin/CompletePasswordReset.aspx");  
65:             ub.Query = "k=" + Server.UrlEncode(Crypto.Encrypt(_user.UserName + DELIM + Crypto.Encrypt(_user.ResetPassword(), new Crypto()), new Crypto()));  
66:             e.Message.Body = string.Format(HttpContext.GetGlobalResourceObject("Email", "PasswordChangeRequest").ToString(), Environment.NewLine, ub.Uri.AbsoluteUri);  
67:   
68:             if (_user == null)  
69:             {  
70:                 e.Cancel = true;  
71:             }  
72:             else  
73:                 if (!Master.IsEmailingOff)  
74:                 {  
75:                     QuizNetSystem quizNetSystem=new QuizNetSystem();  
76:                     quizNetSystem.ResendFailedEmails();  
77:                 }  
78:         }  
79:   
80:         protected void AppPasswordRecovery_SendMailError(object sender, SendMailErrorEventArgs e)  
81:         {  
82:             UriBuilder ub = new UriBuilder(Request.Url)  
83:                 {  
84:                     Query = string.Empty  
85:                 };  
86:   
87:             // If the app settings contains a URI host name, override URI  
88:             string uriHostName = ConfigurationManager.AppSettings["uriHostName"];  
89:             if (!string.IsNullOrEmpty(uriHostName))  
90:             {  
91:                 ub.Host = uriHostName;  
92:             }  
93:   
94:             // Generate the url for the confirmation page  
95:             const string DELIM = "---";  
96:             ub.Path = ResolveUrl("~/UserLogin/CompletePasswordReset.aspx");  
97:             ub.Query = "k=" + Server.UrlEncode(Crypto.Encrypt(_user.UserName + DELIM + Crypto.Encrypt(_user.ResetPassword(), new Crypto()), new Crypto()));  
98:   
99:             Response.Redirect("~/UserLogin/CompletePasswordReset.aspx" + ub.Query);  
100:         }  
101:   
102:         protected override void OnPreRender(EventArgs e)  
103:         {  
104:             AppPasswordRecovery.UserName = _email;  
105:             base.OnPreRender(e);  
106:         }  
107:     }  
108: }  
109:   

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