-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.cshtml.cs
246 lines (232 loc) · 13.2 KB
/
login.cshtml.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using System.Net;
using Microsoft.AspNetCore.Http;
using s3cr3tx.Models;
using System.Text.Json;
using System.Data.SqlClient;
using System.Data;
using Microsoft.Net.Http.Headers;
namespace s3cr3tx.Pages
{
public class LoginModel : PageModel
{
//private readonly ILogger<IndexModel> _logger;
public s3cr3tx.Models.Login loginCurrent;
public s3cr3tx.Models.LoginDbContext LoginContext;
public string _output;
public LoginModel(s3cr3tx.Models.LoginDbContext loginDbContext)
{
LoginContext = loginDbContext;
loginCurrent = new Login();
_output = loginCurrent.Output;
}
//public s3cr3tx.S3cr3tx S3Cr3Tx;
public void OnGet([Bind("member_email", "member_code", "Output")] s3cr3tx.Models.Login login)
{
try
{
loginCurrent = login;
loginCurrent.Output = _output;
}
catch (Exception ex)
{
string strSource = @"s3cr3tx.api.RegisterPageCS.OnGet";
s3cr3tx.Controllers.ValuesController.LogIt(ex.GetBaseException().ToString(), strSource);
}
}
public string Message { get; set; } = "";
public void OnPostView([Bind("member_email", "member_code","Output")] s3cr3tx.Models.Login loginC)
{
try
{
string email = loginC.member_email; //= member;
HttpRequest Request = HttpContext.Request;
if (Request.Form.TryGetValue("loginCurrent.member_email", out Microsoft.Extensions.Primitives.StringValues Email))
{
if (Request.Form.TryGetValue("loginCurrent.member_code", out Microsoft.Extensions.Primitives.StringValues Code))
{
loginCurrent.member_email = Email[0].ToLower();
loginCurrent.member_code = Code[0];
//now insert new member into the database
DateTime dtTimeStamp = DateTime.Now;
string strResult = @"";
string strConnection = @"Data Source=.;Integrated Security=SSPI;Initial Catalog=s3cr3tx";
//SqlConnection sql = new SqlConnection(strConnection);
//SqlCommand command = new SqlCommand();
//command.CommandText = @"dbo.usp_tbl_member_sel_reg";
//command.CommandType = System.Data.CommandType.StoredProcedure;
//SqlParameter p1 = new SqlParameter(@"email", loginCurrent.member_email.Trim());
//command.Parameters.Add(p1);
//strResult = @"";
//using (sql)
//{
// sql.Open();
// command.Connection = sql;
// strResult = (string)command.ExecuteScalar();
//}
//if (!strResult.Equals(@""))
//{
// //valid user
// strResult = System.Convert.ToBase64String(System.Security.Cryptography.SHA512.HashData(System.Text.Encoding.Convert(System.Text.Encoding.GetEncoding(0), System.Text.Encoding.UTF8, System.Text.Encoding.GetEncoding(0).GetBytes(loginCurrent.member_code + strResult))));
//}
SqlConnection sql2 = new SqlConnection(strConnection);
SqlCommand command2 = new SqlCommand();
command2.CommandText = @"dbo.GetCode";
command2.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter p3 = new SqlParameter(@"email", loginCurrent.member_email.Trim());
//SqlParameter p4 = new SqlParameter(@"pword", strResult);
command2.Parameters.Add(p3);
//command2.Parameters.Add(p4);
string strResult1 = @"";
using (sql2)
{
sql2.Open();
command2.Connection = sql2;
strResult1 = (string)command2.ExecuteScalar();
}
string strCompare = Controllers.uspEncDec.Dec(@"support@s3cr3tx.com",strResult1);
//strCompare = strCompare.Replace(@"""",@"");
if (strResult1.Equals(@"") || !strCompare.Equals(loginCurrent.member_code))
{
loginCurrent.Output = @"The email or password you entered did not match our records";
return;
}
else
{
SqlConnection sql3 = new SqlConnection(strConnection);
SqlCommand command3 = new SqlCommand();
command3.CommandText = @"dbo.usp_tbl_member_sel_email";
command3.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter p5 = new SqlParameter(@"email", loginCurrent.member_email);
//SqlParameter p4 = new SqlParameter(@"member_code", strResult);
command3.Parameters.Add(p5);
//command2.Parameters.Add(p4);
DataSet dataSet = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
using (sql3)
{
sql3.Open();
command3.Connection = sql3;
da.SelectCommand = command3;
da.Fill(dataSet);
}
//create member object
Member member = new Member()
{
id = (long)dataSet.Tables[0].Rows[0].ItemArray[0],
email = dataSet.Tables[0].Rows[0].ItemArray[1].ToString(),
Code = dataSet.Tables[0].Rows[0].ItemArray[2].ToString(),
ConfirmCode = @"",
FirstName = dataSet.Tables[0].Rows[0].ItemArray[3].ToString(),
LastName = dataSet.Tables[0].Rows[0].ItemArray[4].ToString(),
regcode = dataSet.Tables[0].Rows[0].ItemArray[5].ToString(),
created = (DateTime)dataSet.Tables[0].Rows[0].ItemArray[6],
updated = (DateTime)dataSet.Tables[0].Rows[0].ItemArray[7],
enabled = (bool)dataSet.Tables[0].Rows[0].ItemArray[8],
confirmed = (bool)dataSet.Tables[0].Rows[0].ItemArray[9],
country = dataSet.Tables[0].Rows[0].ItemArray[10].ToString(),
state = dataSet.Tables[0].Rows[0].ItemArray[11].ToString(),
gender = dataSet.Tables[0].Rows[0].ItemArray[12].ToString(),
mobile = dataSet.Tables[0].Rows[0].ItemArray[13].ToString(),
MobileCarrier = dataSet.Tables[0].Rows[0].ItemArray[14].ToString(),
city = dataSet.Tables[0].Rows[0].ItemArray[15].ToString(),
zipcode = dataSet.Tables[0].Rows[0].ItemArray[16].ToString(),
address = dataSet.Tables[0].Rows[0].ItemArray[17].ToString(),
address2 = dataSet.Tables[0].Rows[0].ItemArray[18].ToString()
};
string strIP = @"";
if (HttpContext.Connection.RemoteIpAddress is not null)
{
IPAddress iP = HttpContext.Connection.RemoteIpAddress;
strIP = iP.ToString();
}
//create member session and member objects
MemberSession ms = new MemberSession()
{
member_id = member.id,
member_email = member.email,
FirstName = member.FirstName,
LastName = member.LastName,
IsActive = true,
member_ip = strIP
};
//Store Session Info:
SqlConnection sql4 = new SqlConnection(strConnection);
SqlCommand command4 = new SqlCommand();
command4.CommandText = @"dbo.usp_tbl_member_sessions_ups";
command4.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter p70 = new SqlParameter(@"member_id", ms.member_id);
SqlParameter p71 = new SqlParameter(@"member_email", ms.member_email);
SqlParameter p72 = new SqlParameter(@"member_token", ms.member_token);
SqlParameter p73 = new SqlParameter(@"member_name", ms.FirstName + @" " + ms.LastName);
SqlParameter p74 = new SqlParameter(@"session_start", ms.session_start);
SqlParameter p75 = new SqlParameter(@"session_active", true);
SqlParameter p76 = new SqlParameter(@"session_last_active", ms.LastActive);
SqlParameter p77 = new SqlParameter(@"session_end", ms.SessionExpires);
SqlParameter p78 = new SqlParameter(@"member_ip", ms.member_ip);
command4.Parameters.Add(p70);
command4.Parameters.Add(p71);
command4.Parameters.Add(p72);
command4.Parameters.Add(p73);
command4.Parameters.Add(p74);
command4.Parameters.Add(p75);
command4.Parameters.Add(p76);
command4.Parameters.Add(p77);
command4.Parameters.Add(p78);
long lngResult4 = 0;
using (sql4)
{
sql4.Open();
command4.Connection = sql4;
lngResult4 = (long)command4.ExecuteScalar();
}
if (lngResult4.Equals(0))
{
loginCurrent.Output = @"Something went wrong.";
return;
}
else
{
ms.id = lngResult4;
//redirect to index
//put a cookie in the cookie jar
string strCookieContent = Controllers.uspEncDec.Enc(@"pmkelly2@icloud.com", ms.member_token);
//var resp = new HttpResponseMessage();
//var cookie = new CookieHeaderValue("session-id", strCookieContent);
//cookie.Expires = DateTimeOffset.Now.AddDays(1);
//cookie.Domain = Request.RequestUri.Host;
//cookie.Path = "/";
//resp.Headers.AddCookies(new CookieHeaderValue[] { cookie });
// Response.m;
Response.Cookies.Delete(@"s3cr3tx");
Response.Cookies.Append(@"s3cr3tx", strCookieContent, new CookieOptions()
{
Secure = true,
HttpOnly = true,
//Domain = @"s3cr3tx.com",
Expires = DateTime.Now.AddYears(1),
//SameSite = SameSiteMode.Strict,
IsEssential = true
});
// Response.WriteAsync(@"Login Success");
// Response.Cookies.
Response.Redirect(@"https://s3cr3tx.com/");
}
}
}
}
}
catch (Exception ex)
{
string strSource = @"s3cr3tx.api.RegisterPageCS.OnGet";
s3cr3tx.Controllers.ValuesController.LogIt(ex.GetBaseException().ToString(), strSource);
}
}
}
}