コード例 #1
0
        public int ValidateEmailAndSendCode(string emailId)
        {
            var expiredOn    = Convert.ToInt32(ConfigurationManager.AppSettings["ExpiredValue"]);
            var isEmailExist = _accessTokenRepository.ValidEmail(emailId);

            if (!isEmailExist)
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Emailadressen finns inte.");
            }

            var user        = _accessTokenRepository.GetUserByEmail(emailId);
            var recoverCode = new RecoveryCode();

            recoverCode.UserId      = user.Id;
            recoverCode.Email       = user.Email;
            recoverCode.RecoverCode = _cryptoGraphy.GenerateCode();
            recoverCode.ExpiredOn   = DateTime.Now.AddMinutes(expiredOn);

            var recoveryCode = RecoveryCodeMapper(recoverCode);

            _accessTokenRepository.CreateNewRecoverCode(recoveryCode);
            var fields = new StringDictionary
            {
                { "Name", user.Email },
                { "RecoveryCode", recoveryCode.RecoveryCode },
                { "ExpiredOn", Convert.ToString(expiredOn) }
            };
            var htmlBody = _fm.ReadFileContents(GetMailerTemplatePath("html", "RecoveryCode")).ReplaceMatch(fields);

            _emailNotifier.SendEmail(emailId, htmlBody, "Recovery Code");
            var minutes = (expiredOn * 60) / 60;

            return(minutes);
        }