Пример #1
0
 public AccountController(
     IAccountService accountService,
     SiteContext currentSite,
     IpAddressTracker ipAddressTracker,
     ISiteMessageEmailSender emailSender,
     SiteTimeZoneService timeZoneHelper,
     IIdentityServerIntegration identityServerIntegration,
     IStringLocalizer <CloudscribeCore> localizer,
     IRecaptchaKeysProvider recaptchaKeysProvider,
     IRecaptchaServerSideValidator recaptchaServerSideValidator,
     IHandleCustomRegistration customRegistration,
     IHandleAccountAnalytics analyticsHandler,
     ILogger <AccountController> logger
     )
 {
     AccountService            = accountService;
     CurrentSite               = currentSite;
     IdentityServerIntegration = identityServerIntegration;
     EmailSender               = emailSender;
     IpAddressTracker          = ipAddressTracker;
     StringLocalizer           = localizer;
     Log = logger;
     RecaptchaKeysProvider        = recaptchaKeysProvider;
     RecaptchaServerSideValidator = recaptchaServerSideValidator;
     TimeZoneHelper     = timeZoneHelper;
     CustomRegistration = customRegistration;
     Analytics          = analyticsHandler;
 }
Пример #2
0
        public virtual async Task <IActionResult> VerifyEmail(Guid userId)
        {
            var info = await AccountService.GetEmailVerificationInfo(userId);

            if (info.User == null)
            {
                return(this.RedirectToSiteRoot(CurrentSite));
            }

            if (info.User.EmailConfirmed)
            {
                return(this.RedirectToSiteRoot(CurrentSite));
            }

            var callbackUrl = Url.Action("ConfirmEmail", "Account",
                                         new { userId = info.User.Id.ToString(), code = info.EmailVerificationToken },
                                         protocol: HttpContext.Request.Scheme);

            EmailSender.SendAccountConfirmationEmailAsync(
                CurrentSite,
                info.User.Email,
                StringLocalizer["Confirm your account"],
                callbackUrl,
                info.EmailVerificationToken
                ).Forget();

            await IpAddressTracker.TackUserIpAddress(CurrentSite.Id, info.User.Id);

            return(RedirectToAction("EmailConfirmationRequired", new { userId = info.User.Id, didSend = true }));
        }
Пример #3
0
        protected async Task <IActionResult> HandleLoginSuccess(UserLoginResult result, string returnUrl)
        {
            Analytics.HandleLoginSuccess(result).Forget();

            if (result.User != null)
            {
                await IpAddressTracker.TackUserIpAddress(CurrentSite.Id, result.User.Id);
            }

            if (!string.IsNullOrEmpty(returnUrl))
            {
                // when site is closed login is still allowed
                // but don't redirect to closed paged
                if (
                    (!returnUrl.Contains("/closed")) &&
                    (!returnUrl.Contains("/oops/error")) &&
                    (!returnUrl.Contains("/account/logout"))
                    )
                {
                    return(LocalRedirect(returnUrl));
                }
            }

            return(this.RedirectToSiteRoot(CurrentSite));
        }
Пример #4
0
 public AccountController(
     IAccountService accountService,
     SiteContext currentSite,
     IpAddressTracker ipAddressTracker,
     ISiteMessageEmailSender emailSender,
     SiteTimeZoneService timeZoneHelper,
     ISmsSender smsSender,
     IIdentityServerIntegration identityServerIntegration,
     IStringLocalizer <CloudscribeCore> localizer,
     IRecaptchaKeysProvider recaptchaKeysProvider,
     IHandleCustomRegistration customRegistration,
     IHandleAccountAnalytics analyticsHandler,
     ILogger <AccountController> logger
     )
 {
     this.accountService = accountService;
     Site = currentSite;
     this.identityServerIntegration = identityServerIntegration;
     this.emailSender      = emailSender;
     this.smsSender        = smsSender;
     this.ipAddressTracker = ipAddressTracker;
     sr  = localizer;
     log = logger;
     this.recaptchaKeysProvider = recaptchaKeysProvider;
     this.timeZoneHelper        = timeZoneHelper;
     this.customRegistration    = customRegistration;
     analytics = analyticsHandler;
 }
