コード例 #1
0
        public ActionResult Login(string returnUrl)
        {
            var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName(Provider.SystemName, _services.StoreContext.CurrentStore.Id);

            if (processor == null || !processor.IsMethodActive(_externalAuthenticationSettings))
            {
                throw new SmartException("Twitter module cannot be loaded");
            }

            var viewModel = new LoginModel();

            TryUpdateModel(viewModel);

            var result = _oAuthProviderTwitterAuthorizer.Authorize(returnUrl);

            switch (result.AuthenticationStatus)
            {
            case OpenAuthenticationStatus.Error:
            {
                if (!result.Success)
                {
                    foreach (var error in result.Errors)
                    {
                        NotifyError(error);
                    }
                }

                return(new RedirectResult(Url.LogOn(returnUrl)));
            }

            case OpenAuthenticationStatus.AssociateOnLogon:
            {
                return(new RedirectResult(Url.LogOn(returnUrl)));
            }

            case OpenAuthenticationStatus.AutoRegisteredEmailValidation:
            {
                //result
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation }));
            }

            case OpenAuthenticationStatus.AutoRegisteredAdminApproval:
            {
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval }));
            }

            case OpenAuthenticationStatus.AutoRegisteredStandard:
            {
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard }));
            }

            default:
                break;
            }

            if (result.Result != null)
            {
                return(result.Result);
            }

            return(HttpContext.Request.IsAuthenticated ?
                   RedirectToReferrer(returnUrl, "~/") :
                   new RedirectResult(Url.LogOn(returnUrl)));
        }
        public ActionResult Login(string returnUrl)
        {
            var processor = _openAuthenticationService.LoadExternalAuthenticationMethodBySystemName("ExternalAuth.Twitter");

            if (processor == null ||
                !processor.IsMethodActive(_externalAuthenticationSettings) || !processor.PluginDescriptor.Installed)
            {
                throw new NopException("Twitter module cannot be loaded");
            }

            var viewModel = new LoginModel();

            TryUpdateModel(viewModel);

            var result = _oAuthProviderTwitterAuthorizer.Authorize(returnUrl);

            switch (result.AuthenticationStatus)
            {
            case OpenAuthenticationStatus.Error:
            {
                if (!result.Success)
                {
                    foreach (var error in result.Errors)
                    {
                        ExternalAuthorizerHelper.AddErrorsToDisplay(error);
                    }
                }

                return(new RedirectResult(Url.LogOn(returnUrl)));
            }

            case OpenAuthenticationStatus.AssociateOnLogon:
            {
                return(new RedirectResult(Url.LogOn(returnUrl)));
            }

            case OpenAuthenticationStatus.AutoRegisteredEmailValidation:
            {
                //result
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.EmailValidation }));
            }

            case OpenAuthenticationStatus.AutoRegisteredAdminApproval:
            {
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.AdminApproval }));
            }

            case OpenAuthenticationStatus.AutoRegisteredStandard:
            {
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Standard }));
            }

            default:
                break;
            }

            if (result.Result != null)
            {
                return(result.Result);
            }
            return(HttpContext.Request.IsAuthenticated ? new RedirectResult(!string.IsNullOrEmpty(returnUrl) ? returnUrl : "~/") : new RedirectResult(Url.LogOn(returnUrl)));
        }