UserValidatorFactory.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:3k
源码类别:
OA系统
开发平台:
C#
- using System;
- namespace OThinker.H3.Portal
- {
- /// <summary>
- /// Summary description for UserValidatorFactory.
- /// </summary>
- public class UserValidatorFactory
- {
- public UserValidatorFactory()
- {
- }
- public static UserValidator GetValidator(string UserAlias)
- {
- string userId = null;
- if (UserAlias != null && UserAlias != "")
- {
- userId = OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(UserAlias);
- }
- if (userId == null || userId == "")
- {
- return null;
- }
- else
- {
- return new DefaultUserValidator(userId);
- }
- }
- public static UserValidator GetUserValidator(System.Web.UI.Page Page)
- {
- if (Page.Session[OThinker.H3.WorkSheet.Sessions.GetUserValidator()] == null)
- {
- // 从集成验证中获得用户别名
- string loginName = Page.User.Identity.Name;
- string userAlias = null;
- if (loginName != null && loginName.IndexOf("\") != -1)
- {
- userAlias = loginName.Substring(loginName.IndexOf("\") + 1);
- }
- // 获得用户信息
- UserValidator user = GetValidator(userAlias);
- if (user == null)
- {
- // 要求用户登录
- string loginUrl = OThinker.H3.Configs.Config.Current.Web.PortalRoot + "\" + "Login.aspx?q=" + System.Web.HttpUtility.UrlEncode(Page.Request.Url.ToString());
- Page.Response.Redirect(loginUrl);
- }
- else
- {
- Page.Session[OThinker.H3.WorkSheet.Sessions.GetUserValidator()] = GetValidator(userAlias);
- }
- }
- return (Portal.UserValidator)Page.Session[OThinker.H3.WorkSheet.Sessions.GetUserValidator()];
- }
- public static bool ValidateUser(OThinker.Organization.IOrganization Organization, string UserAlias, string Password)
- {
- if (UserAlias == null)
- {
- return false;
- }
- string userId = Organization.GetUserIDByAlias(UserAlias);
- if (userId == null)
- {
- return false;
- }
- OThinker.Organization.User user = (OThinker.Organization.User)Organization.GetUnit(userId);
- if (user == null)
- {
- return false;
- }
- else if (user.Password != Password)
- {
- return false;
- }
- return true;
- }
- }
- }