/// <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))); } }
private async Task <UserRegLoginResp> RegOrLogin(CodeLoginReq req, string apiUrl) { var stateRes = CheckLoginModelState(req); if (!stateRes.IsSuccess()) { return(stateRes.ConvertToResult <UserRegLoginResp>()); } var loginRes = await RestApiUtil.RestCoreApi <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); }
/// <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.RestCoreApi <ResultMo <string> >(authUrl, null, HttpMothed.GET); if (urlRes.IsSuccess()) { return(Redirect(urlRes.data)); } return(Content(urlRes.msg)); }
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.RestCoreApi <ResultMo <UserInfoMo> >("/member/GetCurrentUser"); if (!userRes.IsSuccess()) { return(userRes.ConvertToResultOnly <UserInfoMo>()); } CacheUtil.AddOrUpdate(CacheKeysUtil.CurrentUserInfo, userRes.data, TimeSpan.Zero, DateTime.Now.AddHours(CacheKeysUtil.CurrentUserInfoHours)); return(userRes); }