/// <summary> /// 退出 /// </summary> public ActionResult Logout() { if (WorkContext.Uid > 0) { WebHelper.DeleteCookie("web_bsp"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } return(Redirect("/")); }
/// <summary> /// 退出 /// </summary> public ActionResult Logout() { if (WorkContext.Uid > 0) { WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } return(Redirect(Url.Action("index", "home"))); }
/// <summary> /// 退出 /// </summary> public ActionResult Logout() { if (WorkContext.Uid > 0) { WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } return(Redirect("/account/login"));//普通会员退出,跳转到首页 }
/// <summary> /// 首页 /// </summary> /// <returns></returns> public ActionResult Index() { if (WorkContext.Uid > 0) { WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } return(RedirectToAction("login", "account")); ////判断请求是否来自移动设备,如果是则重定向到移动主题 //if (WebHelper.GetQueryInt("m") != 1 && WebHelper.IsMobile()) // return RedirectToAction("index", "home", new RouteValueDictionary { { "area", "mob" } }); ////首页的数据需要在其视图文件中直接调用,所以此处不再需要视图模型 //return View(); }
/// <summary> /// 找回密码 /// </summary> public ActionResult ResetPwd() { try { NameValueCollection parmas = WorkContext.postparms; string oldpwd = parmas["oldpwd"]; string password = parmas["password"]; PartUserInfo partUserInfo = Users.GetPartUserById(WorkContext.Uid); //if (Users.CreateUserPassword(oldpwd, partUserInfo.Salt) != partUserInfo.Password) //{ // //原始密码错误 // return Content("2"); //} if (oldpwd != partUserInfo.Password) { //原始密码错误 return(Content("2")); } //生成用户新密码 string p = password;// Users.CreateUserPassword(password, partUserInfo.Salt); //设置用户新密码 bool upres = Users.UpdateUserPasswordByUid(WorkContext.Uid, p); //清空当前用户信息 WebHelper.DeleteCookie("web"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); if (upres) { return(Content("1")); } else { return(Content("3")); } } catch (Exception ex) { return(Content("3")); } }
/// <summary> /// 重置密码 /// </summary> public ActionResult ResetPwd() { string v = WebHelper.GetQueryString("v"); //解密字符串 string realV; try { realV = MallUtils.AESDecrypt(v); } catch (Exception ex) { //如果v来自邮件,那么需要url解码 realV = MallUtils.AESDecrypt(WebHelper.UrlDecode(v)); } //数组第一项为uid,第二项为验证时间,第三项为随机值 string[] result = StringHelper.SplitString(realV); if (result.Length != 3) { return(HttpNotFound()); } int uid = TypeHelper.StringToInt(result[0]); DateTime time = TypeHelper.StringToDateTime(result[1]); PartUserInfo partUserInfo = Users.GetPartUserById(uid); if (partUserInfo == null) { return(PromptView("用户不存在")); } //判断验证时间是否过时 if (DateTime.Now.AddMinutes(-30) > time) { return(PromptView("此链接已经失效,请重新验证")); } //get请求 if (WebHelper.IsGet()) { ResetPwdModel model = new ResetPwdModel(); model.V = v; return(View(model)); } //ajax请求 string password = WebHelper.GetFormString("password"); string confirmPwd = WebHelper.GetFormString("confirmPwd"); StringBuilder errorList = new StringBuilder("["); //验证 if (string.IsNullOrWhiteSpace(password)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不能为空", "}"); } else if (password.Length < 4 || password.Length > 32) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码必须大于3且不大于32个字符", "}"); } else if (password != confirmPwd) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "confirmPwd", "两次输入的密码不一样", "}"); } if (errorList.Length == 1) { //生成用户新密码 string p = Users.CreateUserPassword(password, partUserInfo.Salt); //设置用户新密码 Users.UpdateUserPasswordByUid(uid, p); //清空当前用户信息 WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); return(AjaxResult("success", Url.Action("login"))); } else { return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true)); } }
/// <summary> /// 登录 /// </summary> public ActionResult Login() { if (WorkContext.Uid > 0) { WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } string returnUrl = WebHelper.GetQueryString("returnUrl"); if (returnUrl.Length == 0) { returnUrl = "/"; } returnUrl = Url.Action("index", "home", new RouteValueDictionary { { "area", "storeadmin" } }); if (WorkContext.MallConfig.LoginType == "") { return(PromptView(returnUrl, "商城目前已经关闭登录功能!")); } /*if (WorkContext.Uid > 0) * return PromptView(returnUrl, "您已经登录,无须重复登录!");*/ if (WorkContext.MallConfig.LoginFailTimes != 0 && LoginFailLogs.GetLoginFailTimesByIp(WorkContext.IP) >= WorkContext.MallConfig.LoginFailTimes) { return(PromptView(returnUrl, "您已经输入错误" + WorkContext.MallConfig.LoginFailTimes + "次密码,请15分钟后再登录!")); } //get请求 if (WebHelper.IsGet()) { LoginModel model = new LoginModel(); model.ReturnUrl = returnUrl; model.ShadowName = WorkContext.MallConfig.ShadowName; model.IsRemember = WorkContext.MallConfig.IsRemember == 1; model.IsVerifyCode = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.VerifyPages); model.OAuthPluginList = Plugins.GetOAuthPluginList(); return(View(model)); } //ajax请求 string accountName = WebHelper.GetFormString(WorkContext.MallConfig.ShadowName); string password = WebHelper.GetFormString("password"); string verifyCode = WebHelper.GetFormString("verifyCode"); int isRemember = WebHelper.GetFormInt("isRemember"); StringBuilder errorList = new StringBuilder("["); //验证账户名 if (string.IsNullOrWhiteSpace(accountName)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不能为空", "}"); } else if (accountName.Length < 4 || accountName.Length > 50) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名必须大于3且不大于50个字符", "}"); } else if ((!SecureHelper.IsSafeSqlString(accountName, false))) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不存在", "}"); } //验证密码 if (string.IsNullOrWhiteSpace(password)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不能为空", "}"); } else if (password.Length < 4 || password.Length > 32) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码必须大于3且不大于32个字符", "}"); } //验证验证码 if (CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.VerifyPages)) { if (string.IsNullOrWhiteSpace(verifyCode)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不能为空", "}"); } else if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不正确", "}"); } } //当以上验证全部通过时 PartUserInfo partUserInfo = null; if (errorList.Length == 1) { if (ValidateHelper.IsEmail(accountName))//邮箱登录 { if (!BMAConfig.MallConfig.LoginType.Contains("2")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用邮箱登录", "}"); } else { partUserInfo = Users.GetPartUserByEmail(accountName); if (partUserInfo == null) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "邮箱不存在", "}"); } } } else if (ValidateHelper.IsMobile(accountName))//手机登录 { if (!BMAConfig.MallConfig.LoginType.Contains("3")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用手机登录", "}"); } else { partUserInfo = Users.GetPartUserByMobile(accountName); if (partUserInfo == null) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "手机不存在", "}"); } } } else //用户名登录 { if (!BMAConfig.MallConfig.LoginType.Contains("1")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用用户名登录", "}"); } else { partUserInfo = Users.GetPartUserByName(accountName); if (partUserInfo == null) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名不存在", "}"); } } } if (partUserInfo != null) { if (Users.CreateUserPassword(password, partUserInfo.Salt) != partUserInfo.Password) //判断密码是否正确 { LoginFailLogs.AddLoginFailTimes(WorkContext.IP, DateTime.Now); //增加登录失败次数 errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不正确", "}"); } else if (partUserInfo.UserRid == 1) //当用户等级是禁止访问等级时 { if (partUserInfo.LiftBanTime > DateTime.Now) //达到解禁时间 { UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits, partUserInfo.RegisterFromStoreId); Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo?.UserRid ?? 0); partUserInfo.UserRid = userRankInfo?.UserRid ?? 0; } else { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "您的账号当前被锁定,不能访问", "}"); } } if (partUserInfo.StoreId == 0) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "您的账号是非店铺管理员,不能访问", "}"); } } } if (errorList.Length > 1)//验证失败时 { return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true)); } else//验证成功时 { //删除登录失败日志 LoginFailLogs.DeleteLoginFailLogByIP(WorkContext.IP); //更新用户最后访问 Users.UpdateUserLastVisit(partUserInfo.Uid, DateTime.Now, WorkContext.IP, WorkContext.RegionId); //更新购物车中用户id Carts.UpdateCartUidBySid(partUserInfo.Uid, WorkContext.Sid); //将用户信息写入cookie中 MallUtils.SetUserCookie(partUserInfo, (WorkContext.MallConfig.IsRemember == 1 && isRemember == 1) ? 30 : -1); returnUrl = Url.Action("index", "home", new RouteValueDictionary { { "area", "malladmin" } }); return(partUserInfo.Uid == 1 ? AjaxResult("mallsuccess", returnUrl) : AjaxResult("success", "登录成功")); } }
/// <summary> /// 订阅宝SSO登录 /// </summary> public ActionResult DybLogin() { try { LogUtil.WriteLog($"开始登陆 url:{WebHelper.GetRawUrl()}"); if (WorkContext.Uid > 0) { WebHelper.DeleteCookie("bma"); Sessions.RemoverSession(WorkContext.Sid); OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid); } string username = WebHelper.GetQueryString("username"); string agentname = WebHelper.GetQueryString("agentname"); string redirectUrl = WebHelper.GetQueryString("redirect"); string ak = WebHelper.GetQueryString("ak"); if (string.IsNullOrEmpty(username)) { return(PromptView("该单点登录链接缺少用户信息")); } var storepid = 0; if (!string.IsNullOrEmpty(agentname)) { var agentUid = OAuths.GetUidByOpenIdAndServer(agentname, "dyb"); if (agentUid > 0) { var agentUser = Users.GetPartUserById(agentUid); storepid = agentUser.StoreId; } } var uid = OAuths.GetUidByOpenIdAndServer(username, "dyb"); if (uid < 1) { //创建用户 var userInfo = OAuths.CreateOAuthUser(DateTime.Now.ToString("yyMMddHHmmssms"), "dyb", username, "dyb", WorkContext.RegionId); uid = userInfo.Uid; } var partUserInfo = Users.GetPartUserById(uid); if (partUserInfo.StoreId == 0) { //创建店铺 var storeId = AdminStores.CreateStore(new StoreInfo { Announcement = "", Banner = "", CreateTime = DateTime.Now, DePoint = 10, Description = "", Honesties = 0, Logo = "", Mobile = "", Name = "微信小程序", Phone = "", QQ = "", RegionId = 0, SePoint = 10, ShPoint = 10, State = 0, StateEndTime = DateTime.Now.AddYears(1), StoreIid = 0, StoreRid = 1, Theme = "default", WW = "", StorePid = storepid }, new StoreKeeperInfo { Address = username, IdCard = username, Name = partUserInfo.UserName, Type = 0 }); AdminStores.CreateStoreShipTemplate(new StoreShipTemplateInfo { Free = 1, StoreId = storeId, Title = "全场包邮", Type = 0 }); //创建会员等级 AdminUserRanks.CreateUserRank(new UserRankInfo { Avatar = string.Empty, CreditsLower = 0, CreditsUpper = -1, LimitDays = 0, StoreId = storeId, System = 0, Title = "初级会员" }); partUserInfo.StoreId = storeId; partUserInfo.UserRid = UserRanks.GetLowestUserRank(storeId).UserRid; WorkContext.StoreId = storeId; Users.UpdatePartUser(partUserInfo); } //如果对应的店铺没有平台ID,则可以更改storepid,否则不行 if (storepid > 0) { var store = Stores.GetStoreById(partUserInfo.StoreId); if (store != null && store.StorePid == 0 && store.StoreId != storepid) { AdminStores.UpdateStorePId(store.StoreId, storepid); } } //将用户信息写入cookie中 MallUtils.SetUserCookie(partUserInfo, 365); StoreInfoManager.UpdateDistributor(partUserInfo.StoreId, ak.Equals("dis", StringComparison.InvariantCultureIgnoreCase)); LogUtil.WriteLog($"开始登陆 开始跳转"); if (string.IsNullOrEmpty(redirectUrl)) { return(RedirectToAction("index", "home", new RouteValueDictionary { { "area", "storeadmin" } })); } else { return(Redirect(redirectUrl)); } } catch (Exception e) { Trace.TraceError(e.Message); throw; } }