/// <summary> /// sends an expiring login link /// </summary> /// <param name="email"></param> /// <returns>success</returns> public bool SendPasswordReset(string email) { using (ManBoxEntities ent = new ManBoxEntities()) { var user = ent.Users.FirstOrDefault(u => u.Email == email); if (user == null) { this.logger.Log(LogType.Warn, "Password reset attempt without valid email. Too many attempts is fishy."); return(false); } var encryptedToken = HttpUtility.UrlEncode(TokenEncrypt.EncryptTokenAsExpiring(user.Subscriptions.First().Token, DateTime.Now.AddDays(1))); var fromRecipient = new MailRecipient("*****@*****.**", "Support ManBox"); var toRecipient = new MailRecipient(email, user.FirstName); var domain = Utilities.GetCountryDomain(user.Country.IsoCode); var linkToken = string.Format("http://{0}/{1}/Account/TokenLogin?token={2}", domain, user.Language.IsoCode, encryptedToken); mailService.SendMail <PasswordResetMail>(toRecipient, fromRecipient, new PasswordResetMail() { RootUrl = "http://" + domain, LanguageIso = user.Language.IsoCode, Date = DateTime.Now, Name = user.FirstName, Subject = "Password Reset", LinkToken = linkToken }); return(true); } }
public UserViewModel TokenLogin(string encryptedToken) { var subscrToken = TokenEncrypt.DecryptExpiringToken(encryptedToken); if (string.IsNullOrEmpty(subscrToken)) { return(null); } using (ManBoxEntities ent = new ManBoxEntities()) { var sub = ent.Subscriptions.Single(s => s.Token == subscrToken); if (sub == null) { throw new Exception("Could not find subscription for token login"); } return(new UserViewModel() { Email = sub.User.Email, Token = subscrToken, FirstName = sub.User.Email, LastName = sub.User.Email, UserId = sub.User.UserId, }); } }
private void SendMail(UpcomingBoxNotificationMail notificationMail) { var domain = Utilities.GetCountryDomain(notificationMail.CountryIso); var toEmail = new MailRecipient(notificationMail.Email, notificationMail.Name); var fromEmail = new MailRecipient("thibaut@" + domain, "ManBox"); notificationMail.Subject = UITexts.ResourceManager.GetString("UpcomingBoxNotificationMailSubject", new System.Globalization.CultureInfo(notificationMail.LanguageIso)); var encryptedToken = HttpUtility.UrlEncode(TokenEncrypt.EncryptTokenAsExpiring(notificationMail.Token, DateTime.Now.AddDays(1))); notificationMail.LinkToken = string.Format("http://{0}/{1}/Account/TokenLogin?token={2}", domain, notificationMail.LanguageIso, encryptedToken); mailService.SendMail <UpcomingBoxNotificationMail>(toEmail, fromEmail, notificationMail); }