コード例 #1
0
ファイル: EmailService.cs プロジェクト: hmnzr/SCMS
        public Email CreateVerificationEmail(User user, VerificationToken token)
        {
            var urlHelper = new UrlHelper();
            var validateActionUrl = urlHelper.Action("Verify", "Account", new { userId = user.Id, token = token.Value });
            var email = new Email()
            {
                To = user.Email,
                Subject = _applicationSettings.ApplicationName + ": " + Resources.Resources.EmailVerificationSubject,
                Body = ConfigureVerificationEmailBody(user.Name, validateActionUrl),

            };

            using (new UnitOfWork(EntitiesContext.Current))
            {
                var emailsRepository = _repositoryFactory.GetEmailsRepository();
                emailsRepository.Add(email);
            }

            return email;
        }
コード例 #2
0
ファイル: MembershipService.cs プロジェクト: hmnzr/SCMS
        public void StartEmailVerification(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            if (user.IsEmailVerified)
                return;

            if (String.IsNullOrWhiteSpace(user.Email))
                return;

            var now = DateTime.UtcNow;

            var tokensRepository = _repositoryFactory.GetVerificationTokensRepository();
            var token = tokensRepository.FirstOrDefault(t => t.UserId == user.Id && !t.IsRedeemed);
            if (token == null)
            {
                token = new VerificationToken()
                {
                    CreateDate = now,
                    TimeEdit = now,
                    IsRedeemed = false,
                    Value = (user.Email + user.Name + now.Ticks.ToString()).Sha256(Const.VerificationTokenSalt),
                    UserId = user.Id
                };

                using (new UnitOfWork(EntitiesContext.Current))
                {
                    tokensRepository.Add(token);
                }
            }

            var email = _emailService.CreateVerificationEmail(user, token);
            _emailService.QueryEmailSending(email);
        }