Пример #5
0
        protected async Task <IActionResult> HandleLoginNotAllowed(UserLoginResult result, string returnUrl)
        {
            Analytics.HandleLoginNotAllowed(result).Forget();

            if (result.User != null)
            {
                await IpAddressTracker.TackUserIpAddress(CurrentSite.Id, result.User.Id);

                if (result.NeedsEmailConfirmation)
                {
                    if (ShouldSendConfirmation(result.User))
                    {
                        var callbackUrl = Url.Action(new UrlActionContext
                        {
                            Action     = "ConfirmEmail",
                            Controller = "Account",
                            Values     = new { userId = result.User.Id.ToString(), code = result.EmailConfirmationToken, returnUrl },
                            Protocol   = HttpContext.Request.Scheme
                        });

                        EmailSender.SendAccountConfirmationEmailAsync(
                            CurrentSite,
                            result.User.Email,
                            StringLocalizer["Confirm your account"],
                            callbackUrl,
                            result.EmailConfirmationToken
                            ).Forget();


                        this.AlertSuccess(StringLocalizer["Please check your email inbox, we just sent you a link that you need to click to confirm your account"], true);
                    }

                    return(RedirectToAction("EmailConfirmationRequired", new { userId = result.User.Id, didSend = true, returnUrl }));
                }

                if (result.NeedsAccountApproval)
                {
                    var timeSpan = DateTime.UtcNow - result.User.CreatedUtc;
                    if (timeSpan.TotalDays < 1)
                    {
                        // account was just created so send notification to approver
                        EmailSender.AccountPendingApprovalAdminNotification(CurrentSite, result.User).Forget();
                    }

                    return(RedirectToAction("PendingApproval", new { userId = result.User.Id, didSend = true }));
                }
            }

            return(this.RedirectToSiteRoot(CurrentSite));
        }
Пример #6
0
        protected async Task <IActionResult> HandleLockout(UserLoginResult result = null)
        {
            Analytics.HandleLockout(result).Forget();

            ViewData["Title"] = StringLocalizer["Locked out"];

            if (result != null && result.User != null)
            {
                await IpAddressTracker.TackUserIpAddress(CurrentSite.Id, result.User.Id);

                Log.LogWarning($"redirecting to lockout page for {result.User.Email} because account is locked");
            }

            return(View("Lockout"));
        }
Пример #7
0
        protected async Task <IActionResult> HandleRequiresTwoFactor(UserLoginResult result, string returnUrl, bool rememberMe)
        {
            Analytics.HandleRequiresTwoFactor(result).Forget();

            if (result.User != null)
            {
                await IpAddressTracker.TackUserIpAddress(CurrentSite.Id, result.User.Id);

                Log.LogWarning($"redirecting from login for {result.User.Email} because 2 factor not configured yet for account");
            }

            return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, rememberMe }));

            //return RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = rememberMe });
        }
Пример #8
0
 public AccountController(
     SiteSettings currentSite,
     SiteUserManager <SiteUser> userManager,
     SiteSignInManager <SiteUser> signInManager,
     IpAddressTracker ipAddressTracker,
     ISiteMessageEmailSender emailSender,
     ISmsSender smsSender,
     ILogger <AccountController> logger)
 {
     Site                  = currentSite;
     this.userManager      = userManager;
     this.signInManager    = signInManager;
     this.emailSender      = emailSender;
     this.smsSender        = smsSender;
     this.ipAddressTracker = ipAddressTracker;
     log = logger;
 }
Пример #9
0
 public AccountController(
     SiteContext currentSite,
     SiteUserManager <SiteUser> userManager,
     SiteSignInManager <SiteUser> signInManager,
     IpAddressTracker ipAddressTracker,
     ISiteMessageEmailSender emailSender,
     ISmsSender smsSender,
     IIdentityServerIntegration identityServerIntegration,
     IStringLocalizer <CloudscribeCore> localizer,
     ILogger <AccountController> logger
     )
 {
     Site                           = currentSite;
     this.userManager               = userManager;
     this.signInManager             = signInManager;
     this.identityServerIntegration = identityServerIntegration;
     this.emailSender               = emailSender;
     this.smsSender                 = smsSender;
     this.ipAddressTracker          = ipAddressTracker;
     sr  = localizer;
     log = logger;
 }