-
Notifications
You must be signed in to change notification settings - Fork 0
/
Forgot.cshtml.cs
249 lines (237 loc) · 13.9 KB
/
Forgot.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
247
248
249
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using s3cr3tx.Models;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Web;
using System.Net;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using System.Net.Mail;
//using Microsoft.Data.SqlClient;
namespace s3cr3tx.Pages
{
//[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ForgotModel : PageModel
{
public string _message = @"";
//private readonly ILogger<ForgotModel> _logger;
public s3cr3tx.Models.Forgot forgotCurrent;
public s3cr3tx.Models.ForgotDbContext ForgotContext;
public string _output;
public ForgotModel(s3cr3tx.Models.ForgotDbContext forgotDbContext)
{
ForgotContext = forgotDbContext;
forgotCurrent = new Forgot();
}
public void OnPostView()
{
try
{
HttpRequest Request = HttpContext.Request;
if (Request.Form.TryGetValue("forgotCurrent.member_email", out Microsoft.Extensions.Primitives.StringValues Email))
{
forgotCurrent.member_email = Email[0].ToLower();
string strConnection = @"Data Source=.;Integrated Security=SSPI;Initial Catalog=s3cr3tx";
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", forgotCurrent.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);
}
if (dataSet.Tables.Count >0)
{
//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();
}
if (member.confirmed.Equals(true) && (member.enabled.Equals(true)))
{
//store the forgot data
SqlConnection sql4 = new SqlConnection(strConnection);
SqlCommand command4 = new SqlCommand();
command4.CommandText = @"dbo.usp_tbl_forgot_ins";
command4.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter p73 = new SqlParameter(@"member_id", member.id);
SqlParameter p71 = new SqlParameter(@"member_email", member.email);
SqlParameter p72 = new SqlParameter(@"member_token", forgotCurrent.member_code);
SqlParameter p74 = new SqlParameter(@"session_start", forgotCurrent.session_start);
SqlParameter p77 = new SqlParameter(@"session_end", forgotCurrent.code_expires);
SqlParameter p78 = new SqlParameter(@"member_ip", strIP);
command4.Parameters.Add(p71);
command4.Parameters.Add(p73);
command4.Parameters.Add(p72);
command4.Parameters.Add(p74);
command4.Parameters.Add(p77);
command4.Parameters.Add(p78);
int lngResult4 ;
using (sql4)
{
sql4.Open();
command4.Connection = sql4;
lngResult4 = (int)command4.ExecuteNonQuery();
}
if (lngResult4.Equals(0))
{
forgotCurrent.Output = @"Something went wrong.";
return;
}
else
{
Member _member = new Member();
MailMessage mail = new MailMessage();
mail.From = new MailAddress(@"support@s3cr3tx.com");
mail.Sender = new MailAddress(@"support@s3cr3tx.com");
mail.Subject = @"s3cr3tx account verification";
mail.To.Add(new MailAddress(forgotCurrent.member_email));
mail.IsBodyHtml = true;
mail.Body = @"Dear " + member.FirstName + @",<br/><br/>Please click the following link to reset your password: <a href='https://s3cr3tx.com/Freset?=" + System.Web.HttpUtility.UrlEncode(forgotCurrent.member_email) + @"_" + forgotCurrent.member_code + "'>https://s3cr3tx.com/Freset?=" + System.Web.HttpUtility.UrlEncode(forgotCurrent.member_email) + @"_" + forgotCurrent.member_code + @"</a><br/><br/>For your account protection, the link will only be active for 20 minutes. <br/><br/>Thank you!<br/><br/>s3cr3tx support@s3cr3tx.com";
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Host = GetS3cr3txD(@"SD8d/1ZiIFiNWRiGUYbXbt6fdtOppU3KOipsr5zGlY+Wk/VyHYiOMynMhwvZgv94Xkkewc0ZW7CW/zJ14JaTfLdNDGzeoHTV+Ae/SpTIsmZkLvMX9nkA/HY7F6PzlP96+5gfQkaWufkLEZ19KwdkhOpwJDTUgEOBOZ4LxCH5tQ0ZwrXhH8pHII2mlNkV+zQQAfPjJvBUiiSyk3UoMTw8NZBfYhi9xmFbgkNbFjKO4XUXTxhcFXcikepf80hWwEdZx7ZUKs+mT8us/boGgXvzolyjQZEqBI4+4XeMZ5N5DbBqMWNCy0Fu9kz11ncz+wJUJmOxorYnecPhMuu22AYR0M3tiW65Pb2i9cyzp52pqhCrSpfs7IOlLEmlfZWFINWYXoTvk3MfzgQKH7qYrTxfLoY8uUnQTJIxIR5Lacwab/F90bhtAqyxFwTFTI3zl+czXpw1JxQXcD+Uaq6XggkQcxq1OgdsmCSDAF6Wmu9iEjDxUbAG2A2vbXGE/N6xkGsU7s89PR7jdgdLk6ITFx7QLEt4hehStKLP/NetljEJevz7rgMVWsiwTELhZHqfZjxw/W3w/AR7Pnt3seVJbpPhy9zOXGF0va0BqWdcnPa1fp0Uo9NV6Oqnxf04vexg1E6mXQQGUpWdGbVIxWrz3JkwdUgxh/ooVwZcmpMxmo1Pil0=");
smtp.Credentials = new NetworkCredential(GetS3cr3txD(@"V4r2dhIxgnJx6395snHcuvuorVqc+UDasFhCZmgshLxQir9VV3pasUtRwJxd186dSNwbNq4WMt0hb+KOpKBsmNoblLOdY8+hZJpG5vislfztBfh2vWt51CdQApCxxym7Jx8Qx8HfACKNiw02RVjW5Rokv/M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9w5/acIXMZC1x6fpWSVrLMk2x63sHYvdb96h/d/Oi1SvaOGT7XD6erRThf0rhGUoCKgohTsRIn60z9Bd7O++nNbIcs/FZKcDTB7gnXj+xAoArZbOfE7vevfmEI="));
smtp.Port = 587;
smtp.Send(mail);
//_member.message = strResult;
_output = @"Please check your email for password reset instructions.";
//Response.Redirect(@"https://s3cr3tx.com/Login");
}
}
else
{
_output = @"Please check for an email from us to confirm your account or contact us at support@s3cr3tx.com";
}
}
else
{
_output = @"Something went wrong please contact us at support@s3cr3tx.com";
}
}
else
{
_output = @"Something went wrong please contact us at support@s3cr3tx.com";
}
}
catch (Exception ex)
{
//string strResult = @"";
string strSource = @"s3cr3tx.api.ConfirmPage.OnGet";
s3cr3tx.Controllers.ValuesController.LogIt(ex.GetBaseException().ToString(), strSource);
Redirect(@"https://s3cr3tx.com/Login");
}
}
private string GetS3cr3txD(string strS3cr3tx)
{
try {
string strEmail = @"support@s3cr3tx.com";
string strAuth = @"bMOgesKqUER7w6I5w79Ewo/DrMK3w7vCsMW4BMWhYz8p4oCd4oC6woFvNsOcw49PwqnCrBRRxb49IuKAmWvCoTbDqcK24oCwc+KAsEMZAFZIw7HDiR3CsjJsfQZbw4HDpcOLy4Y=";
string strCode = @"wq/DisON4oCaPcOXw7k3UFlCwo3DrcOvQ8KtInYTw57CtHLDm8K5AcuGSQp/WnLigJ0sSMODwqHDlhsVw6EnThYUwp3Conx0xb5vw77igKYyW1zFk1vCqFw6w5HDv8K1Dw==";
WebClient wc = new WebClient();
wc.BaseAddress = @"https://s3cr3tx.com/Values";
WebHeaderCollection webHeader = new WebHeaderCollection();
webHeader.Add(@"Email:" + strEmail);
webHeader.Add(@"AuthCode:" + strCode);
webHeader.Add(@"APIToken:" + strAuth);
webHeader.Add(@"Input:" + strS3cr3tx);
webHeader.Add(@"EorD:" + @"d");
webHeader.Add(@"Def:" + @"z");
wc.Headers = webHeader;
string result = @"";
result = wc.DownloadString(@"https://s3cr3tx.com/Values");
return result;
}
catch (Exception ex)
{
//string strResult = @"";
string strSource = @"s3cr3tx.api.ConfirmPage.OnGet";
s3cr3tx.Controllers.ValuesController.LogIt(ex.GetBaseException().ToString(), strSource);
Redirect(@"https://s3cr3tx.com/Login");
return @"";
}
}
public class NewK
{
[Required]
public string email { get; set; }
[Required]
public string pd { get; set; }
[Required]
public string pd2 { get; set; }
}
private string CreateBundle(string strEmail)
{
try {
NewK newK = new NewK();
newK.pd = @"1";
newK.pd2 = @"1";
newK.email = strEmail;
WebClient wc = new WebClient();
//wc.Credentials.GetCredential();
wc.BaseAddress = @"https://s3cr3tx.com/Values";
WebHeaderCollection webHeader = new WebHeaderCollection();
wc.Headers = webHeader;
string result = @"";
webHeader.Add(@"content-type:application/json");
NewK nk = new NewK();
nk.email = strEmail;
nk.pd = @"1";
nk.pd2 = @"1";
string strNk = JsonSerializer.Serialize<NewK>(nk);
result = wc.UploadString(@"https://s3cr3tx.com/Values", strNk);
return result;
}
catch (Exception ex)
{
//string strResult = @"";
string strSource = @"s3cr3tx.api.ConfirmPage.OnGet";
s3cr3tx.Controllers.ValuesController.LogIt(ex.GetBaseException().ToString(), strSource);
Redirect(@"https://s3cr3tx.com/Login");
return @"";
}
}
}
}