UserValidatorFactory.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:3k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. namespace OThinker.H3.Portal
  3. {
  4.     /// <summary>
  5.     /// Summary description for UserValidatorFactory.
  6.     /// </summary>
  7.     public class UserValidatorFactory
  8.     {
  9.         public UserValidatorFactory()
  10.         {
  11.         }
  12.         public static UserValidator GetValidator(string UserAlias)
  13.         {
  14.             string userId = null;
  15.             if (UserAlias != null && UserAlias != "")
  16.             {
  17.                 userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(UserAlias);
  18.             }
  19.             if (userId == null || userId == "")
  20.             {
  21.                 return null;
  22.             }
  23.             else
  24.             {
  25.                 return new DefaultUserValidator(userId);
  26.             }
  27.         }
  28.         public static UserValidator GetUserValidator(System.Web.UI.Page Page)
  29.         {
  30.             if (Page.Session[OThinker.H3.WorkSheet.Sessions.GetUserValidator()] == null)
  31.             {
  32.                 // 从集成验证中获得用户别名
  33.                 string loginName = Page.User.Identity.Name;
  34.                 string userAlias = null;
  35.                 if (loginName != null && loginName.IndexOf("\") != -1)
  36.                 {
  37.                     userAlias = loginName.Substring(loginName.IndexOf("\") + 1);
  38.                 }
  39.                 // 获得用户信息
  40.                 UserValidator user = GetValidator(userAlias);
  41.                 if (user == null)
  42.                 {
  43.                     // 要求用户登录
  44.                     string loginUrl = OThinker.H3.Configs.Config.Current.Web.PortalRoot + "\" + "Login.aspx?q=" + System.Web.HttpUtility.UrlEncode(Page.Request.Url.ToString());
  45.                     Page.Response.Redirect(loginUrl);
  46.                 }
  47.                 else
  48.                 {
  49.                     Page.Session[OThinker.H3.WorkSheet.Sessions.GetUserValidator()] = GetValidator(userAlias);
  50.                 }
  51.             }
  52.             return (Portal.UserValidator)Page.Session[OThinker.H3.WorkSheet.Sessions.GetUserValidator()];
  53.         }
  54.         public static bool ValidateUser(OThinker.Organization.IOrganization Organization, string UserAlias, string Password)
  55.         {
  56.             if (UserAlias == null)
  57.             {
  58.                 return false;
  59.             }
  60.             string userId = Organization.GetUserIDByAlias(UserAlias);
  61.             if (userId == null)
  62.             {
  63.                 return false;
  64.             }
  65.             OThinker.Organization.User user = (OThinker.Organization.User)Organization.GetUnit(userId);
  66.             if (user == null)
  67.             {
  68.                 return false;
  69.             }
  70.             else if (user.Password != Password)
  71.             {
  72.                 return false;
  73.             }
  74.             return true;
  75.         }
  76.     }
  77. }