Beispiel #1
0
        public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            Response.Cookies.Add(
                new HttpCookie(_webLocalizationConfiguration.CookieName, cultureName)
            {
                Expires = Clock.Now.AddYears(2)
            }
                );

            if (AbpSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    AbpSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                    );
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && AbpUrlHelper.IsLocalUrl(Request.Url, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect(Request.ApplicationPath));
        }
Beispiel #2
0
        /// <summary>
        /// OAuthScope.snsapi_base方式回调
        /// </summary>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <param name="returnUrl">用户最初尝试进入的页面</param>
        /// <returns></returns>
        public async Task <IActionResult> BaseCallback(string code, string state, string returnUrl)
        {
            if (string.IsNullOrEmpty(code))
            {
                return(Content("您拒绝了授权!"));
            }

            //通过,用code换取access_token
            var appId = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.WechatAppId);

            var appSecret = await SettingManager.GetSettingValueAsync(AppSettings.TenantManagement.WechatAppSecret);

            var result = OAuthApi.GetAccessToken(appId, appSecret, code);

            if (result.errcode != ReturnCode.请求成功)
            {
                return(Content("错误:" + result.errmsg));
            }
            HttpContext.Session.SetString("WechatOpenId", result.openid);


            if (string.IsNullOrEmpty(returnUrl) || AbpUrlHelper.IsLocalUrl(Request, returnUrl))
            {
                return(Content($"认证成功: {result.openid},无权访问"));
            }

            // 查找绑定的用户,使用外部认证源登录流程


            return(Redirect(returnUrl));

            // 没有绑定用户,跳转到绑定页面

            return(RedirectToAction("Bind", new { returnUrl }));
        }
        public async Task <ActionResult> AgentLogin(long agentId, string returnUrl = "")
        {
            var loginId   = AbpSession.GetUserId();
            var userAgent = await _loginAgentRepository.FirstOrDefaultAsync(x => x.PrincipalId == loginId && x.AgentId == agentId);

            await SignInAsync(userAgent.Agent);

            if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && AbpUrlHelper.IsLocalUrl(Request.Url, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect(Request.ApplicationPath));
        }
Beispiel #4
0
        public async Task <IActionResult> Bind(WechatBindInput input)
        {
            var openId = HttpContext.Session.GetString("WechatOpenId");

            if (string.IsNullOrEmpty(openId))
            {
                return(Content("请从微信中访问"));
            }

            if (UseCaptchaOnRegistration())
            {
                RecaptchaValidator.Validate(input.Captcha);
            }

            var tenancyName = GetTenancyNameOrNull();

            var loginResult = await LogInManager.LoginAsync(input.UserNameOrEmail, input.Password, tenancyName);

            if (loginResult.Result != AbpLoginResultType.Success)
            {
                var exception =
                    AbpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result,
                                                                                  input.UserNameOrEmail, tenancyName);
                ViewData["Error"] = exception.Message;
                return(View(input));
            }

            // 绑定
            await _wechatService.BindAsync(new WechtLoginInput
            {
                UserId      = loginResult.User.Id,
                TenantId    = loginResult.Tenant.Id,
                ProviderKey = openId
            });

            await _signInManager.SignInAsync(loginResult.User, true);

            if (AbpUrlHelper.IsLocalUrl(Request, input.ReturnUrl))
            {
                return(Redirect(input.ReturnUrl));
            }
            return(Redirect("/"));
        }
        public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName));

            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                cookieValue,
                new CookieOptions
            {
                Expires  = Clock.Now.AddYears(2),
                HttpOnly = true
            }
                );

            if (AbpSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    AbpSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                    );
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new AjaxResponse()));
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && AbpUrlHelper.IsLocalUrl(Request, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect("/")); //TODO: Go to app root
        }
        public IActionResult Index(string returnUrl = "")
        {
            var islocal = AbpUrlHelper.IsLocalUrl(Request, returnUrl);

            return(View());
        }