예제 #1
0
        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("密码错误");
                }
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
파일: HomeService.cs 프로젝트: wkxuan/code
        public void ChangePs(SYSUSEREntity data)
        {
            SYSUSEREntity sysuser = DbHelper.Select(new SYSUSEREntity()
            {
                USERID = employee.Id
            });

            sysuser.PASSWORD = salt(sysuser.USERID, data.PASSWORD);
            DbHelper.Save(sysuser);
        }
예제 #4
0
        public UIResult SearchUser(SYSUSEREntity Data)
        {
            var res = service.UserService.GetUserElement(Data);

            return(new UIResult(
                       new
            {
                user = res.Item1,
                userrole = res.Item2
            }
                       ));
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        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));
        }
예제 #7
0
파일: HomeService.cs 프로젝트: wkxuan/code
        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);
        }
예제 #8
0
        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));
        }
예제 #9
0
        public void Delete(SYSUSEREntity DefineDelete)
        {
            var v = GetVerify(DefineDelete);

            CommenDelete(DefineDelete);
        }
예제 #10
0
 public string Save(SYSUSEREntity DefineSave)
 {
     return(service.HomeService.SaveSysUser(DefineSave));
 }
예제 #11
0
 public string salt(SYSUSEREntity user, string psw)
 {
     return(MD5Encryption.Encrypt(user.USERID + LoginSalt + psw));
 }
예제 #12
0
 bool Verify(SYSUSEREntity user, string password)
 {
     return(user.PASSWORD == salt(user, password));
 }
예제 #13
0
 public void ChangePsw(SYSUSEREntity data)
 {
     service.HomeService.ChangePs(data);
 }