-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirmEmail.aspx.cs
109 lines (95 loc) · 4 KB
/
confirmEmail.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Net.Mail;
using RandomNumber;//Generates random number and return the value in string format
public partial class confirmEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Session["createEmail"] as string))
{
Label1.Text = null;
}
if (!string.IsNullOrEmpty(Session["createEmail"] as string))
{
string userEmail = Session["createEmail"].ToString();
string userPassword = Session["createPassword"].ToString();
Session["_email"] = userEmail;
Session["_password"] = userPassword;
// Random rn = new Random();
//int randomNumber = rn.Next(100000, 999999);
RandomGenerator obj = new RandomGenerator();
string _rndNumber = obj.randomNumber(100000,999999);
//Session["_rndNumber"] = randomNumber.ToString();
Session["_rndNumber"] = _rndNumber;
string subject = "Confirm registration code";
try
{
using (MailMessage mm = new MailMessage("[email protected]", userEmail))
{
mm.Subject = subject;
mm.Body = Session["_rndNumber"].ToString();
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("[email protected]", "a22334455");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
//try
//{
// System.Net.Mail.MailMessage objemail = new System.Net.Mail.MailMessage();
// objemail.From = new MailAddress("[email protected]");
// objemail.To.Add(new MailAddress(userEmail));
// objemail.Subject = subject;
// objemail.IsBodyHtml = true;
// objemail.Body = Session["_rndNumber"].ToString();
// SmtpClient client = new SmtpClient();
// client.EnableSsl = true;
// client.Send(objemail);
// // Response.Write("<script>alert('Pin has been sent to your email. Please open it.')</script>");
// Label1.Text = "Pin has been sent to your email. Please confirm it.";
//}
catch (Exception ex)
{
Response.Write("<script>alert('Failed to send email'+ex.message)</script>");
}
finally
{
Session.Remove("createEmail");
Session.Remove("createPassword");
//Session["Email"] = null;
//Session["Password"] = null;
}
}
}
protected void ButtonPinConfirm_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(TextBoxPin.Text) == (Convert.ToInt32(Session["_rndNumber"].ToString())))
{
DBOperation cr = new DBOperation();
cr.create(Session["_email"].ToString(), Session["_password"].ToString());
Session["Email"] = Session["_email"];
Session.Remove("_rndNumber");
Session.Remove("_email");
Session.Remove("_password");
Response.Write("<script>alert('Congrats! Your account has been created succesfully!!')</script>");
Response.Redirect("~/admin/insert_tutorial.aspx");
}
else
{
Response.Write("<script>alert('Pin do not match')</script>");
}
}
}