private void CheckUserInfo() { string userName = Request.Form["txtLoginId"]; string userPassword = Request.Form["txtPwd"]; BLL.UserManager um = new BLL.UserManager(); msg = string.Empty; MODEL.User user = null; bool b = um.UserLogin(userName, userPassword, out msg, out user); if (b) { Session["userInfo"] = user; if (!string.IsNullOrEmpty(Request.Form["Remember_password"])) { HttpCookie cookie1 = new HttpCookie("cp1", user.LoginId); HttpCookie cookie2 = new HttpCookie("cp2", Common.WebCommon.GetStringMd5(user.PassWord)); cookie1.Expires = DateTime.Now.AddDays(3); cookie2.Expires = DateTime.Now.AddDays(3); Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); } GoToPage(user); } }
public async Task <ActionResult> UserDelete(Guid id) { IBLL.IUserManager userManager = new BLL.UserManager(); await userManager.UserDelete(id); return(RedirectToAction(nameof(AdminList))); }
protected void AddUserInfo() { Model.User userInfo = new Model.User(); userInfo.Address = Request["txtAddress"]; userInfo.LoginId = Request["txtName"]; userInfo.LoginPwd = Request["txtPwd"]; userInfo.Mail = Request["txtEmail"]; userInfo.Name = Request["txtRealName"]; userInfo.Phone = Request["txtPhone"]; userInfo.UserState.Id = Convert.ToInt32(UserStateEnum.NormalState); BLL.UserManager userManager = new BLL.UserManager(); string msg = string.Empty; if (userManager.Add(userInfo, out msg) > 0) { Session["userInfo"] = userInfo; Response.Redirect("/Default.aspx"); } else { Response.Redirect("/ShowMsg.aspx?msg=" + msg + "&txt=首页" + "&url=/Default.aspx"); } }
// GET: Admin/Home public async Task <ActionResult> Index() { var loginname = Session["loginAdmin"].ToString(); IBLL.IUserManager userManager = new BLL.UserManager(); var usermodel = await userManager.GetUserByEmail(loginname); return(View(usermodel)); }
public async Task <ActionResult> UserEdit(AdminListViewModel model) { if (ModelState.IsValid) { IBLL.IUserManager userManager = new BLL.UserManager(); await userManager.UserEdit(model.Id, model.Email, model.ImagePath, model.SiteName, model.Type); return(RedirectToAction(nameof(AdminList))); } ModelState.AddModelError("", "验证失败"); return(View(model)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BLL.UserManager userManager = new BLL.UserManager(); if (userManager.ValidateUserLogin()) { BindCartList(); } else { Common.WebCommon.RedirectPage(); } } }
public async Task <ActionResult> Login(AdminLoginViewModel model) { if (ModelState.IsValid) { IBLL.IUserManager userManager = new BLL.UserManager(); Guid userId; if (userManager.Login(model.Email, model.LoginPwd, out userId)) { var usermodel = await userManager.GetUserByEmail(model.Email); if (usermodel.Type == 0) { ModelState.AddModelError("", "该账号没有管理权限"); return(View(model)); } //跳转 //用session还是用cookie if (model.RememberMe) { Response.Cookies.Add(new HttpCookie("loginAdmin") { Value = model.Email, Expires = DateTime.Now.AddDays(7) }); Response.Cookies.Add(new HttpCookie("adminId") { Value = userId.ToString(), Expires = DateTime.Now.AddDays(7) }); } else { Session["loginAdmin"] = model.Email; Session["adminId"] = userId; } return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "用户名密码错误"); } } else { ModelState.AddModelError("", "您的账号密码有误"); } return(View(model)); }
public async Task <ActionResult> UserEdit(Guid id) { IBLL.IUserManager userManager = new BLL.UserManager(); var user = await userManager.GetOneUserById(id); return(View(new AdminListViewModel() { Id = user.Id, Email = user.Email, ImagePath = user.ImagePath, SiteName = user.SiteName, FansCount = user.FansCount, FocusCount = user.FocusCount, Type = user.Type })); }
public async Task <IHttpActionResult> Register(LoginViewModel model) { if (ModelState.IsValid) { IBLL.IUserManager userManager = new BLL.UserManager(); if (await userManager.GetUserByEmail(model.Email) == null) { await userManager.Register(model.Email, model.LoginPwd); return(this.SendData("注册成功")); } return(this.ErrorData("邮箱已注册")); } return(this.ErrorData("输入数据不合法")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { IBLL.IUserManager userManager = new BLL.UserManager(); if (await userManager.GetUserByEmail(model.Email) == null) { await userManager.Register(model.Email, model.Password); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", "邮箱已存在"); } return(View(model)); }
public ActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { IBLL.IUserManager userManager = new BLL.UserManager(); Guid userid; if (userManager.Login(model.Email, model.LoginPwd, out userid)) { //跳转 //用session还是用cookie if (model.RememberMe) { Response.Cookies.Add(new HttpCookie("loginName") { Value = model.Email, Expires = DateTime.Now.AddDays(7) }); Response.Cookies.Add(new HttpCookie("userId") { Value = userid.ToString(), Expires = DateTime.Now.AddDays(7) }); } else { Session["loginName"] = model.Email; Session["userId"] = userid; } return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "用户名密码错误"); } } else { ModelState.AddModelError("", "您的账号密码有误"); } return(View(model)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; BLL.UserManager userManager = new BLL.UserManager(); if (userManager.ValidateUserLogin())//判断是否登录 { int bookId = Convert.ToInt32(context.Request["bookId"]); //判断数据库中是否有该商品. BLL.BookManager bookManager = new BLL.BookManager(); Model.Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { int userId = ((Model.User)context.Session["userInfo"]).Id;//获取登录用户登录的ID。 BLL.CartManager cartManager = new BLL.CartManager(); Model.Cart cartModel = cartManager.GetModel(userId, bookId); //如果购物车有该商品,更新数量加1,没有插入 if (cartModel != null) { cartModel.Count = cartModel.Count + 1; cartManager.Update(cartModel); } else { Model.Cart modelCart = new Model.Cart(); modelCart.Count = 1; modelCart.Book = bookModel; modelCart.User = ((Model.User)context.Session["userInfo"]); cartManager.Add(modelCart); } context.Response.Write("ok:商品成功添加到购物车"); } else { context.Response.Write("no:无此商品"); } } else { context.Response.Write("login:没有登录"); } }
public async Task <ActionResult> QQLogin() { IBLL.IUserManager userManager = new BLL.UserManager(); var code = Request.QueryString["code"]; var token = GetAuthorityAccessToken(code); var dic = GetAuthorityOpendIdAndUnionId(token); var userInfo = GetUserInfo(token, dic["openid"]); Dto.UserInformationDto user = await userManager.GetUserByOpenId(dic["openid"], userInfo); Response.Cookies.Add(new HttpCookie("userinfo") { Value = JsonConvert.SerializeObject(user), Expires = DateTime.Now.AddDays(7) }); return(RedirectToAction("Index", "Home")); }
public IHttpActionResult Login(LoginViewModel model) { if (ModelState.IsValid) { IBLL.IUserManager userManager = new BLL.UserManager(); if (userManager.Login(model.Email, model.LoginPwd, out Guid userid)) { return(this.SendData(JwtTools.Encoder(new Dictionary <string, object>() { { "username", model.Email }, { "userid", userid } }))); } else { return(this.ErrorData("用户名密码错误")); } } return(this.ErrorData("输入数据不合法")); }
private void CheckUserCookie() { if(Request.Cookies["cp1"]!=null&&Request.Cookies["cp2"]!=null) { string userCookieName = Request.Cookies["cp1"].Value; string userCookiePass = Request.Cookies["cp2"].Value; BLL.UserManager um = new BLL.UserManager(); MODEL.User user = um.GetModel(userCookieName); if(user!=null) { string pwd = Common.WebCommon.GetStringMd5(user.PassWord); if(pwd==userCookiePass) { Session["userInfo"] = user; GoToPage(user); } } else { //TODO:情况cookie } } }
private void CheckUserCookie() { if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null) { string userCookieName = Request.Cookies["cp1"].Value; string userCookiePass = Request.Cookies["cp2"].Value; BLL.UserManager um = new BLL.UserManager(); MODEL.User user = um.GetModel(userCookieName); if (user != null) { string pwd = Common.WebCommon.GetStringMd5(user.PassWord); if (pwd == userCookiePass) { Session["userInfo"] = user; GoToPage(user); } } else { //TODO:情况cookie } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string name = context.Request["name"]; string mail = context.Request["mail"]; BLL.UserManager UserInfoManager = new BLL.UserManager(); Model.User userInfo = UserInfoManager.GetModel(name); if (userInfo != null) { if (userInfo.Mail == mail) { UserInfoManager.FindUserPwd(userInfo);//找回用户的密码 } else { context.Response.Write("邮箱错误!!"); } } else { context.Response.Write("查无此人!!"); } }
public void ProcessRequest(HttpContext context) { ; context.Response.ContentType = "text/plain"; BLL.UserManager bll = new BLL.UserManager(); string action = context.Request["action"]; // 获得分页 if (action == "get") { int pageIndex, pageSize; try { pageIndex = Convert.ToInt32(context.Request["pageIndex"]); pageSize = Convert.ToInt32(context.Request["pageSize"]); } catch { return; } pageIndex = pageIndex < 1 ? 1 : pageIndex; pageSize = pageSize <= 0 || pageSize > 10 ? 10 : pageSize; int pageCount = (int)Math.Ceiling((double)bll.GetModelCount() / (double)pageSize); List <Model.User> list = bll.GetPageList(pageIndex, pageSize); object obj = new { pageIndex, pageSize, pageCount, data = list, }; JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write(js.Serialize(obj)); } // 获得一个 else if (action == "getById") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } var user = bll.GetModel(id); if (user == null) { context.Response.Write("no:该用户不存在"); return; } JavaScriptSerializer js = new JavaScriptSerializer(); context.Response.Write("ok:" + js.Serialize(user)); } // 删除 else if (action == "delete") { int id = 0; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } if (bll.Delete(id)) { context.Response.Write("ok:删除成功"); } else { context.Response.Write("no:删除失败"); } } // 修改 else if (action == "edit") { int id; if (!int.TryParse(context.Request["id"], out id)) { context.Response.Write("error:非法的ID"); return; } Model.User user = bll.GetModel(id); if (user == null) { context.Response.Write("no:该用户不存在"); return; } user.UserName = context.Request["userName"] == null ? user.UserName : context.Request["userName"]; user.Nickname = context.Request["nickname"] == null ? user.UserName : context.Request["nickname"]; user.Pwd = context.Request["pwd"] == null ? user.UserName : context.Request["pwd"]; user.Sex = Convert.ToChar(context.Request["sex"] == null ? user.UserName : context.Request["sex"]); user.Phone = context.Request["phone"] == null ? user.UserName : context.Request["phone"]; user.Address = context.Request["address"] == null ? user.UserName : context.Request["address"]; if (string.IsNullOrWhiteSpace(user.Pwd)) { context.Response.Write("no:密码不能为空"); } if (bll.Update(user)) { context.Response.Write("ok:修改成功"); } else { context.Response.Write("no:修改失败"); } } // 添加 else if (action == "add") { string username = context.Request["userName"]; string pwd = context.Request["pwd"]; char sex = Convert.ToChar(context.Request["sex"] == null?"\0": context.Request["sex"]); if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(pwd) || (sex) == '\0') { context.Response.Write("no:参数错误"); return; } Model.User user = new Model.User(); user.UserName = username; user.Nickname = context.Request["nickname"] == null? user.UserName : context.Request["nickname"]; user.Pwd = Common.MD5Helper.GetMD5String(pwd); user.Sex = sex; user.Phone = context.Request["phone"] == null?string.Empty: context.Request["phone"]; user.Address = context.Request["address"] == null ? string.Empty : context.Request["address"]; user.Url = context.Request["userUrl"] == null ? string.Empty : context.Request["userUrl"]; user.Description = context.Request["description"] == null ? string.Empty : context.Request["description"]; user.UserPic = context.Request["userPic"] == null ? string.Empty : context.Request["userPic"]; if (bll.Add(user)) { context.Response.Write("ok:添加成功"); } else { context.Response.Write("no:添加失败"); } } else { context.Response.Write("error:非法的action"); } }
public static DAL.User CreateUser(DAL.User user) { try { using (TransactionScope ts = new TransactionScope()) { using (BLL.UserManager um = new BLL.UserManager()) { if (user.Password == null || user.Password.Trim() == "") user.Password = WebSecurity.Membership.GeneratePassword(8, 0); WebSecurity.MembershipUser membershipUser = WebSecurity.Membership.CreateUser(user.UserName, user.Password, user.Email); Guid ProviderKey = (Guid)membershipUser.ProviderUserKey; user.MembershipProviderKey = ProviderKey; if (user.Role.Trim() != "") { string[] roles = user.Role.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (roles.Length > 0) AddUserToRoles(user.UserName, roles); } um.CreateUser(user); } ts.Complete(); } return user; } catch (WebSecurity.MembershipCreateUserException) { throw new Exceptions.UserException("User account creation failed."); } catch (WebSecurity.MembershipPasswordException) { throw new Exceptions.UserException("Please provide a valid password."); } catch (Exception) { throw new Exceptions.UserException("User account creation failed."); } }
//管理员管理 public async Task <ActionResult> AdminList() { IBLL.IUserManager userManager = new BLL.UserManager(); return(View(await userManager.GetAllUsers())); }
public static void DeleteUser(DAL.User user) { try { using (TransactionScope ts = new TransactionScope()) { using (BLL.UserManager um = new BLL.UserManager()) { WebSecurity.Membership.DeleteUser(user.UserName); um.DeleteUser(user); } ts.Complete(); } } catch (Exception) { throw new Exceptions.UserException("Deleting user failed."); } }
public static List<DAL.User> GetAllUsers() { using (BLL.UserManager um = new BLL.UserManager()) { return um.GetAllUsers(); } }
public static DAL.User GetUserById(int userId) { using (BLL.UserManager um = new BLL.UserManager()) { return um.GetUserByID(userId); } }
public static DAL.User UpdateUser(DAL.User user) { try { using (TransactionScope ts = new TransactionScope()) { using (BLL.UserManager um = new BLL.UserManager()) { DAL.User oldUser = um.GetUserByID(user.UserID); if (oldUser != null) { if (oldUser.UserName != user.UserName) throw new Exceptions.UserException("Changing user name is not allowed."); string[] roles = user.Role.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (roles.Length > 0) AddUserToRoles(user.UserName, roles); MembershipUser mUser = WebSecurity.Membership.GetUser(user.UserName); user.MembershipProviderKey = (Guid)mUser.ProviderUserKey; user = um.UpdateUser(user); } else { throw new Exceptions.UserException("No user found to update."); } } ts.Complete(); return user; } } catch (Exceptions.UserException userex) { throw userex; } catch (Exception) { throw new Exceptions.UserException("Updating user failed."); } }
public static List <Models.ACL_User> GetAllUser() { BLL.UserManager userManager = new BLL.UserManager(); return(userManager.GetAllList()); }