private string JumpBase(string telNo, string projUrl) { //如果用户已经登录 if (WebUserAuth.UserId.HasValue && WebUserAuth.UserId.Value != Guid.Empty) { //是否同一用户 bool userEx = UserExists(telNo, WebUserAuth.UserId.Value); if (userEx) { return(projUrl); } else { WebUserAuth.SignOut(); GlobalUtils.ClearOpenIdFromCookie(); } } //如果用户没有登录 //判断用户是否存在 TdUserInfo user = GetUserInfo(telNo); //如果用户存在 自动登录 string result = String.Empty; if (user != null) { //是否平台用户 if (user.RegisterFrom.StartsWith(_app)) { result = AutoLogin(telNo, user); } //自动登录失败 或 不是平台用户 跳转到登录页面 if (!string.IsNullOrEmpty(result) || !user.RegisterFrom.StartsWith(_app)) { CookieHelper.WriteCookie("Wap_UserName", telNo, 1); return(GlobalUtils.WebURL + "/user/Login.aspx?ReturnUrl=" + projUrl); } } else //如果用户不存在 自动注册 { result = UserInsertByPhone(telNo); if (!string.IsNullOrEmpty(result)) { return(GlobalUtils.WebURL + "/user/Register.aspx?tdfrom=" + _app + "&phone=" + telNo + "&ReturnUrl=" + projUrl); } } return(projUrl); }
private string AutoLogin(string telNo, TdUserInfo model) { if (model == null) { return("没有找到用户信息"); } if (string.IsNullOrEmpty(telNo.Trim())) { return("手机号不能为空"); } if ((model.uStatus ?? 0) == 1) { WebUserAuth.SignIn(model.Id.ToString()); //登录时判断超级会员是否过期 model.Level = BusinessDll.Users.JudgeUserLevel(model.Level.Value, model.LevelEndDate); model.LastLoginDate = DateTime.Now; string userIP = Tool.WebFormHandler.GetIP(); TuanDai.InfoSystem.Model.LoginLog loginLogEntity = new TuanDai.InfoSystem.Model.LoginLog(); loginLogEntity.Id = Guid.NewGuid().ToString(); loginLogEntity.UserId = model.Id.ToString(); loginLogEntity.IpAddress = userIP; loginLogEntity.LoginDate = model.LastLoginDate; loginLogEntity.DeviceType = "WeiXin"; loginLogEntity.DeviceName = Request["app"].ToLower() + "自动登录"; //TuanDai.InfoSystem.WcfClient.LoginLogService logApi = new TuanDai.InfoSystem.WcfClient.LoginLogService(); //logApi.AddLoginLog(loginLogEntity); TuanDai.WXApiWeb.SysLogHelper.AddLoginLog(loginLogEntity); UserBLL userbll = new UserBLL(); //保存用户最后登录时间 userbll.WXUpdateUserLastLoginDate(model); //记录注册IP //BusinessDll.RegisterIp.WriteLoginHandler(model.Id); userbll.AsyncLoginEnd(model.Id, 1, userIP, "", "", model.ThirdPartyId, model.ThirdPartyType); //登录成功后移除第三方写的Cookie CookieHelper.ClearCookie("ThirdLoginUserInfo"); CookieHelper.ClearCookie("WXLoginType"); return(string.Empty); } else { return("登录失败,用户状态不能登录"); } }