public ActionResult Login(string userName, string passWord) { User user = new User(); string msg = string.Empty; var result = _IUserService.LogOn(userName, passWord, out user, out msg); Session["ADMIN_USER"] = user; return new ActionReturn(result, msg, ""); }
public ActionResult Update(User model) { model.Id = CUR_USER.Id; model.ModifyUser = CUR_USER.UserName; model.ModifyTime = CUR_USER.ModifyTime; if (_IUserService.Update(model) > 0) { CUR_USER.NickName = model.NickName; CUR_USER.Sex = model.Sex; return new ActionReturn(true, "修改成功!", null); } return new ActionReturn(false, "修改失败!", null); }
/// <summary> /// 登录 /// </summary> /// <param name="userName"></param> /// <param name="passWord"></param> /// <param name="user"></param> /// <param name="msg"></param> /// <returns>登录成功返回true和User信息,失败返回false和null</returns> public bool LogOn(string userName, string passWord, out User user, out string msg) { int result_u = 0; user = null; msg = string.Empty; string sql_u = @"Select COUNT(*) Count From user Where UserName = @UserName;"; string sql_up = @"Select * From user Where UserName = @UserName And PassWord = @PassWord;"; MySqlParameter[] para_u = new MySqlParameter[] { new MySqlParameter("@UserName", userName) }; MySqlParameter[] para_up = new MySqlParameter[] { new MySqlParameter("@UserName", userName), new MySqlParameter("@PassWord", passWord) }; //验证用户是否存在 using (var conn = DataBase.GetOpenConn4MySql()) { MySqlDataReader dr = DataBase.ExecuteQueryReader(sql_u, conn, para_u); while (dr.Read()) { result_u = dr["Count"] != null ? Convert.ToInt32(dr["Count"]) : 0; } dr.Close(); if (result_u <= 0) { msg = "用户名不存在"; return false; } } //验证用户名和密码是否正确 DataSet ds = new DataSet(); MySqlDataAdapter da = DataBase.ExecuteQuery4MySql(sql_up, para_up.ToList()); if (da != null) { da.Fill(ds); } if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { user = FillData.FillDataToEntity<User>(new User(), ds.Tables[0]); return true; } else { msg = "密码输入错误"; return false; } }
public ActionResult Login(string userName, string passWord) { User user = new User(); string msg = string.Empty; if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(passWord)) { var result = _IUserService.LogOn(userName, passWord, out user, out msg); if (result) { Session["CUR_USER"] = user; return new ActionReturn(true, msg, null);//登录成功 } else { return new ActionReturn(false, msg, null); } } else { return new ActionReturn(false, msg = "用户名或密码为空", "/Account/LogOn"); } }
public ActionResult Register(string userName, string passWord) { var user = new User() { Id = Guid.NewGuid().ToId(), UserName = userName, NickName = userName, PassWord = passWord, UserResource = "Web Register", UserType = 2, CreateTime = DateTime.Now, CreateUser = userName, }; if (_IUserService.Insert(user)) { return new ActionReturn(true, "注册成功", null); } return new ActionReturn(false); }
/// <summary> /// 添加用户 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool Insert(User entity) { if (entity != null) { if (_DataBase.InsertModel<User>(entity)) return true; return false; } else { return false; } }
/// <summary> /// 根据ID查询单个用户 /// </summary> /// <param name="id"></param> /// <returns></returns> public User GetById(string id) { User user = new User(); user = _DataBase.QueryStoredProcedure<User>("aaa", null).FirstOrDefault(); return user; }
/// <summary> /// 更新用户昵称和性别信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(User model) { var sql = @"Update user Set NickName = @NickName, Sex = @Sex Where Id = @Id"; MySqlParameter[] para = new MySqlParameter[] { new MySqlParameter("@NickName", model.NickName), new MySqlParameter("@Sex", model.Sex), new MySqlParameter("@Id", model.Id) }; if (DataBase.ExecuteNonQuery4MySql(sql, para.ToList()) > 0) { return 1; } return 0; }