public static string CstCreateAcct(CstInfo newLoginDetails) { Code = PasswordCreation.GenerateCode(); Hashpwd = HashPassword.ComputeSha256Hash(Code); DateTime current = DateTime.Now; SqlCommand cmd = new SqlCommand(); SqlCommand cmdAct = new SqlCommand(); try { if (newLoginDetails.CstFName == "" || newLoginDetails.CstLName == "") { throw new Exception(); } if (newLoginDetails.CstEmail == "") { throw new Exception(); } if (!newLoginDetails.CstEmail.Contains("@gmail.com")) { throw new Exception(); } cmd.Parameters.Clear(); cmd.Connection = con; cmd.CommandText = @"INSERT INTO NewCstTable(cst_FirstName, cst_LastName, cst_Email, cst_Password, Created_acct_at) OUTPUT INSERTED.id_cst VALUES(@fname, @lname, @email, @token, @timestamp)"; cmd.Parameters.AddWithValue("@fname", newLoginDetails.CstFName); cmd.Parameters.AddWithValue("@lname", newLoginDetails.CstLName); cmd.Parameters.AddWithValue("@email", newLoginDetails.CstEmail); cmd.Parameters.AddWithValue("@token", Hashpwd); cmd.Parameters.AddWithValue("@timestamp", current); con.Open(); cstId = Convert.ToInt32(cmd.ExecuteScalar());//cmd.ExecuteNonQuery(); con.Close(); cmdAct.Parameters.Clear(); cmdAct.Connection = con; cmdAct.CommandText = string.Format("insert into AccountTable values(@acttype, @cstid, @actnum, @bal)"); cmdAct.Parameters.AddWithValue("@acttype", newLoginDetails.CstAcctType); cmdAct.Parameters.AddWithValue("@cstid", cstId); cmdAct.Parameters.AddWithValue("@actnum", PasswordCreation.GenerateAccount()); cmdAct.Parameters.AddWithValue("@bal", Convert.ToDouble(newLoginDetails.Balance)); con.Open(); cmdAct.ExecuteNonQuery(); try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(newLoginDetails.CstEmail); mail.Subject = "Cst Info"; mail.Body = $"Your Access code: {Code} \nUse your email {newLoginDetails.CstEmail} and access code to login"; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", Pwd); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } catch (Exception ex) { return($"CstFailed from inner catch msg sending why => {ex.Message}"); } return($"Customer sucessfull Signup => {cstId}"); } catch (Exception ex) { return($"CStFailed from catch why => {ex.Message}"); } finally { con.Close(); } }
//Admin signup public static string AdminSignUpDB(AdminInfo adminDetails) { AdminFname = adminDetails.AdminFName; AdminLname = adminDetails.AdminLName; AdminEmail = adminDetails.AdminEmail; Code = PasswordCreation.GenerateCode(); Hashpwd = HashPassword.ComputeSha256Hash(Code); DateTime current = DateTime.Now; SqlCommand cmd = new SqlCommand(); try { if (AdminFname == "" || AdminLname == "") { throw new Exception(); } if (AdminEmail == "") { throw new Exception(); } if (!AdminEmail.Contains("@gmail.com")) { throw new Exception(); } cmd.Parameters.Clear(); cmd.Connection = con; cmd.CommandText = @"INSERT INTO Admin(AdminFirstName, AdminLastName, AdminEmail, AdminToken, Created_at) VALUES(@fname, @lname, @email, @token, @timestamp)"; cmd.Parameters.AddWithValue("@fname", AdminFname); cmd.Parameters.AddWithValue("@lname", AdminLname); cmd.Parameters.AddWithValue("@email", AdminEmail); cmd.Parameters.AddWithValue("@token", Hashpwd); cmd.Parameters.AddWithValue("@timestamp", current); con.Open(); cmd.ExecuteNonQuery(); con.Close(); try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(AdminEmail); mail.Subject = "Admin Info"; mail.Body = $"Your Access code: {Code} \n Use email and access code to login"; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", Pwd); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } catch (Exception ex) { return($"Failed from inner catch msg sending why => {ex.Message}"); } return($"Sucessfull Signup"); } catch (Exception ex) { return($"Failed from catch why => {ex.Message}"); } }
public void RegisterClient([DataBind("client")] Client client, ulong homeRegion, [DataBind("regionSettings")] RegionSettings[] regionSettings, [DataBind("permissions")] UserPermission[] permissions, [DataBind("options")] AdditionalSettings options, [DataBind("payer")] Payer payer, uint?existingPayerId, [DataBind("supplier")] Supplier supplier, [DataBind("clientContacts")] Contact[] clientContacts, [DataBind("userContacts")] Contact[] userContacts, [DataBind("userPersons")] Person[] userPersons, string additionalEmailsForSendingCard, string comment) { PasswordCreation password = null; var fullName = client.FullName.Replace("№", "N").Trim(); var name = client.Name.Replace("№", "N").Trim(); var currentPayer = RegisterPayer(options, payer, existingPayerId, name, fullName); client = new Client(currentPayer, DbSession.Load <Region>(homeRegion)) { FullName = fullName, Name = name, MaskRegion = regionSettings.GetBrowseMask(), Registration = new RegistrationInfo(Admin), ContactGroupOwner = new ContactGroupOwner() }; Defaults.Apply(client); client.Settings.WorkRegionMask = client.MaskRegion; client.Settings.OrderRegionMask = regionSettings.GetOrderMask(); var user = new User(client); var address = new Address(); Account account = user.Accounting; BindObjectInstance(client.Settings, "client.Settings"); BindObjectInstance(user, "user"); BindObjectInstance(account, "account"); SetARDataBinder(AutoLoadBehavior.NullIfInvalidKey); BindObjectInstance(address, "address"); var equalClientInRegion = DbSession.QueryOver <Client>().Where(c => c.HomeRegion.Id == homeRegion && c.Name == name).RowCount() > 0; var forValidation = new List <object> { client }; if (!options.RegisterEmpty) { forValidation.Add(user); client.AddUser(user); } if (!IsValid(forValidation) || equalClientInRegion) { DbSession.Delete(currentPayer); RegisterClient(); PropertyBag["clientContacts"] = clientContacts; PropertyBag["client"] = client; PropertyBag["user"] = user; PropertyBag["address"] = address; PropertyBag["options"] = options; PropertyBag["account"] = account; if (equalClientInRegion) { Error(string.Format("В данном регионе уже существует клиент с таким именем {0}", name)); } return; } if (String.IsNullOrEmpty(address.Value) || options.RegisterEmpty) { address = null; } if (options.RegisterEmpty) { user = null; } if (address != null) { address.Value = address.Value.Replace("№", "N").Trim(); client.AddAddress(address); } CreateDrugstore(client, options, supplier); AddContacts(client.ContactGroupOwner, clientContacts); if (user != null) { CreateUser(user, permissions, userPersons); user.UpdateContacts(userContacts); user.RegistredWith(client.Addresses.LastOrDefault()); password = user.CreateInAd(Session); var log = new PasswordChangeLogEntity(user.Login); if (options.SendRegistrationCard) { log = SendRegistrationCard(log, user, password.Password, additionalEmailsForSendingCard); } string smsLog = ""; if (options.SendSmsToUser) { var phonesForSendToUserArray = user.GetPhonesForSendingSms().Select(x => x.Number).ToArray(); smsLog = smsLog + " " + ReportHelper.SendSmsPasswordToUser(user, password.Password, phonesForSendToUserArray); } if (options.SendSmsToAdmin) { var phonesForSendToAdminArray = GetPhoneSupportByRegionForSms(user.RootService.HomeRegion.Id); smsLog = smsLog + " " + ReportHelper.SendSmsToRegionalAdmin(user, password.Password, phonesForSendToAdminArray); } log.SmsLog = smsLog; DbSession.Save(log); } client.Addresses.Each(a => a.CreateFtpDirectory()); client.AddBillingComment(comment); new Mailer(DbSession).ClientRegistred(client, comment, Defaults); if (!options.FillBillingInfo) { Mail().NotifyBillingAboutClientRegistration(client); } if (options.FillBillingInfo) { Redirect("Register", "RegisterPayer", new { id = client.Payers.Single().Id, showRegistrationCard = options.ShowRegistrationCard, passwordId = password != null ? password.PasswordId : "" }); } else if (client.Users.Count > 0 && options.ShowRegistrationCard) { Redirect("main", "report", new { id = client.Users.First().Id, passwordId = password.PasswordId }); } else { Notify("Регистрация завершена успешно"); RedirectTo(client); } }