示例#1
0
        public int ValidateWebEmailAndSendCode(string emailId)
        {
            var expiredOn    = Convert.ToInt32(ConfigurationManager.AppSettings["ExpiredValue"]);
            var isEmailExist = _accessTokenRepository.ValidWebEmail(emailId);

            if (!isEmailExist)
            {
                throw new Exception("Emailadressen finns inte.");
            }

            var webUser            = _accessTokenRepository.GetWebUserByEmail(emailId);
            var webUserRecoverCode = new WebUserRecoveryCode
            {
                WebUserId    = webUser.Id,
                RecoveryCode = _cryptoGraphy.GenerateCode(),
                ExpiredOn    = DateTime.Now.AddMinutes(expiredOn)
            };

            _accessTokenRepository.CreateNewWebUserRecoverCode(webUserRecoverCode);
            var fields = new StringDictionary
            {
                { "name", webUser.Name },
                { "RecoveryCode", webUserRecoverCode.RecoveryCode },
                { "ExpiredOn", expiredOn.ToString() }
            };
            var htmlBody = _fm.ReadFileContents(GetMailerTemplatePath("html", "RecoveryCode")).ReplaceMatch(fields);

            _emailNotifier.SendEmail(webUser.Email, htmlBody, "Återställningskod");
            var minutes = (expiredOn * 60) / 60;

            return(minutes);
        }