Ejemplo n.º 1
0
        public Operation <ContextVerification> CreateVerificationObject(string userId, string verificationContext, DateTime?expiryDate)
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var user         = _query.GetUserById(userId).ThrowIfNull("user not found");
            var _cv          = new ContextVerification();
            var cvexpiration = _settings.GetSetting(Constants.Settings_DefaultContextVerificationExpirationTime)
                               .Resolve()
                               .ParseData <TimeSpan>();
            _cv.Context           = verificationContext;
            _cv.ExpiresOn         = expiryDate ?? (DateTime.Now + cvexpiration);
            _cv.Target            = user;
            _cv.VerificationToken = GenerateToken();
            _cv.Verified          = false;

            return(_pcommand.Add(_cv));
        });
Ejemplo n.º 2
0
        public Operation RequestCredentialReset(CredentialMetadata metadata, string targetUser)
        => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () =>
        {
            var user = _query.GetUserById(targetUser);
            if (user.Status != (int)AccountStatus.Active)
            {
                throw new Exception("invalid account state");
            }

            var verification = _query.GetLatestContextVerification(user, Constants.VerificationContext_CredentialReset);

            //if no unverified context still exists in the db, create a new one
            if (verification == null || verification.Verified || verification.ExpiresOn <= DateTime.Now)
            {
                var expiry = _settingsManager.GetSetting(Constants.Settings_DefaultContextVerificationExpirationTime)
                             .Resolve()
                             .ParseData <TimeSpan>();
                verification = new ContextVerification
                {
                    Context           = Constants.VerificationContext_CredentialReset,
                    Target            = user,
                    ExpiresOn         = DateTime.Now + expiry,
                    VerificationToken = RandomAlphaNumericGenerator.RandomAlphaNumeric(50)
                };

                _pcommand.Add(verification).Resolve();
            }

            return(_backgroundProcessor.EnqueueOperation <IEmailPush>(_mp => _mp.SendMail(new AccountActivation
            {
                From = "*****@*****.**",
                Subject = "Password Reset",
                Target = user.UserId,
                Link = _apiProvider.GeneratePasswordUpdateVerificationUrl(verification.VerificationToken, targetUser).Result,
                LogoUrl = _apiProvider.LogoUri().Result,
                LogoTextUrl = _apiProvider.LogoTextUri().Result
            }))
                   .Then(opr => { }));
        });