· 8 years ago · May 27, 2018, 06:56 AM
1override protected void OnInit(EventArgs e)
2 {
3 base.OnInit(e);
4
5 //INSTANT C# NOTE: Converted event handlers:
6 Login1.LoginError += new System.EventHandler(Login1_LoginError);
7 }
8 protected string GetSuperAdminEmailAddress()
9 {
10 MembershipDataClassesDataContext db = new MembershipDataClassesDataContext();
11 var SuperAdminEmailAddress = db.GetSuperAdminEmailAddress().SingleOrDefault();
12
13 return SuperAdminEmailAddress.Email;
14 }
15
16 protected void SendEmail(string UserAddress)
17 {
18
19 string ToAddress = GetSuperAdminEmailAddress();
20
21 //(1) Create the MailMessage instance
22 MailMessage mm = new MailMessage(UserAddress, ToAddress);
23
24 //(2) Assign the MailMessage's properties
25 mm.Subject = UserAddress + " is locked out at ShawDAS";
26 mm.Body = UserAddress + " has been locked out of their account";
27 mm.IsBodyHtml = false;
28
29 //(3) Create the SmtpClient object
30 SmtpClient smtp = new SmtpClient();
31
32 //(4) Send the MailMessage (will use the Web.config settings)
33 smtp.Send(mm);
34 }
35
36 protected void Login1_LoginError(object sender, EventArgs e) //Handles Login1.LoginError
37 {
38 //'Set the parameters for InvalidCredentialsLogDataSource
39 InvalidCredentialsLogDataSource.InsertParameters["ApplicationName"].DefaultValue = Membership.ApplicationName;
40 InvalidCredentialsLogDataSource.InsertParameters["UserName"].DefaultValue = Login1.UserName;
41 InvalidCredentialsLogDataSource.InsertParameters["IPAddress"].DefaultValue = Request.UserHostAddress;
42
43 //'The password is only supplied if the user enters an invalid username or invalid password - set it to Nothing, by default
44 InvalidCredentialsLogDataSource.InsertParameters["Password"].DefaultValue = null;
45
46 //'There was a problem logging in the user
47 //'See if this user exists in the database
48 MembershipUser userInfo;
49 userInfo = Membership.GetUser(Login1.UserName);
50
51 if (userInfo == null)
52 {
53 //'The user entered an invalid username...
54 LoginErrorDetails.Text = "There is no user in the database with the username " + Login1.UserName;
55
56 //'The password is only supplied if the user enters an invalid username or invalid password
57 //InvalidCredentialsLogDataSource.InsertParameters["Password"].DefaultValue = Login1.Password;
58 }else{
59 //'See if the user is locked out or not approved
60 if(!userInfo.IsApproved){
61 LoginErrorDetails.Text = "Your account has not yet been approved by the site's administrators. Please try again later...";
62 }else if(userInfo.IsLockedOut) {
63 LoginErrorDetails.Text = "Your account has been locked out because of a maximum number of incorrect login attempts. The site administrator has been notified. You will NOT be able to login until the site administrator has your account unlocked.";
64 SendEmail(userInfo.Email);
65 }else{
66 //'The password was incorrect (don't show anything, the Login control already describes the problem)
67 LoginErrorDetails.Text = String.Empty;
68
69 //'The password is only supplied if the user enters an invalid username or invalid password
70 InvalidCredentialsLogDataSource.InsertParameters["Password"].DefaultValue = Login1.Password;
71 }
72 }
73
74 //'Add a new record to the InvalidCredentialsLog table
75 InvalidCredentialsLogDataSource.Insert();
76 }
77protected void InvalidCredentialsLogDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
78{
79
80}