public ActionResult Login() { try { var loginName = WebHelper.GetFormString("loginName", string.Empty); var password = WebHelper.GetFormString("password", string.Empty); UsersBLL bll = new UsersBLL(); var user = new UsersEntity(); //首先判断是邮箱还是电话: if (ValidateHelper.IsEmail(loginName)) { user = bll.GetUsersEntityByEmail(loginName, null).TData; } else { if (ValidateHelper.IsPhone(loginName)) { user = bll.GetUsersEntityByMobile(loginName, null).TData; } else { return AjaxResult("valicationErr", "请输入正确的邮箱或者电话号码!!", false); } } if (user != null && user.Password.Equals(SecurityUtil.HashPassword(password))) { //统一存cookie ShopUtils.SetUserCookie(user, 2); Session["User"] = user; user.IsOnline = 1; bll.Update(user,null); return AjaxResult("success", "登录成功!!", false); } else return AjaxResult("error", "用户名或密码不正确!!", false); } catch (Exception ex) { return AjaxResult("error", ex.ToString(), false); throw; } }
public ActionResult DoLoginn(LoginModel users) { try { var loginName = WebHelper.GetFormString("loginName", string.Empty); var password = WebHelper.GetFormString("password", string.Empty); UsersBLL bll = new UsersBLL(); var user = new UsersEntity(); //首先判断是邮箱还是电话: if (ValidateHelper.IsEmail(loginName)) { user = bll.GetUsersEntityByEmail(loginName, null).TData; } else { if (ValidateHelper.IsPhone(loginName)) { user = bll.GetUsersEntityByMobile(loginName, null).TData; } else { return Content("<script>alert('请输入正确的邮箱或者电话号码!!');location.href = '/shop/admin/loginn';</script>"); } } if (user != null && user.Password.Equals(SecurityUtil.HashPassword(password))) { //统一存cookie ShopUtils.SetUserCookie(user, 2); Session["User"] = user; user.IsOnline = 1; bll.Update(user, null); return Content("<script>location.href = '/shop/admin/GoodsMana';</script>"); } else return Content("<script>alert('用户名或密码不正确!!');location.href = '/shop/admin/loginn';</script>"); } catch (Exception ex) { return Content("<script>alert('登陆出错!!');location.href = '/shop/admin/loginn';</script>"); throw; } }