Exemplo n.º 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);
        }
Exemplo n.º 2
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.RestCoreApi <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));
            }
            else
            {
                return(Redirect(string.Concat(loginUrl, "?state=", userRes.user.status)));
            }
        }
        public void Lookup()
        {
            var uriBuilder = new UriBuilder(_url);

            uriBuilder.Query = $"q={City}&units=metric&appid={_apiKey}";

            ResponseText = RestApiUtil.Get(uriBuilder.Uri);

            if (JsonUtil.IsValidJson(ResponseText))
            {
                ResponseData = JsonUtil.Deserialize <OpenWeatherMapData>(ResponseText);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 授权
        /// </summary>
        /// <param name="plat">平台(参见ThirdPaltforms) 10-微信  20-支付宝  30-新浪 </param>
        /// <param name="state">回调附带参数</param>
        /// <param name="type">授权客户端类型 1-pc端web, 2-应用内浏览器(如公众号) 4-应用内静默授权</param>
        /// <returns></returns>
        public async Task <IActionResult> auth(int plat, string state, int type)
        {
            var redirectUrl = $"{m_CurrentDomain}/oauth/receive/{plat}";
            var authUrl     = $"/sns/oauth/getoauthurl?plat={plat}&redirectUrl={redirectUrl}&state={state}&type={type}";

            var urlRes = await RestApiUtil.RestApi <ResultMo <string> >(authUrl, null, HttpMethod.Get);

            if (urlRes.IsSuccess())
            {
                return(Redirect(urlRes.data));
            }

            return(Content(urlRes.msg));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 public CourseFirstDialog(string plan)
 {
     plandetails  = plan;
     _restApiUtil = new RestApiUtil();
 }
Exemplo n.º 7
0
 public RootDialog()
 {
     _restApiUtil = new RestApiUtil();
 }
Exemplo n.º 8
0
 public DonationFirstDialog(string plan)
 {
     plandetails  = plan;
     _restApiUtil = new RestApiUtil();
 }