public ActionResult ChangePassword(string currentpassword, string newpassword, string retypedpassword) { if (string.IsNullOrEmpty(currentpassword) || string.IsNullOrEmpty(currentpassword) || string.IsNullOrEmpty(currentpassword)) { TempData["ErrorMessage"] = "All password fields must be filled to change the password."; } else { Guid accountGuid = Guid.Parse(this.CurrentUser.AccountName); OnionWalletEntities entities = new OnionWalletEntities(); OnionUser user = entities.OnionUsers.FirstOrDefault(x => x.GUID == accountGuid); if (user == null) { TempData["ErrorMessage"] = "A general error occured. Please contact support at " + ConfigurationManager.AppSettings["SiteEmail"].ToString() + "."; } else { if (!user.CheckPassword(currentpassword)) { TempData["ErrorMessage"] = "Current password does not match."; } else if (newpassword != retypedpassword) { TempData["ErrorMessage"] = "New passwords are not the same."; } else { user.SetPassword(newpassword); entities.SaveChanges(); TempData["SuccessMessage"] = "Password updated."; } } } return(RedirectToAction("Account", "Home")); }
public ActionResult Register(IndexModel data) { if (!ModelState.IsValid) { return(View(data)); } if (data.RegisterPassword != data.RegisterRepeatPassword) { TempData["ErrorMessage"] = "Passwords do not match."; TempData["RegisterEmail"] = data.RegisterEmail; return(RedirectToAction("Index")); } if (!data.RegisterAcceptTOS) { TempData["ErrorMessage"] = "Please accept terms of service."; TempData["RegisterEmail"] = data.RegisterEmail; return(RedirectToAction("Index")); } OnionWalletEntities entities = new OnionWalletEntities(); OnionUser existing = entities.OnionUsers.FirstOrDefault(x => x.Email == data.RegisterEmail.ToLower()); if (existing != null) { TempData["ErrorMessage"] = "Email already exists!"; TempData["RegisterEmail"] = data.RegisterEmail; return(RedirectToAction("Index")); } OnionUser user = new OnionUser(); user.InitGUIDs(); user.Email = data.RegisterEmail; user.SetPassword(data.RegisterPassword); user.IsMailing = data.RegisterIsMailing; user.OnionAddress = "gugus"; user.IsActive = true; user.CreateDate = DateTime.Now; entities.OnionUsers.Add(user); entities.SaveChanges(); string subject = "OnionWallet Email confirmation"; string body = "Hi" + Environment.NewLine + Environment.NewLine + "You have successfully created your Web OnionWallet on onionwallet.ch!" + Environment.NewLine + Environment.NewLine; body = body + "Please click the link below to activate your wallet:" + Environment.NewLine + Environment.NewLine; body = body + ConfigurationManager.AppSettings["BaseURL"].ToString() + "/mailconfirmation/" + user.EmailConfirmationGUID.ToString() + Environment.NewLine + Environment.NewLine; body = body + "Thanks and enjoy the Onion Party!"; new Thread(() => { OnionWalletEntities threadEntities = new OnionWalletEntities(); try { OnionUser threadUser = threadEntities.OnionUsers.FirstOrDefault(x => x.GUID == user.GUID); OnionHandler onionHandler = new OnionHandler(); threadUser.OnionAddress = onionHandler.CreateAccount(user.GUID.ToString()); threadEntities.SaveChanges(); } catch (Exception ex) { Log log = new Log(); log.CreateDate = DateTime.Now; log.Level = 1; log.Message = ex.Message; log.Type = (int)LogTypeEnum.Error; log.UserID = 0; threadEntities.Logs.Add(log); threadEntities.SaveChanges(); } }).Start(); new Thread(() => { try { GmailHandler.SendMail(user.Email, subject, body); } catch (Exception ex) { OnionWalletEntities threadEntities = new OnionWalletEntities(); Log log = new Log(); log.CreateDate = DateTime.Now; log.Level = 1; log.Message = ex.Message; log.Type = (int)LogTypeEnum.Error; log.UserID = 0; threadEntities.Logs.Add(log); threadEntities.SaveChanges(); } }).Start(); TempData["SuccessMessage"] = "Party ticket booked! Please click link in confirmation email and log in to access your wallet. Check your spam folder, if you can't find the email."; return(RedirectToAction("Index")); }