public bool CheckToken(string userId) { string userkey = Sys_User.GetKey(userId); var user = CacheManager.GetData <Sys_User>(userkey); return(user != null); }
public IActionResult ModifyUserPwd(string password, string userName) { WebResponseContent webResponse = new WebResponseContent(); if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(userName)) { return(Json(webResponse.Error("参数不完整"))); } if (password.Length < 6) { return(Json(webResponse.Error("密码长度不能少于6位"))); } ISys_UserRepository repository = Sys_UserRepository.Instance; Sys_User user = repository.FindFirst(x => x.UserName == userName); if (user == null) { return(Json(webResponse.Error("用户不存在"))); } user.UserPwd = password.EncryptDES(AppSetting.Secret.User); repository.Update(user, x => new { x.UserPwd }, true); //如果用户在线,强制下线 UserContext.Current.LogOut(user.User_Id); return(Json(webResponse.OK("密码修改成功"))); }
public ActionResult Form(Sys_User model, string password, string roleIds) { if (model.Id.IsNullOrEmpty()) { //新增用户基本信息。 var userId = _userService.Insert(model).ToString(); //新增用户角色信息。 _userRoleRelationService.SetRole(userId, roleIds.ToStrArray()); //新增用户登陆信息。 Sys_UserLogOn userLogOnEntity = new Sys_UserLogOn() { UserId = userId, Password = password }; var userLoginId = _userLogOnService.Insert(userLogOnEntity); return(userId != null && userLoginId != null?Success() : Error()); } else { //更新用户基本信息。 int row = _userService.Update(model); //更新用户角色信息。 _userRoleRelationService.SetRole(model.Id, roleIds.ToStrArray()); return(row > 0 ? Success() : Error()); } }
public UserState(Sys_User user) { var listRoles = new List <UserRole>(); UserName = user.UserCode; IsSysAdmin = user.IsSysAdmin; //ListAccess = user.ListAccess; // mặc định gán listRoles.Add(UserRole.TrustedMember); Role = UserRole.TrustedMember; if (IsSysAdmin) { // nếu có quyền SysAdmin => gán bằng quyền SysAdmin listRoles.Add(UserRole.SysAdmin); Role = UserRole.SysAdmin; } if (listRoles.Count > 0) { Roles = new List <UserRole>(); Roles.AddRange(listRoles); user.Roles = new List <UserRole>(); user.Roles.AddRange(listRoles); } this.SysUser = user; }
public ActionResult SubmitResetPassword(string password, string oldPassword, string verifyCode) { //verifyCode = Md5Helper.Encrypt(verifyCode.ToLower(), 16); //string code = SessionHelper.Get("CheckCode"); string code = WebHelper.GetSession("session_verifycode"); WebHelper.RemoveSession("session_verifycode"); if (string.IsNullOrWhiteSpace(code) || verifyCode.ToUpper() != code.ToUpper()) { return(Fail("验证码错误,请重新输入")); } Sys_User user = _user.GetUserInfoById(WebSecurityHelper.Passport.Current.UserId); if (user.UserType == 1007001) { return(Fail("当前账户不能修改密码")); } if (oldPassword.ToUpper() != user.UserPassWord) { return(Fail("原密码错误,请重新输入")); } _user.UpdateUserPWd(user.Id, password); Session.Abandon(); Session.Clear(); OperatorHelper.Instance.EmptyCurrent(); return(Success("密码修改成功,请牢记新密码。\r 将会自动安全退出。")); }
/// <summary> /// 修改密码 /// </summary> /// <param name="userId">用户Id</param> /// <param name="newPwd">新密码</param> /// <param name="errMsg">错误信息</param> /// <returns></returns> public static bool ModifyPassword(Guid userId, string newPwd, out string errMsg) { errMsg = string.Empty; if (ModelConfigHelper.ModelIsViewMode(typeof(Sys_User))) { errMsg = "用户管理模块为视图模式不允许更新密码!"; return(false); } Sys_User user = CommonOperate.GetEntity <Sys_User>(x => x.Id == userId && !x.IsDeleted && x.IsValid && x.IsActivated, string.Empty, out errMsg); if (user == null) { errMsg = "非法用户!"; return(false); } //获取混淆码 string passwordSalt = SecurityHelper.GenerateSalt(); //获取混淆码加密过的密码 string passwordHash = SecurityHelper.EncodePassword(newPwd, passwordSalt); //SecurityHelper.EncodePassword(MySecurity.MD5(newPwd), passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; Guid rs = CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>() { "PasswordHash", "PasswordSalt" }, false); if (rs != Guid.Empty) //修改密码成功 { errMsg = TempUserOperate(userId, newPwd); } return(string.IsNullOrEmpty(errMsg)); }
public ActionResult SubmitForm(Sys_ItemsDetail itemsDetailEntity, string keyValue) { try { bool i = false; Sys_User uInfo = ViewData["Account"] as Sys_User; if (keyValue == "" || keyValue == null) { itemsDetailEntity.F_CreatorUserId = OperatorProvider.Provider.GetCurrent().UserCode; itemsDetailEntity.F_CreatorTime = DateTime.Now; itemsDetailEntity.F_Id = System.Guid.NewGuid().ToString(); i = itemsDetailApp.Add(itemsDetailEntity); } else { itemsDetailEntity.F_Id = keyValue; itemsDetailEntity.F_LastModifyUserId = OperatorProvider.Provider.GetCurrent().UserCode; itemsDetailEntity.F_LastModifyTime = DateTime.Now; string[] notstr = { "F_CreatorUserId", "F_CreatorTime", "F_ParentId", "F_ItemId" }; i = itemsDetailApp.Update(itemsDetailEntity, notstr); } if (i) { return(Success()); } else { return(Warning()); } } catch (Exception ex) { return(Error(ex.Message)); } }
public IActionResult CreateUser([FromBody] SysUserCreateOrUpdateViewModel model) { var response = ResponseModelFactory.CreateInstance; var data = _sysUserRepo.FindEntity(x => x.LoginName == model.LoginName); if (data != null) { response.SetFailed("登录名已存在"); return(Ok(response)); } //if (!AuthContextService.IsAdministrator) //{ // response.SetFailed("权限不足"); // return Ok(response); //} Sys_User adduser = new Sys_User(); _mapper.Map(model, adduser); // adduser.Password = CrypToHelper.HashPassword(model.Password); adduser.Create(); _sysUserRepo.Insert(adduser); if (!_unitOfWork.Save()) { response.SetFailed("添加失败"); return(Ok(response)); } response.SetData(adduser.Id); return(Ok(response)); }
/// <summary> /// Update password of a specified user /// </summary> /// <param name="userName">Name of user who will be changed password</param> /// <param name="password">New password</param> public void UpdateNewPassword(string userName, string password) { const string METHOD_NAME = THIS + ".UpdateNewPassword()"; try { using (var trans = new TransactionScope()) { var dcPCS = new PCSDataContext(Utils.Instance.ConnectionString); Sys_User current = dcPCS.Sys_Users.SingleOrDefault(u => u.UserName == userName); if (current != null) { current.Pwd = CryptoUtil.EncryptPassword(password); // submit changes dcPCS.SubmitChanges(); } trans.Complete(); } } catch (SqlException ex) { if (ex.Errors.Count > 1) { if (ex.Number == ErrorCode.SQLDUPLICATE_KEYCODE) { throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex); } throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex); } }
public JsonResult CheckPassword(string OldPassword) { JsonResult result = new JsonResult(); int userId = Convert.ToInt32(Session["UserId"]); Sys_User detail = up.getUesrDetailByUserId(userId); string dbOldPassword = detail.Password; string dbpasswordSalt = detail.PasswordSalt; string OldpasswordHash = CryptoService.GenerateSHA256Hash(OldPassword, dbpasswordSalt); //var checkOldPass = up.CheckOldPassword(OldpasswordHash); var matching = ddl.CheckPassword(OldpasswordHash, userId); if (matching != null) { result.Data = ""; return(result); } else { result.Data = "Incorrect Password!!!"; return(result); } }
public ActionResult SubmitForm(Sys_User userEntity, string keyValue) { try { bool i = false; if (keyValue == "" || keyValue == null) { userEntity.F_CreatorUserId = OperatorProvider.Provider.GetCurrent().UserCode; userEntity.F_CreatorTime = DateTime.Now; userEntity.F_Id = System.Guid.NewGuid().ToString(); i = userApp.Add(userEntity); } else { userEntity.F_Id = keyValue; userEntity.F_LastModifyUserId = OperatorProvider.Provider.GetCurrent().UserCode; userEntity.F_LastModifyTime = DateTime.Now; string[] notstr = { "F_Password", "F_HeadIcon", "F_SecurityLevel", "F_Signature", "F_CreatorUserId", "F_CreatorTime" }; i = userApp.Update(userEntity, notstr); } if (i) { return(Success()); } else { return(Warning()); } } catch (Exception ex) { return(Error(ex.Message)); } }
public JsonResult Login(Sys_User entity) { try { int a = 10; int b = 0; int c = a / b; } catch (Exception ex) { NLogUtil.Error(ex.ToString()); //throw; } Sys_User user = _sysUserService.LoadEntities(c => c.UserName.Equals(entity.UserName)).SingleOrDefault(); if (user == null) { return(Json(new { state = 201, message = "用户名或密码错误" }, JsonRequestBehavior.AllowGet)); } if (user.PassWord.Equals(EncryptUtil.Md5(entity.PassWord))) { Session["YD_USER"] = user; string ip = Request.UserHostAddress; Sys_Log log = _logService.AddEntity(new Sys_Log { OccurTime = DateTime.Now, UserId = user.Id, Type = 1, LoginIp = ip }); return(Json(new { state = 200, messgae = "登录成功" }, JsonRequestBehavior.AllowGet)); } return(Json(new { state = 201, message = "用户名或密码错误" }, JsonRequestBehavior.AllowGet)); }
public override bool ValidateUser(string username, string password) { bool isValid = false; bool isApproved = false; Sys_User user = _userRepository.GetUser_IsNotLockedOut(ApplicationName, username); if (user == null) { return(false); } string pwd = user.Password; isApproved = user.IsApproved == 1 ? true : false; if (CheckPassword(password, pwd, user.PasswordKey)) { if (isApproved) { isValid = true; _userRepository.UpdateLogonDate(ApplicationName, username, DateTime.Now, DateTime.Now); } } else { UpdateFailureCount(username, "password"); } return(isValid); }
/// <summary> /// 批量禁用用户 /// </summary> /// <param name="vguid"></param> /// <returns></returns> public bool DisableUser(string vguid) { using (SqlSugarClient _dbMsSql = SugarDao_MsSql.GetInstance()) { bool result = false; Guid Vguid = Guid.Parse(vguid); try { _dbMsSql.BeginTran(); result = _dbMsSql.Update <Sys_User>(new { Enable = "0" }, i => i.Vguid == Vguid); Sys_User userInfo = _dbMsSql.Queryable <Sys_User>().Where(i => i.Vguid == Vguid).SingleOrDefault(); string weChatJson = JsonHelper.ModelToJson <Sys_User>(userInfo); ////存入操作日志表 _logLogic.SaveLog(16, 26, Common.CurrentUser.GetCurrentUser().LoginName, userInfo.LoginName, weChatJson); _dbMsSql.CommitTran(); } catch (Exception ex) { _dbMsSql.RollbackTran(); Common.LogHelper.LogHelper.WriteLog(ex.Message); } finally { } return(result); } }
/// <summary> /// 获取用户信息 /// </summary> /// <param name="user">用户对象</param> /// <returns></returns> private static UserInfo GetUserInfo(Sys_User user) { if (user == null || string.IsNullOrEmpty(user.UserName)) { return(null); } UserInfo userInfo = new UserInfo() { UserId = user.Id, UserName = user.UserName, AliasName = string.IsNullOrEmpty(user.AliasName) ? user.UserName : user.AliasName, OrganizationId = user.Sys_OrganizationId }; //员工信息 OrgM_Emp emp = OrgMOperate.GetEmpByUserName(user.UserName); if (emp != null) { userInfo.EmpId = emp.Id; userInfo.EmpCode = emp.Code; userInfo.EmpName = emp.Name; } userInfo.ExtendUserObject = UserExtendEventHandler.GetUserExtendInfo(userInfo); return(userInfo); }
/// <summary> /// 添加外聘讲师 /// </summary> /// <param name="user"></param> /// <returns></returns> public JsonResult AddOuterTeacher(Sys_User user) { try { if (user.UserId == 0) { user.Realname = user.Realname.Trim(); userBL.InsertOuterTeacher(user); } else { user.JobNum = ""; user.Password = ""; user.Username = ""; user.IsTeacher = 2; userBL.Update(user); } return(Json(new { result = 1, content = "添加成功" }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { result = 0, content = "添加失败" }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 账户是否有效 /// </summary> /// <param name="username"></param> /// <param name="errMsg">异常信息</param> /// <returns></returns> public static bool UserIsValid(string username, out string errMsg) { errMsg = string.Empty; Sys_User tempUser = CommonOperate.GetEntity <Sys_User>(x => !x.IsDeleted && x.IsValid && x.IsActivated && x.UserName.ToLower() == username.Trim().ToLower(), string.Empty, out errMsg); return(tempUser != null); }
protected void Save_Btn(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.Oldpwd.Value) && !string.IsNullOrEmpty(this.newpwd.Value)) { if (this.newpwd.Value.Trim() == this.newpwd1.Value.Trim()) { IList all = Sys_User.Init().GetAll(string.Concat(new string[] { "id=", this.Uid, " and password='******'" }), null); if (all.Count > 0) { Sys_UserInfo sys_UserInfo = all[0] as Sys_UserInfo; sys_UserInfo.PassWord = Encrypt.MD5_32(this.newpwd.Value.Trim().ToLower()); Sys_User.Init().Update(sys_UserInfo); Help.UpdateIMUser(sys_UserInfo); base.Response.Write("<script>alert('您好!密码已修改成功!');window.location='" + base.Request.Url.AbsoluteUri + "'</script>"); } else { base.Response.Write("<script>alert('原密码不正确,请重新输入!');window.location='" + base.Request.Url.AbsoluteUri + "'</script>"); } } else { base.Response.Write("<script>alert('确认密码 不一致,请重新输入!');window.location='" + base.Request.Url.AbsoluteUri + "'</script>"); } } }
/// <summary> /// 修改用户别名 /// </summary> /// <param name="username">用户名</param> /// <param name="aliasName">用户别名</param> /// <returns></returns> public static string UpdateUserAliasName(string username, string aliasName) { if (ModelConfigHelper.ModelIsViewMode(typeof(Sys_User))) { return("用户管理模块为视图模式不允许更新用户别名!"); } if (string.IsNullOrWhiteSpace(aliasName)) { return("用户别名不能为空!"); } string errMsg = string.Empty; Sys_User user = CommonOperate.GetEntity <Sys_User>(x => x.UserName == username, null, out errMsg); if (user == null) { return("用户信息不存在!"); } if (user.AliasName != aliasName) { user.AliasName = aliasName; Guid rs = CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>() { "AliasName" }, false); } return(errMsg); }
/// <summary> /// 检查账号密码是否正确 /// </summary> /// <param name="userName"></param> /// <param name="passWord"></param> /// <returns></returns> public Sys_User CheckUser(string userName, string passWord) { Sys_User result = null; try { if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(passWord)) { return(result); } using (var db = SugarDao.GetInstance()) { string uName = userName.ToLower(); string pwd = MD5Encrypt.Encrypt(passWord); result = db.Queryable <Sys_User>().FirstOrDefault(t => t.Account == uName && t.Password == pwd && t.IsEnabled); } return(result); } catch (Exception) { throw; } }
/// <summary> /// 获取签到详情 /// </summary> /// <param name="teacher">教师</param> /// <param name="time">时间</param> /// <param name="section">节次</param> /// <returns></returns> public AttendanceDetailResult AttendanceRecord(string teacher, string time, string section) { Sys_User user = null; if (teacher != null) { user = UserService.GetEntity(u => u.F_Account == teacher || u.F_RealName == teacher).FirstOrDefault(); } SchollTime schollTime = CourseService.GetSchollTime(time); var courses = FilterForCondition(schollTime, teacher, section); var result = new AttendanceDetailResult(); if (courses == null || courses.Count() == 0) { result.Message = "查询不到符合该条件的课程"; return(result); } var attendanceDetails = GetAttendanceDetailsForCourses(courses, schollTime, user); if (attendanceDetails == null || attendanceDetails.Count() == 0) { result.Message = "该教师今天有课程,但并没有发起签到"; result.ResultCode = ResultCode.Error; } else { result.Data = attendanceDetails; result.ResultCode = ResultCode.Ok; } return(result); }
public IHttpActionResult empinsert(Sys_User empinsert) { var insert = cm.Sys_User.Add(empinsert); cm.SaveChanges(); return(Ok()); }
public ActionResult UserManagementDetail() { bool isEdit = bool.Parse(Request.QueryString["isEdit"]); //绑定角色 List <Sys_Role> sysRoleList = new List <Sys_Role>(); sysRoleList = _ul.GetSysRoleList(); ViewData["SysRoleList"] = sysRoleList; //绑定公司 // List<Master_Organization> companyList = new List<Master_Organization>(); // companyList = _ul.GetCompanyList(); // ViewData["CompanyList"] = companyList; List <Master_Organization> departmentList = new List <Master_Organization>(); Sys_User sysRoleModel = new Sys_User(); if (isEdit) { string vguid = Request.QueryString["Vguid"]; sysRoleModel = _ul.GetUserInfoByVguid(vguid); // departmentList = GetDepartmentListByEdit(sysRoleModel.Company.ToString()); } Sys_Role_Module roleModuleModel = _al.GetRoleModulePermission(Common.CurrentUser.GetCurrentUser().Role, Common.Tools.ModuleVguid.UserSystemModule); ViewBag.DepartmentList = departmentList; ViewBag.CurrentModulePermission = roleModuleModel; ViewBag.UserInfo = sysRoleModel; ViewBag.isEdit = isEdit; return(View()); }
/// <summary> /// 操作完成后 /// </summary> /// <param name="operateType"></param> /// <param name="t"></param> /// <param name="result"></param> /// <param name="currUser"></param> /// <param name="otherParams"></param> public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_EmpDeptDuty t, bool result, UserInfo currUser, object[] otherParams = null) { if (result) { string errMsg = string.Empty; if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit) { if (t.OrgM_EmpId.HasValue && t.OrgM_EmpId.Value != Guid.Empty && t.OrgM_DeptId.HasValue && t.OrgM_DeptId.Value != Guid.Empty) { OrgM_Dept dept = OrgMOperate.GetDeptById(t.OrgM_DeptId.Value); string username = OrgMOperate.GetUserNameByEmpId(t.OrgM_EmpId.Value); if (!string.IsNullOrEmpty(username) && dept != null) { Sys_User user = UserOperate.GetUser(username); Sys_Organization org = UserOperate.GetAllOrgs(x => x.Name == dept.Name && x.Flag == dept.Id.ToString()).FirstOrDefault(); if (user != null && org != null && user.Sys_OrganizationId != org.Id) { user.Sys_OrganizationId = org.Id; CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>() { "Sys_OrganizationId" }, false); } } } } } }
public ActionResult Add(AddUserInput input) { var services = CreateService <IAccountAppService>(); if (services.ExistUserName(input.UserName)) { throw new InvalidDataException("用户名[{0}]已存在".ToFormat(input.UserName)); } else { string userSecretkey = UserHelper.GenUserSecretkey(); string encryptedPassword = PasswordHelper.Encrypt(input.Password, userSecretkey); Sys_User user = new Sys_User { UserName = input.UserName, RoleId = input.RoleId, RealName = input.RealName, IsEnabled = input.IsEnabled, Description = input.Description, UserSecretkey = userSecretkey, UserPassword = encryptedPassword, CreateUserId = CurrentSession.UserId, CreateTime = DateTime.Now, LogOnCount = 0 }; services.Insert(user); } return(AddSuccessMsg()); }
private void Show() { Sys_UserInfo byId = Sys_User.Init().GetById(Convert.ToInt32(this.Uid)); this.userlist.Value = (byId.et6 ?? ""); this.namelist.Value = (byId.et5 ?? ""); }
public JsonResult SaveUserBaseInfo(string idcard, string mobnum, string email, string memo, string photoUrl) { try { Sys_User user = CurrentUser; user.IdCardNo = idcard; user.MobileNum = mobnum; user.Email = email; user.Memo = memo; user.PhotoUrl = photoUrl; bool result = userBL.Update(user); if (result) { CurrentUser = user; } return(Json(new { result = result ? 1 : 0, content = result ? "保存成功" : "保存失败" }, JsonRequestBehavior.DenyGet)); } catch { return(Json(new { result = 0, content = "保存失败" }, JsonRequestBehavior.DenyGet)); } }
/// <summary> /// API用户过期信息缓存 /// </summary> public void SetUserCacheAPI(Sys_User user) { //生成用户token var token = Sys_User.GetKey(user.UserId); CacheManager.Add(token, user, 12 * 60); }
public int Insert(UserVM form) { //string sql = "insert into Sys_User (UserName) values (@0)"; //SqlParameter[] parameter = new SqlParameter[] { // new SqlParameter("@0", SqlDbType.VarChar, 50) //}; //parameter[0].Value = user.UserName; //return this.userRepository.ExecuteSqlCommand(ContextDB.managerDBContext, sql, parameter); //return this.userRepository.Insert(ContextDB.managerDBContext, user); //SqlParameter[] parameters = { // new SqlParameter("@UserName", user.UserName), // new SqlParameter("@Ret", SqlDbType.Int) //}; //parameters[1].Direction = ParameterDirection.Output; //var result = ContextDB.managerDBContext.Database.ExecuteSqlCommand("exec proc_userInsert @UserName, @Ret out", parameters); //int ret = (int)parameters[1].Value; // SqlParameter[] p = //{ // SqlHelper.MakeInParam("@UserId",SqlDbType.VarChar,20,UserId), // SqlHelper.MakeInParam("@Pwd",SqlDbType.VarChar,50,Pwd) // }; Sys_User model = new Sys_User(); Ext.CopyFrom(model, form); model.UpdateDate = DateTime.Now; model.Password = MD5Encrypt.Encrypt(model.Password); return(this._userRepository.Insert(ContextDB.managerDBContext, model)); }
public bool InsertPersonInfo(Sys_User User, string CreatorId) { OracleHelper _oraDal = new OracleHelper(); string LookSql = string.Format("select USERNAME from BANK_USER where USERNAME='******'", User.UserName); var LookDt = _oraDal.ExecuteQuery(LookSql); if (LookDt.Rows.Count > 0) { return(false); } string sql = string.Format("Insert into BANK_USER (USERNAME,PASSWORD,REALNAME,HEADICON,MOBILEPHONE,WECHAT,DEPARTMENTID,DESCRIPTION,CREATIONTIME,CREATEUSERID,GENDER) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},'{9}','{10}')", User.UserName, DESEncrypt.Encrypt("123456"), User.RealName, User.HeadIcon, User.MobilePhone, User.WeChat, User.DepartmentId, User.Description, "SYSDATE", CreatorId, User.Gender); int result = _oraDal.ExecuteSQL(sql); if (result > 0) { return(true); } else { return(false); } }