Пример #1
0
        private async Task <UserRegLoginResp> RegOrLogin(CodeLoginReq req, string apiUrl)
        {
            var stateRes = CheckLoginModelState(req);

            if (!stateRes.IsSuccess())
            {
                return(stateRes.ConvertToResultInherit <UserRegLoginResp>());
            }

            var loginRes = await RestApiUtil.PostCoreApi <UserRegLoginResp>(apiUrl, req);

            if (!loginRes.IsSuccess())
            {
                return(loginRes);
            }

            Response.Cookies.Append(GlobalKeysUtil.UserCookieName, loginRes.token,
                                    new CookieOptions()
            {
                HttpOnly = true, Expires = DateTimeOffset.Now.AddDays(30)
            });

            loginRes.return_url = Request.Cookies[GlobalKeysUtil.UserReturnUrlCookieName] ?? "/";
            return(loginRes);
        }
Пример #2
0
        public static async Task <ResultMo <UserInfoMo> > GetCurrentUser()
        {
            var user = CacheUtil.Get <UserInfoMo>(CacheKeysUtil.CurrentUserInfo);

            if (user != null)
            {
                return(new ResultMo <UserInfoMo>(user));
            }

            var userRes = await RestApiUtil.PostCoreApi <ResultMo <UserInfoMo> >("/member/GetCurrentUser");

            if (!userRes.IsSuccess())
            {
                return(userRes.ConvertToResult <UserInfoMo>());
            }

            CacheUtil.Set(CacheKeysUtil.CurrentUserInfo, userRes.data, TimeSpan.FromHours(CacheKeysUtil.CurrentUserInfoHours));

            return(userRes);
        }
Пример #3
0
        /// <summary>
        /// 授权回调接收
        /// </summary>
        /// <param name="plat"></param>
        /// <param name="code"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public async Task <IActionResult> receive(int plat, string code, string state)
        {
            var url     = string.Concat("/member/portal/socialauth?plat=", plat, "&code=", code, "&state=", state);
            var userRes = await RestApiUtil.PostCoreApi <UserRegLoginResp>(url);

            if (!userRes.IsSuccess())
            {
                return(Redirect(string.Concat("/un/error?ret=", userRes.ret, "&message=", userRes.msg)));
            }

            Response.Cookies.Append(GlobalKeysUtil.UserCookieName, userRes.token,
                                    new CookieOptions()
            {
                HttpOnly = true, Expires = DateTimeOffset.Now.AddDays(30)
            });

            if (userRes.user.status >= 0)
            {
                var returnUrl = Request.Cookies[GlobalKeysUtil.UserReturnUrlCookieName] ?? "/";
                return(Redirect(returnUrl));
            }
            return(Redirect(string.Concat(loginUrl, "?state=", userRes.user.status)));
        }