public override void Login(string username, string password) { List <SYSUSEREntity> users = _db.SelectList(new SYSUSEREntity() { USERCODE = username }); if (users.IsEmpty()) { throw new Exception("找不到用户"); } else if (users.Where(a => a.USER_FLAG.ToInt() == (int)用户标记.正常).IsEmpty()) { throw new Exception($"用户已{users.First().USER_FLAG.ToEnum<用户标记>() }"); } else { SYSUSEREntity user = users.First(); if (Verify(user, password)) { Employee e = GetUser(user.USERID); ApplicationContextBase.GetContext().SetData(LoginKey + e.Id, users); ApplicationContextBase.GetContext().principal = new GenericPrincipal(new GenericIdentity(e.Id), null); FormsAuthentication.SetAuthCookie(e.Id, true); } else { throw new Exception("密码错误"); } } }
public override T GetUser <T>(bool throwError = true) { string key = ApplicationContextBase.GetContext()?.principal?.Identity.Name; T e = ApplicationContextBase.GetContext().GetData <T>(LoginKey + key); if (!key.IsEmpty() && e == null && ApplicationContextBase.GetContext().principal != null) { SYSUSEREntity user = _db.Select(new SYSUSEREntity(key)); if (user == null) { throw new NoLoginException(); } return(GetUser(user.USERID) as T); } if (e == null) { if (ConfigExtension.TestModel)//测试模式 { var teste = new Employee() { Id = ConfigExtension.TestModel_User, Name = $"测试模式:{ConfigExtension.TestModel_User}", PlatformId = "" } as T; return(teste); } if (throwError) { throw new NoLoginException(); } } return(e); }
public void ChangePs(SYSUSEREntity data) { SYSUSEREntity sysuser = DbHelper.Select(new SYSUSEREntity() { USERID = employee.Id }); sysuser.PASSWORD = salt(sysuser.USERID, data.PASSWORD); DbHelper.Save(sysuser); }
public UIResult SearchUser(SYSUSEREntity Data) { var res = service.UserService.GetUserElement(Data); return(new UIResult( new { user = res.Item1, userrole = res.Item2 } )); }
/// <summary> /// /// </summary> /// <param name="Id"></param> /// <returns></returns> public Employee GetUser(string Id) { SYSUSEREntity user = _db.Select(new SYSUSEREntity(Id)); Employee e = new Employee() { Id = user.USERID, Name = user.USERNAME, PlatformId = "" }; e.PermissionHandle = HasPermission; return(e); }
public string Save(SYSUSEREntity DefineSave) { var v = GetVerify(DefineSave); if (DefineSave.USERID.IsEmpty()) { DefineSave.USERID = service.CommonService.NewINC("SYSUSER"); } v.IsUnique(a => a.USERID); v.IsUnique(a => a.USERCODE); v.Require(a => a.USERNAME); v.Require(a => a.USER_TYPE); v.Require(a => a.ORGID); v.Verify(); return(CommonSave(DefineSave)); }
public string SaveSysUser(SYSUSEREntity data) { var v = GetVerify(data); if (data.USERID.IsEmpty()) { data.USERID = NewINC("SYSUSER"); data.PASSWORD = salt(data.USERID, data.PASSWORD); } else { if (data.PASSWORD.IsEmpty()) { SYSUSEREntity sysuser = DbHelper.Select(new SYSUSEREntity() { USERID = data.USERID }); data.PASSWORD = sysuser.PASSWORD; } else { data.PASSWORD = salt(data.USERID, data.PASSWORD); } } v.Require(a => a.USERID); v.IsUnique(a => a.USERID); v.Require(a => a.USERCODE); v.IsUnique(a => a.USERCODE); v.Require(a => a.USERNAME); v.IsUnique(a => a.USERNAME); v.Require(a => a.VOID_FLAG); v.Verify(); using (var Tran = DbHelper.BeginTransaction()) { data.USER_ROLE?.ForEach(menu => { GetVerify(menu).Require(a => a.ROLEID); }); DbHelper.Save(data); Tran.Commit(); } return(data.USERID); }
public Tuple <dynamic, DataTable> GetUserElement(SYSUSEREntity Data) { string sql = $@"select A.USERID,A.USERCODE,A.USERNAME,A.USER_TYPE,A.ORGID,to_char(A.USER_FLAG) USER_FLAG,"; sql += " to_char(A.VOID_FLAG) VOID_FLAG,B.ORGIDCASCADER from SYSUSER A,ORG B where A.ORGID=B.ORGID(+) "; if (!Data.USERID.IsEmpty()) { sql += " and A.USERID = " + Data.USERID; } DataTable user = DbHelper.ExecuteTable(sql); string sqlUserRole = $@"select A.USERID,B.ROLEID,B.ROLECODE,B.ROLENAME,C.ORGNAME from USER_ROLE A,ROLE B,ORG C where A.ROLEID=B.ROLEID and B.ORGID=C.ORGID(+) "; if (!Data.USERID.IsEmpty()) { sqlUserRole += " and A.USERID = " + Data.USERID; } DataTable userrole = DbHelper.ExecuteTable(sqlUserRole); return(new Tuple <dynamic, DataTable>(user.ToOneLine(), userrole)); }
public void Delete(SYSUSEREntity DefineDelete) { var v = GetVerify(DefineDelete); CommenDelete(DefineDelete); }
public string Save(SYSUSEREntity DefineSave) { return(service.HomeService.SaveSysUser(DefineSave)); }
public string salt(SYSUSEREntity user, string psw) { return(MD5Encryption.Encrypt(user.USERID + LoginSalt + psw)); }
bool Verify(SYSUSEREntity user, string password) { return(user.PASSWORD == salt(user, password)); }
public void ChangePsw(SYSUSEREntity data) { service.HomeService.ChangePs(data); }