Beispiel #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("密码错误");
                }
            }
        }
Beispiel #2
0
 public override void LogOut()
 {
     if (HasLogin)
     {
         ApplicationContextBase.GetContext().RemoveData(LoginKey + GetUser <User>().Id);
     }
 }
Beispiel #3
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);
        }
Beispiel #4
0
        public override T GetUser <T>(bool throwError = true)
        {
            if (ConfigExtension.TestModel)//测试模式
            {
                ServiceUser teste = new ServiceUser()
                {
                    Id         = ConfigExtension.TestModel_User,
                    Name       = $"测试模式:{ConfigExtension.TestModel_User}",
                    PlatformId = "-1"
                };
                return(teste as T);
            }
            string key  = ApplicationContextBase.GetContext()?.principal?.Identity.Name;
            T      user = GetUserByKey <T>(key);

            if (user == null)
            {
                if (throwError)
                {
                    throw new NoLoginException();
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(user);
            }
        }
Beispiel #5
0
 public override void Login(string username, string password)
 {
     Model.User user = service.GetUserByCode(username, password).ToObj(a => new User()
     {
         Id = a.Id, Name = a.Name
     });
     ApplicationContextBase.GetContext().SetData(LoginKey + user.Id, user);
     ApplicationContextBase.GetContext().principal = new GenericPrincipal(new GenericIdentity(user.Id), null);
 }
Beispiel #6
0
 public override int Logins(string username, string password)
 {
     Model.User user = service.GetUserByCode(username, password).ToObj(a => new User()
     {
         Id = a.Id, Name = a.Name
     });
     ApplicationContextBase.GetContext().SetData(LoginKey + user.Id, user);
     ApplicationContextBase.GetContext().principal = new GenericPrincipal(new GenericIdentity(user.Id), null);
     FormsAuthentication.SetAuthCookie(user.Id, true);
     return(0);
 }
Beispiel #7
0
 public override void Login(string username, string password)
 {
     if (username.IsEmpty())
     {
         if (ConfigExtension.TestModel)//测试模式
         {
             return;
         }
         throw new NoLoginException();
     }
     //------------这里接入验证登陆和权限配置
     if (GetUserByKey <ServiceUser>(username) != null)
     {
         ApplicationContextBase.GetContext().principal = new GenericPrincipal(new GenericIdentity(username), null);
     }
     else
     {
         throw new NoLoginException();
     }
 }
Beispiel #8
0
        public override T GetUser <T>(bool throwError = true)
        {
            if (ConfigExtension.TestModel)//测试模式
            {
                Employee teste = new Employee()
                {
                    Id         = ConfigExtension.TestModel_User,
                    Name       = $"测试模式:{ConfigExtension.TestModel_User}",
                    PlatformId = ""
                };
                teste.PermissionHandle = HasPermission;
                return(teste as T);
            }
            string key = ApplicationContextBase.GetContext()?.principal?.Identity.Name;
            T      e   = ApplicationContextBase.GetContext().GetData <T>(LoginKey + key);

            if (!key.IsEmpty() && e == null && ApplicationContextBase.GetContext().principal != null)
            {
                User user = service.GetUserById(key)?.ToObj(a => new User()
                {
                    Id = a.Id, Name = a.Name
                });
                if (user == null)
                {
                    throw new NoLoginException();
                }
                Employee emp = new Employee()
                {
                    Id         = user.Id,
                    Name       = user.Name,
                    PlatformId = ""
                };
                emp.PermissionHandle = HasPermission;
                return(emp as T);
            }
            if (e == null && throwError)
            {
                throw new NoLoginException();
            }
            return(e);
        }