public JsonResult Delete(string id) { if (!string.IsNullOrWhiteSpace(id)) { //保护管理员不能被删除 if (id == "admin") { LogHandler.WriteServiceLog(GetUserName(), "尝试删除管理员", "失败", "删除", "用户设置"); return(Json(JsonHandler.CreateMessage(0, "管理员不能被删除!"), JsonRequestBehavior.AllowGet)); } EAP_User o = new EAP_User() { TrueName = id }; CommandResult r = DeleteObj <EAP_User>(o); if (r.IntResult > 0)// (userBLL.Delete(ref errors, id)) { LogHandler.WriteServiceLog(GetUserName(), "Id:" + id, "成功", "删除", "用户设置"); return(Json(JsonHandler.CreateMessage(1, Suggestion.DeleteSucceed), JsonRequestBehavior.AllowGet)); } else { string ErrorCol = r.Message; LogHandler.WriteServiceLog(GetUserName(), "Id:" + id + "," + ErrorCol, "失败", "删除", "用户设置"); return(Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail + ErrorCol), JsonRequestBehavior.AllowGet)); } } else { return(Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail), JsonRequestBehavior.AllowGet)); } }
public JsonResult EditPwd(string oldPwd, string newPwd) { LoginInfo _login = LoginUser; EAP_User user = GetObjByID <EAP_User>(_login.User.ID.ToString()); // if (user != null) //{ // return Json(JsonHandler.CreateMessage(0, "旧密码不匹配!"), JsonRequestBehavior.AllowGet); //} user.Password = NM.Util.DESEncrypt.Encrypt(newPwd); CommandResult r = SaveObj <EAP_User>(user); if (r.IntResult > 0) { LogHandler.WriteServiceLog(GetUserName(), "Id:" + LoginUser.User.UserName + ",密码:********", "成功", "初始化密码", "用户设置"); return(Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed), JsonRequestBehavior.AllowGet)); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserName(), "Id:" + GetUserName() + ",,密码:********" + ErrorCol, "失败", "初始化密码", "用户设置"); return(Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol), JsonRequestBehavior.AllowGet)); } }
public CommandResult AddUser(EAP_User user) { if (string.IsNullOrEmpty(user.Password)) { user.Password = DESEncrypt.Encrypt("123456"); } CommandResult result = new CommandResult(); result.Result = false; /* * string sFields = ""; * string sValues = ""; * * if (user.Items.Count <= 0) * { * return result; * } * * user.Items.ForEach(e => * { * if (e.K != "ID" && e.K != "Org_Name") * { * if (!string.IsNullOrEmpty(e.K) && e.S == EntityStatus.New && !e.K.EndsWith("_G")) * { * sFields += string.Format("[{0}],", e.K); * sValues += string.Format("'{0}',", e.V); * } * } * }); * * string sSql = string.Format( * "INSERT INTO EAP_User({0}) VALUES({1});SELECT CAST(scope_identity() AS int);", * sFields.Trim().TrimEnd(','), * sValues.Trim().TrimEnd(',')); * * int iPID = DataProvider.ExecuteScalar<int>(sSql); */ List <string> _fns = new List <string> (); _fns.Add("Org_Name"); int iPID = DataProvider.DoInsert(user, "EAP_USER", true, _fns); if (iPID > 0) { result.Result = true; result.ReturnValue.Add(new LookupDataItem() { K = "ID", V = iPID.ToString() }); result.Message = "新增成功。"; } else { result.Result = false; result.Message = "新增失败。"; } return(result); }
public CommandResult UpdateUser(EAP_User user) { CommandResult result = new CommandResult(); List <string> _fns = new List <string>(); _fns.Add("Org_Name"); _fns.Add("ID"); int iRows = DataProvider.DoUpdate(user, "EAP_USER", "ID", _fns); /* * string sSql = "UPDATE EAP_User SET "; * user.Items.ForEach(e => * { * if (e.K != "ID" && e.K != "Org_Name") * { * if (e.S == EntityStatus.Modified && !string.IsNullOrEmpty(e.K)) * { * sSql += string.Format("[{0}]='{1}',", e.K, e.V); * } * } * }); * * sSql = sSql.Trim().TrimEnd(','); * sSql += " WHERE ID='" + user.ID.ToString() + "'"; * * int iRows = DataProvider.ExecuteNonQuery(sSql); */ result.Result = iRows > 0 ? true : false; result.Message = iRows > 0 ? "更新成功。" : "更新失败。"; return(result); }
public ActionResult Info() { EAP_User _currlogin = LoginUser.User; EAP_User info = GetObjByID <EAP_User>(_currlogin.UserID.ToString()); return(View(info)); }
public void DeleteRoleFromUser(DataRequest request, DataResponse result, DataProvider datasource) { EAP_User user = TJson.Parse <EAP_User>(request["P0"]); string sRoleIDs = request["P1"]; result.Value = ToJson(new AccountOP(request.LogIn).DeleteRoleFromUser(user, sRoleIDs)); }
public ActionResult Create() { ViewBag.Perm = GetPermission(); ViewBag.Struct = null;// new SelectList(structBLL.GetQueryableByParentId("0"), "Value", "Text"); //ViewBag.Areas = new SelectList(areasBLL.GetList("0"), "Id", "Name"); EAP_User m = new EAP_User(); return(View(m)); }
public JsonResult Create(EAP_User model) { if (model != null && ModelState.IsValid) { LoginInfo _login = LoginUser; //默认密码123456 model.Password = NM.Util.DESEncrypt.Encrypt("123456"); CommandResult r = SaveObj <EAP_User>(model); if (r.IntResult > 0) { LogHandler.WriteServiceLog(_login.User.UserID.ToString(), "Id:" + model.ID + ",Name:" + model.TrueName, "成功", "保存", "用户"); return(Json(JsonHandler.CreateMessage(1, Suggestion.Save), JsonRequestBehavior.AllowGet)); } else { string ErrorCol = r.Message; LogHandler.WriteServiceLog(_login.User.UserID.ToString(), "Id:" + model.ID + ",Name:" + model.TrueName + "," + ErrorCol, "失败", "保存", "用户"); return(Json(JsonHandler.CreateMessage(0, Suggestion.SaveFail + ErrorCol), JsonRequestBehavior.AllowGet)); } } else { return(Json(JsonHandler.CreateMessage(0, Suggestion.SaveFail), JsonRequestBehavior.AllowGet)); } /* * if (model != null && ModelState.IsValid) * { * * model.Id = ResultHelper.NewId; * model.CreateTime = ResultHelper.NowTime; * model.Password = ValueConvert.MD5(model.Password); * model.CreatePerson = GetUserTrueName(); * model.State = true; * if (userBLL.Create(ref errors, model)) * { * LogHandler.WriteServiceLog(GetUserId(), "Id:" + model.Id + ",Name:" + model.UserName, "成功", "创建", "用户设置"); * return Json(JsonHandler.CreateMessage(1, Suggestion.InsertSucceed), JsonRequestBehavior.AllowGet); * } * else * { * string ErrorCol = errors.Error; * LogHandler.WriteServiceLog(GetUserId(), "Id:" + model.Id + ",Name:" + model.UserName + "," + ErrorCol, "失败", "创建", "用户设置"); * return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail + ErrorCol), JsonRequestBehavior.AllowGet); * } * } * else * { * return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail), JsonRequestBehavior.AllowGet); * } */ }
//查询所有EAP_Org public EAP_User GetOrgList() { EAP_User user = new EAP_User(); string sSql = string.Format("SELECT * FROM EAP_Org"); List <EAP_Org> _List = DataProvider.LoadData <EAP_Org>(sSql); if (_List != null) { user.OrgList = _List; } return(user); }
public CommandResult DeleteRoleFromUser(EAP_User user, string sRoleIDs) { CommandResult result = new CommandResult(); string sSql = string.Format(@"DELETE FROM EAP_UserRole WHERE [USERID]='{0}' and [ROLEID] IN({1})", user.ID, sRoleIDs); int iRows = DataProvider.ExecuteNonQuery(sSql); result.Result = iRows > 0 ? true : false; result.Message = iRows > 0 ? "删除成功。" : "删除失败。"; return(result); }
public ActionResult Edit(string id) { ViewBag.Perm = GetPermission(); EAP_User o = GetObjByID <EAP_User>(id); ViewBag.SelectedOrgId = o.OrgId; return(View(o)); /* * SysUser entity = userBLL.GetById(id); * ViewBag.Struct = new SelectList(structBLL.GetQueryableByParentId("0"), "Value", "Text"); * ViewBag.Areas = new SelectList(areasBLL.GetList("0"), "Id", "Name"); * SysUserEditModel info = new SysUserEditModel() * { * Id = entity.Id, * UserName = entity.UserName, * TrueName = entity.TrueName, * Card = entity.Card, * MobileNumber = entity.MobileNumber, * PhoneNumber = entity.PhoneNumber, * QQ = entity.QQ, * EmailAddress = entity.EmailAddress, * OtherContact = entity.OtherContact, * Province = entity.Province, * City = entity.City, * Village = entity.Village, * Address = entity.Address, * State = entity.State, * CreateTime = entity.CreateTime, * CreatePerson = entity.CreatePerson, * Sex = entity.Sex, * Birthday = ResultHelper.DateTimeConvertString(entity.Birthday), * JoinDate = ResultHelper.DateTimeConvertString(entity.JoinDate), * Marital = entity.Marital, * Political = entity.Political, * Nationality = entity.Nationality, * Native = entity.Native, * School = entity.School, * Professional = entity.Professional, * Degree = entity.Degree, * DepId = entity.DepId, * PosId = entity.PosId, * Expertise = entity.Expertise, * JobState = entity.JobState, * Photo = entity.Photo, * Attach = entity.Attach * }; * return View(info); */ }
public JsonResult ReSet(string Id, string Pwd) { if (!string.IsNullOrEmpty(Id)) { LoginInfo _login = LoginUser; EAP_User o = GetObjByID <EAP_User>(Id); o.Password = NM.Util.DESEncrypt.Encrypt(Pwd); CommandResult r = SaveObj <EAP_User>(o); if (r.IntResult > 0) { LogHandler.WriteServiceLog(_login.User.UserName.ToString(), "Id:" + Id + ",Name:" + o.TrueName, "成功", "初始化密码", "用户"); return(Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed), JsonRequestBehavior.AllowGet)); } else { string ErrorCol = r.Message; LogHandler.WriteServiceLog(_login.User.UserName.ToString(), "Id:" + Id + ",Name:" + o.TrueName + "," + ErrorCol, "失败", "初始化密码", "用户"); return(Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol), JsonRequestBehavior.AllowGet)); } } else { return(Json(JsonHandler.CreateMessage(0, Suggestion.EditFail), JsonRequestBehavior.AllowGet)); } /* * SysUserEditModel editModel = new SysUserEditModel(); * editModel.Id = Id; * editModel.Password = ValueConvert.MD5(Pwd); * if (userBLL.EditPwd(ref errors, editModel)) * { * LogHandler.WriteServiceLog(GetUserId(), "Id:" + Id + ",密码:********", "成功", "初始化密码", "用户设置"); * return Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed), JsonRequestBehavior.AllowGet); * } * else * { * string ErrorCol = errors.Error; * LogHandler.WriteServiceLog(GetUserId(), "Id:" + Id + ",,密码:********" + ErrorCol, "失败", "初始化密码", "用户设置"); * return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol), JsonRequestBehavior.AllowGet); * } * */ }
/// <summary> /// /// </summary> /// <param name="sUserName"></param> /// <param name="nametype">0:用户名登录 1:caid登录</param> /// <returns></returns> public EAP_User GetUserByUserName(string sUserName, int nametype = 0) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@UserName", sUserName), new SqlParameter("@nametype", nametype) }; EAP_User user = DataProvider.GetEntity <EAP_User>("usp_GetUserByUserName2", parameters); if (user != null) { string sSql = string.Format("SELECT * FROM uv_UserRole WHERE UserID='{0}'", user.ID); List <EAP_Role> _List = DataProvider.LoadData <EAP_Role>(sSql); user.Roles.Clear(); user.Roles.AddRange(_List); } return(user); }
public CommandResult AddRoleToUser(EAP_User user, string sRoleIDs) { CommandResult result = new CommandResult(); string[] arrayRoleID = sRoleIDs.Split(','); string sSql = ""; try { for (int i = 0; i < arrayRoleID.Length; i++) { /* * sSql = string.Format("INSERT INTO EAP_UserRole([UserID],[RoleID],[AddBy],[AddOn]) values('{0}','{1}','{2}','{3}');SELECT CAST(scope_identity() AS int);", * user.ID, arrayRoleID[i], Account.User.UserName, DateTime.Now); * * DataProvider.ExecuteScalar<int>(sSql); */ SerializableData _sd = new SerializableData(); _sd.SetInt32("USERID", user.ID); _sd.SetString("ROLEID", arrayRoleID[i]); _sd.SetString("ADDBY", Account.User.UserName); int iPID = DataProvider.DoInsert(_sd, "EAP_UserRole", true, null); if (iPID <= 0) { throw new Exception("保存失败。" + _sd.ToJson()); } } result.Result = true; result.Message = "添加成功。"; return(result); } catch { result.Result = false; result.Message = "数据库操作失败,参考Sql: " + sSql; return(result); } }
public LoginInfo Login(string sUserName, string sPassword, string clientIP, string clientName, int port, string ukeyid = "000000", int nametype = 0) { string sLoginMessage = ""; LoginStatus ls = LoginStatus.Failed; if (nametype == 0) { if (string.IsNullOrEmpty(sUserName)) { sLoginMessage = "登录失败,用户名输入为空。"; } if (string.IsNullOrEmpty(sPassword)) { sLoginMessage = "登录失败,密码输入为空。"; } } else if (nametype == 1) { if (string.IsNullOrEmpty(ukeyid)) { sLoginMessage = "登录失败,用户iD为空。"; } } EAP_User user = null; if (nametype == 1) { user = GetUserByUserName(ukeyid, 1); } else { user = GetUserByUserName(sUserName); } if (null == user) { sLoginMessage = "登录失败,用户不存在。"; } else if ((nametype == 0) && (sPassword != DESEncrypt.Decrypt(user.Password))) { sLoginMessage = "登录失败,密码不正确。"; } else if (user.IsLock) { sLoginMessage = "该用户名已经已经停止使用。"; } else { //加上检验是否进行ukey验证的代码 bool blok = true; if (user.isUseKey_G >= 1) { if (string.IsNullOrEmpty(ukeyid)) { sLoginMessage = "没有检测到UKey,请重试!"; blok = false; } else if (ukeyid != "000000") //当传入000000时,表示是后台调用,不需要校验 { if (user.isUseKey_G == 1) //一个组织可以使用多个ukey,不分用户; { string sSql = string.Format("select ID from EAP_OrgUKey where orgid={0} and ukeyid='{1}'", user.OrgId, ukeyid); List <int> _ukeyls = DataProvider.LoadData <int>(sSql); if ((_ukeyls == null) || (_ukeyls.Count == 0)) { sLoginMessage = "UKey认证失败!"; blok = false; } } else if (user.isUseKey_G == 2) //一个用户一个ukey { if (string.Compare(user.BarCode, ukeyid, true) != 0) { sLoginMessage = "UKey认证失败!"; blok = false; } } } } if (blok) { sLoginMessage = "登录成功。"; ls = LoginStatus.Successed; } } #region get client pc info string serverIP, serverName; DateTime myNow = DateTime.Now; serverName = Dns.GetHostEntry("localhost").HostName; //System.Net.Dns.GetHostName(); System.Net.IPAddress[] addressList = Dns.GetHostEntry(serverName).AddressList; if (addressList.Length > 0) { int _k = addressList.Length - 1; serverIP = addressList[_k].ToString(); } else { serverIP = addressList[0].ToString(); } serverIP = "1"; #endregion LoginInfo login = new LoginInfo() { //ClientIP = clientIP, ClientName = string.IsNullOrEmpty(clientName) ? "No get." : clientName, //ServerIP = string.IsNullOrEmpty(serverIP) ? "No get." : serverIP, ServerName = string.IsNullOrEmpty(serverName) ? "No get." : serverName, LoginPort = port, Status = ls, Message = string.IsNullOrEmpty(sLoginMessage) ? "No Message." : sLoginMessage, User = user, }; //user.Roles.ForEach(e => //{ // List<String> _List = this.GetPermissionByRole(e.ID); // _List.ForEach(c => // { // if (!login.Permission.Contains(c)) // { // login.Permission.Add(c); // } // }); //}); SaveLoginInfo(login); return(login); }
public void UpdateUser(DataRequest request, DataResponse result, DataProvider datasource) { EAP_User user = TJson.Parse <EAP_User>(request["P0"]); result.Value = ToJson(new AccountOP(request.LogIn).UpdateUser(user)); }
public JsonResult Edit(EAP_User model) { if (model != null && ModelState.IsValid) { LoginInfo _login = LoginUser; EAP_User o = GetObjByID <EAP_User>(model.ID.ToString()); o.UserName = model.UserName; o.TrueName = model.TrueName; o.OrgId = model.OrgId; ///need code /// CommandResult r = SaveObj <EAP_User>(o); if (r.IntResult > 0) { LogHandler.WriteServiceLog(_login.User.UserID.ToString(), "Id:" + model.ID + ",Name:" + model.TrueName, "成功", "保存", "用户"); return(Json(JsonHandler.CreateMessage(1, Suggestion.Save), JsonRequestBehavior.AllowGet)); } else { string ErrorCol = r.Message; LogHandler.WriteServiceLog(_login.User.UserID.ToString(), "Id:" + model.ID + ",Name:" + model.TrueName + "," + ErrorCol, "失败", "保存", "用户"); return(Json(JsonHandler.CreateMessage(0, Suggestion.SaveFail + ErrorCol), JsonRequestBehavior.AllowGet)); } } else { return(Json(JsonHandler.CreateMessage(0, Suggestion.SaveFail), JsonRequestBehavior.AllowGet)); } /* * if (info != null && ModelState.IsValid) * { * * EAP_User o = GetObjByID<EAP_User>(info.ID.ToString()); * o.UserName = info.UserName; * o.TrueName = info.TrueName; * o.OrgId = info.OrgId; * * ///need code * /// * * * if (userBLL.Edit(ref errors, info)) * { * LogHandler.WriteServiceLog(GetUserId(), "Id:" + info.Id + ",Name:" + info.UserName, "成功", "修改", "用户设置"); * return Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed), JsonRequestBehavior.AllowGet); * } * else * { * string ErrorCol = errors.Error; * LogHandler.WriteServiceLog(GetUserId(), "Id:" + info.Id + ",Name:" + info.UserName + "," + ErrorCol, "失败", "修改", "用户设置"); * return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol), JsonRequestBehavior.AllowGet); * } * } * else * { * return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail), JsonRequestBehavior.AllowGet); * } * */ }
public static CommonResult Login(string username, string password, string clientIp = null, string clientName = null, int nametype = 0, int port = 0) { CommonResult result = new CommonResult() { ResultID = 0 }; if (string.IsNullOrEmpty(username)) { result.Message = "登录失败,用户名输入为空。"; } if (string.IsNullOrEmpty(password)) { result.Message = "登录失败,密码输入为空。"; } EapOracleListProcEntity pe = new EapOracleListProcEntity("usp_GetUserByUserName2"); pe["UserName"] = username; pe["nametype"] = nametype; EAP_User user = null; var users = pe.Execute <EAP_User>(); if (users.Data.Count == 0) { result.Message = "登录失败,用户不存在。"; } else { user = users.Data[0]; if (nametype == 0 && password != DESEncrypt.Decrypt(user.Password)) { result.Message = "登录失败,密码不正确。"; } else if (user.IsLock) { result.Message = "该用户名已经已经停止使用。"; } else { result.ResultID = 1; result.Tag = user; } } #region 记录登录日志 #region get client pc info string serverIP, serverName; DateTime myNow = DateTime.Now; serverName = Dns.GetHostEntry("localhost").HostName; System.Net.IPAddress[] addressList = Dns.GetHostEntry(serverName).AddressList; if (addressList.Length > 0) { int _k = addressList.Length - 1; serverIP = addressList[_k].ToString(); } else { serverIP = addressList[0].ToString(); } serverIP = "1"; #endregion APP_Login info = new APP_Login(); info["USERNAME"] = username; info["SERVERIP"] = serverIP; info["SERVERNAME"] = string.IsNullOrEmpty(serverName) ? "No get." : serverName; info["CLIENTIP"] = clientIp; info["CLIENTNAME"] = string.IsNullOrEmpty(clientName) ? "No get." : clientName; info["LOGINPORT"] = port; info["LOGINTIME"] = DateTime.Now; info["LOGMESSAGE"] = result.Message; info["STATUS"] = result.ResultID; info.Save(); #endregion return(result); }