-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRegistration.aspx.cs
124 lines (120 loc) · 5.54 KB
/
Registration.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;
using System.Net.Mail;
using System.Net;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RegisterUser(object sender, EventArgs e)
{
#region commented hardcode insert
//MySqlConnection con = new MySqlConnection();
//con.ConnectionString = "server=173.194.241.131;database=auction_powers;uid=root;pwd=root;";
//MySqlCommand cmd = null;
////add freetext to db
//con.Open();
//cmd = new MySqlCommand();
//cmd.Parameters.AddWithValue("?username", txtUsername.Text.Trim());
//cmd.Parameters.AddWithValue("?password", txtPassword.Text.Trim());
//cmd.Parameters.AddWithValue("?email", txtEmail.Text.Trim());
//cmd.Connection = con;
//cmd.CommandText = "INSERT INTO user (username, `password`, email) VALUES (?username, ?password, ?email)";
//cmd.ExecuteNonQuery();
//con.Close();
#endregion
User registering_user = new User(txtUsername.Text.Trim(), txtPassword.Text.Trim(), txtEmail.Text.Trim());
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = "server=173.194.241.131;database=auction_powers;uid=root;pwd=root;";
MySQLClient register_user = new MySQLClient(conn);
register_user.Insert_Users(registering_user);
}
protected void RegisterUser2(object sender, EventArgs e)
{
int user_Id;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand("Insert_User"))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Username", txtUsername.Text.Trim());
cmd.Parameters.AddWithValue("Pass", txtPassword.Text.Trim());
cmd.Parameters.AddWithValue("Email", txtEmail.Text.Trim());
cmd.Connection = con;
con.Open();
user_Id = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
}
string message = string.Empty;
switch (user_Id)
{
case -1:
message = "Username already exists.\\nPlease choose a different username.\\n" + txtUsername.Text;
break;
case -2:
message = "Supplied email address has already been used.";
break;
default:
message = "Registration successful.\\nUser Id: " + user_Id/*.ToString()*/;
SendActivationEmail(user_Id);//line 81
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
// this isn't quite working look at line 75 for some reason it is passing in the integer 0 instead of the userId
private void SendActivationEmail(int user_Id)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string activation_Code = Guid.NewGuid().ToString();
//string message = "The activation code: " + activation_Code + "\\n The User_Id: " + user_Id;
//ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
using (MySqlConnection con = new MySqlConnection(constr))
{
//using (MySqlCommand cmd = new MySqlCommand("INSERT INTO User_Activation VALUES(_User_Id, _Activation_Code)"))
using (MySqlCommand cmd = new MySqlCommand("User_Activation"))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("_User_Id", user_Id);
cmd.Parameters.AddWithValue("_Activation_Code", activation_Code);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
using (MailMessage mm = new MailMessage("[email protected]", txtEmail.Text))
{
mm.Subject = "Account Activation";
string body = "Hello " + txtUsername.Text.Trim() + ",";
body += "<br /><br />Please click the following link to activate your account";
body += "<br /><a href = '" + Request.Url.AbsoluteUri.Replace("Registration.aspx", "Activation.aspx?Activation_Code=" + activation_Code) + "'>Click here to activate your account.</a>";
body += "<br /><br />Thanks";
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("[email protected]", "auctionp1");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
}