public CustomJsonResult Login(RopLogin rop) { RetLogin ret = new RetLogin(); var result = AdminServiceFactory.AuthorizeRelay.SignIn(rop.UserName, rop.Password, CommonUtil.GetIP(), Enumeration.LoginType.Website); if (result.ResultType == Enumeration.LoginResult.Failure) { if (result.ResultTip == Enumeration.LoginResultTip.UserNotExist || result.ResultTip == Enumeration.LoginResultTip.UserPasswordIncorrect) { return(Json(ResultType.Failure, ret, "用户名或密码不正确")); } if (result.ResultTip == Enumeration.LoginResultTip.UserDisabled) { return(Json(ResultType.Failure, ret, "账户被禁用")); } if (result.ResultTip == Enumeration.LoginResultTip.UserDeleted) { return(Json(ResultType.Failure, ret, "账户被删除")); } } string key = GuidUtil.New(); UserInfo userInfo = new UserInfo(); userInfo.UserId = result.User.Id; userInfo.UserName = result.User.UserName; SSOUtil.SetUserInfo(key, userInfo); Response.Cookies.Add(new HttpCookie(OwnRequest.SESSION_NAME, key)); ret.Url = rop.ReturnUrl; return(Json(ResultType.Success, ret, "登录成功")); }
public RedirectResult Oauth2() { try { var request = Request; var code = request.QueryString["code"]; var returnUrl = request.QueryString["returnUrl"]; LogUtil.Info("returnUrl=>" + (returnUrl == null ? "" : returnUrl.ToString())); if (string.IsNullOrEmpty(code)) { var url = SdkFactory.Wx.Instance().GetAuthorizeUrl(returnUrl); LogUtil.Info("待跳转路径2:" + url); return(Redirect(url)); } else { var oauth2_Result = SdkFactory.Wx.Instance().GetWebOauth2AccessToken(code); if (oauth2_Result.errcode == null) { LogUtil.Info("用户OpenId:" + oauth2_Result.openid); LogUtil.Info("用户AccessToken:" + oauth2_Result.access_token); var snsUserInfo_Result = SdkFactory.Wx.Instance().GetUserInfoByOAuth2Token(oauth2_Result.access_token, oauth2_Result.openid); WxUserInfo wxUserInfo = new WxUserInfo(); wxUserInfo.AccessToken = oauth2_Result.access_token; wxUserInfo.OpenId = oauth2_Result.openid; wxUserInfo.ExpiresIn = DateTime.Now.AddSeconds(oauth2_Result.expires_in); wxUserInfo.Nickname = snsUserInfo_Result.nickname; wxUserInfo.Sex = snsUserInfo_Result.sex; wxUserInfo.Province = snsUserInfo_Result.province; wxUserInfo.City = snsUserInfo_Result.city; wxUserInfo.Country = snsUserInfo_Result.country; wxUserInfo.HeadImgUrl = snsUserInfo_Result.headimgurl; wxUserInfo.UnionId = snsUserInfo_Result.unionid; wxUserInfo = BizFactory.WxUser.CheckedUser(GuidUtil.New(), wxUserInfo); if (wxUserInfo != null) { LogUtil.Info("用户Id:" + wxUserInfo.ClientId); string key = GuidUtil.New(); UserInfo userInfo = new UserInfo(); userInfo.UserId = wxUserInfo.ClientId; userInfo.WxOpenId = oauth2_Result.openid; userInfo.WxAccessToken = oauth2_Result.access_token; SSOUtil.SetUserInfo(key, userInfo); Response.Cookies.Add(new HttpCookie(OwnRequest.SESSION_NAME, key)); LogUtil.Info("returnUrl.UrlDecode 前:" + returnUrl); string s_returnUrl = HttpUtility.UrlDecode(returnUrl); LogUtil.Info("returnUrl.UrlDecode 后:" + s_returnUrl); s_returnUrl = s_returnUrl.Replace("|", "&"); LogUtil.Info("returnUrl.UrlDecode 替换|,&:" + s_returnUrl); LogUtil.Info("returnUrl 最后返回:" + s_returnUrl); if (!string.IsNullOrEmpty(s_returnUrl)) { return(Redirect(s_returnUrl)); } } LogUtil.Info("用户跳进主页"); return(Redirect("/Home/Index")); } } } catch (Exception ex) { LogUtil.Error("微信Oauth2授权验证发生异常", ex); } return(Redirect("/Home/Oauth2")); }
public CustomJsonResult Login(LoginModel model) { GoToViewModel gotoViewModel = new GoToViewModel(); var result = SysFactory.AuthorizeRelay.SignIn(model.UserName, model.Password, CommonUtils.GetIP(), Enumeration.LoginType.Website); if (result.ResultType == Enumeration.LoginResult.Failure) { if (result.ResultTip == Enumeration.LoginResultTip.UserNotExist || result.ResultTip == Enumeration.LoginResultTip.UserPasswordIncorrect) { return(Json(ResultType.Failure, gotoViewModel, "用户名或密码不正确")); } if (result.ResultTip == Enumeration.LoginResultTip.UserDisabled) { return(Json(ResultType.Failure, gotoViewModel, "账户被禁用")); } if (result.ResultTip == Enumeration.LoginResultTip.UserDeleted) { return(Json(ResultType.Failure, gotoViewModel, "账户被删除")); } } string host = ""; string returnUrl = ""; switch (result.User.Type) { case Enumeration.UserType.Staff: host = System.Configuration.ConfigurationManager.AppSettings["custom:WebBackUrl"]; //returnUrl = string.Format("{0}?returnUrl={1}", host, model.ReturnUrl); returnUrl = string.Format("{0}", host); break; case Enumeration.UserType.Client: break; case Enumeration.UserType.Agent: host = System.Configuration.ConfigurationManager.AppSettings["custom:WebAgentUrl"]; //returnUrl = string.Format("{0}?returnUrl={1}", host, model.ReturnUrl); returnUrl = string.Format("{0}", host); break; case Enumeration.UserType.Salesman: break; } UserInfo userInfo = new UserInfo(); userInfo.UserId = result.User.Id; userInfo.UserName = result.User.UserName; userInfo.Token = Guid.NewGuid().ToString().Replace("-", ""); SSOUtil.SetUserInfo(userInfo); gotoViewModel.Url = string.Format("{0}?token={1}", returnUrl, userInfo.Token); return(Json(ResultType.Success, gotoViewModel, "登录成功")); }
public CustomJsonResult Login(RopLogin rop) { RetLogin ret = new RetLogin(); if (Session[sesionKeyLoginVerifyCode] == null) { return(Json(ResultType.Failure, ret, "验证码超时")); } if (Session[sesionKeyLoginVerifyCode].ToString() != rop.VerifyCode) { return(Json(ResultType.Failure, ret, "验证码不正确")); } var result = AdminServiceFactory.AuthorizeRelay.SignIn(rop.UserName, rop.Password, CommonUtil.GetIP(), Enumeration.LoginType.Website); if (result.ResultType == Enumeration.LoginResult.Failure) { if (result.ResultTip == Enumeration.LoginResultTip.UserNotExist || result.ResultTip == Enumeration.LoginResultTip.UserPasswordIncorrect) { return(Json(ResultType.Failure, ret, "用户名或密码不正确")); } if (result.ResultTip == Enumeration.LoginResultTip.UserDisabled) { return(Json(ResultType.Failure, ret, "账户被禁用")); } if (result.ResultTip == Enumeration.LoginResultTip.UserDeleted) { return(Json(ResultType.Failure, ret, "账户被删除")); } } string host = ""; string returnUrl = ""; switch (result.User.Type) { case Enumeration.UserType.Staff: host = System.Configuration.ConfigurationManager.AppSettings["custom:WebBackUrl"]; //returnUrl = string.Format("{0}?returnUrl={1}", host, model.ReturnUrl); returnUrl = string.Format("{0}", "/Wb/Home/Index"); break; case Enumeration.UserType.Merchant: host = System.Configuration.ConfigurationManager.AppSettings["custom:WebMerchUrl"]; //returnUrl = string.Format("{0}?returnUrl={1}", host, model.ReturnUrl); returnUrl = string.Format("{0}", host); break; } string key = GuidUtil.New(); UserInfo userInfo = new UserInfo(); userInfo.UserId = result.User.Id; userInfo.UserName = result.User.UserName; SSOUtil.SetUserInfo(key, userInfo); ret.Url = string.Format("{0}?token={1}", returnUrl, key); return(Json(ResultType.Success, ret, "登录成功")); }