/// <summary> /// 请求用户授权Token /// </summary> /// <param name="authorize"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAuthorize Authorize(SYSAuthorizeDTO authorize) { //检查请求参数 if (string.IsNullOrEmpty(authorize.response_type)) { throw CFException.Create(STDAuthorizeResult.ResponseTypeInvalid); } if (string.IsNullOrEmpty(authorize.client_id)) { throw CFException.Create(STDAuthorizeResult.ClientIDInvalid); } try { //检查应用代码 var certificate = _certificateRepository.Get(item => item.ApiKey == authorize.client_id); if (certificate.ID == null) { throw CFException.Create(STDAuthorizeResult.ClientIDInvalid); } //创建授权码 string code = ALUtils.GetGUIDShort(); CacheService.Default.GetOrAdd("STDAuthorizeDTO_" + code, authorize, 10); //HttpRuntime.Cache.Add("STDAuthorizeDTO_" + code, authorize, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); return(new SYSAuthorize(code, authorize.state)); } catch (Exception ex) { throw CFException.Create(STDAuthorizeResult.Fail, ex.Message, ex); } }
/// <summary> /// 将操作附加到资源点 /// </summary> /// <returns></returns> public SYSOperation OperationInject(SYSOperationDTO dto) { if (string.IsNullOrEmpty(dto.OperationCode) || string.IsNullOrEmpty(dto.OperationName)) { throw CFException.Create(SYSOperationInjectResult.NameOrCodeNotFound); } try { //tag class 待确定 var prevCertificate = _operationRepository.Get(new EntitySpec <SYSOperation>(query => { query.SystemID = CurrentSystemId; query.OperationCode = dto.OperationCode; })); if (prevCertificate.ID.HasValue) { throw CFException.Create(SYSOperationInjectResult.CodeAlreadyExists); } SYSOperation entity = dto.Map <SYSOperationDTO, SYSOperation>(); entity.SystemID = CurrentSystemId; entity.InputTime = DateTime.Now; entity.Inputer = CFContext.User.UserName; entity.InputerID = CFContext.User.ID; _operationRepository.Add(entity); //粘贴tag return(entity); } catch (Exception ex) { throw CFException.Create(SYSOperationInjectResult.Fail, ex); } }
/// <summary> /// 将操作附加到资源点 /// </summary> /// <returns></returns> internal SYSFilter Add(SYSFilterInjectDTO dto) { if (string.IsNullOrEmpty(dto.FilterCode) || string.IsNullOrEmpty(dto.FilterName)) { throw CFException.Create(SYSFilterInjectResult.NameOrCodeNotFound); } try { var prevCertificate = this.Get(new EntitySpec <SYSFilter>(query => { query.SystemID = dto.SystemId; query.FilterCode = dto.FilterCode; })); if (prevCertificate.ID.HasValue) { throw CFException.Create(SYSFilterInjectResult.CodeAlreadyExists); } SYSFilter entity = dto.Map <SYSFilterInjectDTO, SYSFilter>(); entity.SystemID = dto.SystemId; entity.InputTime = DateTime.Now; entity.Inputer = CFContext.User.UserName; entity.InputerID = CFContext.User.ID; this.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(SYSFilterInjectResult.Fail, ex); } }
/// <summary> /// 分配账户角色 /// </summary> public SYSGroupUser AccountAssign(SYSGroupUserAssignDTO dto) { if (string.IsNullOrEmpty(dto.GroupCode)) { throw CFException.Create(SYSGroupUserAssignResult.SystemCodeInvalid); } try { var group = this.Context.Resolve <SYSGroupRepository>().Get(new EntitySpec <SYSGroup>(query => { query.SystemID = dto.SystemId; query.GroupCode = dto.GroupCode; })); if (group.ID == null) { throw CFException.Create(SYSGroupUserAssignResult.GroupNotFound); } var groupAccount = this.Get(new EntitySpec <SYSGroupUser>(query => { query.GroupID = group.ID; query.UserId = dto.AccountID; })); if (groupAccount.ID.HasValue) { throw CFException.Create(SYSGroupUserAssignResult.GroupAccountAlreadyExists); } var entity = new SYSGroupUser { UserId = dto.AccountID, GroupID = group.ID, }; this.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(SYSGroupUserAssignResult.Fail, ex); } }
/// <summary> /// 找回通行证密码 /// </summary> /// <param name="retrievePassword"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void PassportRetrievePassword(SYSPassportRetrievePasswordDTO dto) { if (string.IsNullOrEmpty(dto.LoginName)) { throw CFException.Create(SYSPassportChangePasswordResult.LoginNameDoesNotExist); } try { var passport = _passportRepository.Get(item => item.LoginName == dto.LoginName); //检查用户信息 if (!passport.ID.HasValue) { throw CFException.Create(SYSPassportChangePasswordResult.LoginNameDoesNotExist); } //检查新密码 if (string.IsNullOrEmpty(dto.Password) || !ALValidator.IsLengthStr(dto.Password, 6, 16)) { throw CFException.Create(SYSPassportChangePasswordResult.PasswordTooWeak); } if (string.IsNullOrEmpty(dto.ConfirmedPassword) || dto.Password != dto.ConfirmedPassword) { throw CFException.Create(SYSPassportChangePasswordResult.RePasswordIncorrect); } //更改密码 passport.Password = passport.ComputePassword(dto.LoginName, dto.Password); _passportRepository.Modify(passport); return; } catch (Exception ex) { throw CFException.Create(SYSPassportChangePasswordResult.Fail, ex.Message, ex); } }
/// <summary> /// 生成访问令牌 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken GeneralTocken(SYSAccessTokenDTO accessToken) { //检查应用代码和密钥 var certificate = _certificateRepository.Get(item => item.ApiKey == accessToken.client_id && item.Secret == accessToken.client_secret); if (certificate.ID == null) { throw CFException.Create(STDAccessTokenResult.ClientIDOrSecretInvalid); } //验证授权码 var authorize = CacheService.Default.Get <SYSAuthorizeDTO>("STDAuthorizeDTO_" + accessToken.code); if (authorize.Equals(default(SYSAuthorizeDTO))) { throw CFException.Create(STDAccessTokenResult.CodeInvalid); } if (authorize.redirect_uri != accessToken.redirect_uri) { throw CFException.Create(STDAccessTokenResult.RedirectUriInvalid); } //验证用户登录 if (authorize.uid == null) { throw CFException.Create(STDAccessTokenResult.UIDInvalid); } //创建访问令牌 var token = new SYSAccessToken(certificate.SystemID.Value) //令牌有效期:2小时 { uid = authorize.uid.Value, scope = authorize.scope, }; return(token); }
/// <summary> /// 生成令牌 /// </summary> /// <param name="dto"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken GeneralTocken(SYSAccessTokenDTO dto) { if (!Exist(dto.grant_type)) { throw CFException.Create(STDAccessTokenResult.GrantTypeInvalid); } try { //获得访问密钥 var auth = CreateAuth(dto.grant_type); var token = auth.GeneralTocken(dto); //保存访问密钥 var appToken = SaveToken(token); if (appToken.ID == null) { throw CFException.Create(STDAccessTokenResult.AccountNotFount); } return(token); } catch (DefinedException ex) { throw ex; } catch (Exception ex) { throw CFException.Create(STDAccessTokenResult.Fail, ex.Message, ex); } }
public static IEnumerable <TSource> Where <TSource>(this IEnumerable <TSource> source, ISpecification <TSource> specification) where TSource : class { if (specification == null || specification.Lambda == null) { CFException.Create(OperateResult.NotFound, "指定的规约未定义Lambda表达式"); } return(source.Where(specification.Lambda.Compile())); }
/// <summary> /// 获得指定数据库类型的数据分析器 /// </summary> /// <param name="providerName"></param> /// <returns></returns> public static IDBAnalyzer GetDBAnalyzer(string providerName) { Type dbAnalyzer; if (registeredDBAnalyzer.TryGetValue(providerName, out dbAnalyzer)) { return((IDBAnalyzer)Activator.CreateInstance(dbAnalyzer)); } throw CFException.Create(OperateResult.NotFound, "尚未注册" + providerName + "类型的数据分析器。"); }
/// <summary> /// 获取系统信息 /// </summary> /// <param name="systemId"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSSystem GetSystemInfo(long systemId) { var system = _systemRepository.Get(systemId); if (!system.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } return(system); }
/// <summary> /// 获取系统信息 /// </summary> /// <param name="code"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSSystem GetSystemInfo(string code) { var system = _systemRepository.Get(item => item.SystemCode == code); if (!system.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } return(system); }
/// <summary> /// 注册通行证 /// </summary> /// <param name="passport"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSPassport PassportRegist(SYSPassportRegistDTO passport) { if (string.IsNullOrEmpty(passport.LoginName) || !ALValidator.IsLengthStr(passport.LoginName, 4, 50) || !ALValidator.IsNormalChar(passport.LoginName)) { throw CFException.Create(SYSPassportRegistResult.LoginNameInvalid); } if (string.IsNullOrEmpty(passport.Password) || !ALValidator.IsLengthStr(passport.Password, 6, 16)) { throw CFException.Create(SYSPassportRegistResult.PasswordTooWeak); } if (string.IsNullOrEmpty(passport.RePassword) || passport.Password != passport.RePassword) { throw CFException.Create(SYSPassportRegistResult.RePasswordIncorrect); } if (string.IsNullOrEmpty(passport.Email) || !ALValidator.IsEmail(passport.Email)) { throw CFException.Create(SYSPassportRegistResult.EmailInvalid); } try { if (_passportRepository.Get(item => item.LoginName == passport.LoginName).ID != null) { throw CFException.Create(SYSPassportRegistResult.LoginNameAlreadyExists); } if (_passportRepository.Get(item => item.Email == passport.Email).ID != null) { throw CFException.Create(SYSPassportRegistResult.EmailAlreadyExists); } var now = DateTime.Now; var entity = new SYSPassport { LoginName = passport.LoginName, Email = passport.Email, Remarks = passport.Remarks, LastLoginTime = now, LastLoginError = 0, IsValid = true, IsLocked = false, Inputer = CFContext.User.UserName, InputerID = CFContext.User.ID, InputTime = now }; entity.Password = entity.ComputePassword(passport.LoginName, passport.Password); _passportRepository.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(SYSPassportRegistResult.Fail, ex.Message, ex); } }
public SYSAccessToken GeneralTocken(SYSAccessTokenDTO accessToken) { //检查应用代码和密钥 var certificate = _certificateRepository.Get(item => item.ApiKey == accessToken.client_id && item.Secret == accessToken.client_secret); if (certificate.ID == null) { throw CFException.Create(STDAccessTokenResult.ClientIDOrSecretInvalid); } //创建访问令牌 var token = new SYSAccessToken(certificate.SystemID.Value); //令牌有效期:2小时 return(token); }
/// <summary> /// 删除系统账号 /// </summary> /// <param name="systemId"></param> /// <param name="uId"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void UnRegisterAccount(long systemId, string uId) { var entity = _accountRepository.Get(item => item.SystemID == systemId && item.UID == uId); if (!entity.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } try { _accountRepository.Remove(entity); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 注销访问令牌 /// </summary> /// <param name="systemId"></param> /// <param name="passportId"></param> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void DestroyToken(long systemId, long passportId) { var entity = _tokenRepository.Get(item => item.SystemID == systemId && item.PassportID == passportId); if (!entity.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } try { _tokenRepository.Remove(entity); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 删除系统 /// </summary> /// <param name="code"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void UnRegisterSystem(string code) { var entity = _systemRepository.Get(item => item.SystemCode == code); if (!entity.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } try { _systemRepository.Remove(entity); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 生成更新令牌 /// </summary> /// <param name="accessToken"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccessToken GeneralTocken(SYSAccessTokenDTO accessToken) { //检查更新令牌 var refreshToken = _tokenRepository.Get(item => item.RefreshToken == accessToken.refresh_token); if (refreshToken.ID == null) { throw CFException.Create(STDAccessTokenResult.ClientIDOrSecretInvalid); } //创建访问令牌 var token = new SYSAccessToken(refreshToken.SystemID.Value) { uid = refreshToken.PassportID, scope = refreshToken.Scope, }; return(token); }
/// <summary> /// 删除证书 /// </summary> /// <param name="apiKey"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void RecyleCertificate(string apiKey) { var entity = _certificateRepository.Get(item => item.ApiKey == apiKey); if (!entity.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } try { _certificateRepository.Remove(entity); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 注销通行证 /// </summary> /// <param name="loginName"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void PassportUnRegister(string loginName) { var entity = _passportRepository.Get(item => item.LoginName == loginName); if (!entity.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } try { _passportRepository.Remove(entity); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 更新密码锁定状态 /// </summary> /// <param name="loginName"></param> /// <param name="isLocked"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void PassportLock(string loginName, bool isLocked) { var passport = _passportRepository.Get(item => item.LoginName == loginName); if (!passport.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } passport.IsLocked = isLocked; try { _passportRepository.Modify(passport); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 使用授权Token登录 /// </summary> /// <param name="authorizeLogin"></param> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void AuthorizeLogin(SYSAuthorizeLoginDTO authorizeLogin) { //检查请求参数 if (string.IsNullOrEmpty(authorizeLogin.code)) { throw CFException.Create(STDAuthorizeLoginResult.AuthorizeCodeInvalid); } if (string.IsNullOrEmpty(authorizeLogin.username) || string.IsNullOrEmpty(authorizeLogin.password)) { throw CFException.Create(STDAuthorizeLoginResult.AccountOrPasswordInvalid); } try { //验证授权码 var authorize = CacheService.Default.Get <SYSAuthorizeDTO>("STDAuthorizeDTO_" + authorizeLogin.code); if (authorize.Equals(default(SYSAuthorizeDTO))) { throw CFException.Create(STDAuthorizeLoginResult.AuthorizeCodeInvalid); } //验证用户账号 SYSPassport passport; if (!Login(authorizeLogin.username, authorizeLogin.password, out passport)) { throw CFException.Create(STDAuthorizeLoginResult.AccountOrPasswordInvalid); } CacheService.Default.Add("STDAuthorizeDTO_" + authorizeLogin.code, new SYSAuthorizeDTO { response_type = authorize.response_type, client_id = authorize.client_id, redirect_uri = authorize.redirect_uri, scope = authorize.scope, state = authorize.state, uid = passport.ID, }); return; } catch (Exception ex) { throw CFException.Create(STDAuthorizeLoginResult.Fail, ex.Message, ex); } }
internal SYSStrategy StrategyInject(SYSStrategyDTO dto) { if (string.IsNullOrEmpty(dto.Code) || string.IsNullOrEmpty(dto.Name)) { throw CFException.Create(SYSStrategyResult.NameOrCodeNotFound); } try { var tagService = TagService.GetInstance(); tagService.DependOn(this.Context); SYSTag tagInfo = tagService.GetTag(dto.ResourceTagID); if (tagInfo.ID == null) { throw CFException.Create(SYSStrategyResult.ResourceTagInvalid); } SYSTagClass tagClassInfo = tagService.GetTagClass(tagInfo.TagClassID ?? 0); if (tagClassInfo.ID == null) { throw CFException.Create(SYSStrategyResult.ResourceTagInvalid); } var prevCertificate = this.Get(new EntitySpec <SYSStrategy>(query => { query.SystemID = dto.SystemId; query.StrategyCode = dto.Code; })); if (prevCertificate.ID.HasValue) { throw CFException.Create(SYSStrategyResult.CodeAlreadyExists); } SYSStrategy entity = dto.Map <SYSStrategyDTO, SYSStrategy>(); entity.SystemID = dto.SystemId; entity.InputTime = DateTime.Now; entity.Inputer = CFContext.User.UserName; entity.InputerID = CFContext.User.ID; this.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(SYSStrategyResult.Fail, ex); } }
public SYSOperationFilter OperationAssign(SYSOperationFilterAssignDTO dto) { if (string.IsNullOrEmpty(dto.OperationCode) || string.IsNullOrEmpty(dto.OperationCode)) { throw CFException.Create(SYSOperationFilterAssignResult.SystemCodeInvalid); } try { var filter = this.Context.Resolve <SYSFilterRepository>().Get(new EntitySpec <SYSFilter>(query => { query.SystemID = dto.SystemId; query.FilterCode = dto.FilterCode; })); if (!filter.ID.HasValue) { throw CFException.Create(SYSOperationFilterAssignResult.FilterNotFound); } var operation = this.Context.Resolve <SYSOperationRepository>().Get(new EntitySpec <SYSOperation>(query => { query.SystemID = dto.SystemId; query.OperationCode = dto.OperationCode; })); if (!operation.ID.HasValue) { throw CFException.Create(SYSOperationFilterAssignResult.OperationNotFound); } var operationFilter = this.Get(new EntitySpec <SYSOperationFilter>(query => { query.FilterID = filter.ID; query.OperationID = operation.ID; })); if (operationFilter.ID.HasValue) { throw CFException.Create(SYSOperationFilterAssignResult.OperationFilterAlreadyExist); } var entity = new SYSOperationFilter { OperationID = operation.ID, FilterID = filter.ID, }; this.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(SYSOperationFilterAssignResult.Fail, ex); } }
public SYSStrategyOperation OperationAssign(SYSStrategyOperationAssignDTO dto) { if (string.IsNullOrEmpty(dto.StrategyCode) || string.IsNullOrEmpty(dto.OperationCode)) { throw CFException.Create(SYSStrategyOperationAssignResult.SystemCodeInvalid); } try { var operation = this.Context.Resolve <SYSOperationRepository>().Get(new EntitySpec <SYSOperation>(query => { query.SystemID = dto.SystemId; query.OperationCode = dto.OperationCode; })); if (!operation.ID.HasValue) { throw CFException.Create(SYSStrategyOperationAssignResult.OperationNotFound); } var strategy = this.Context.Resolve <SYSStrategyRepository>().Get(new EntitySpec <SYSStrategy>(query => { query.SystemID = dto.SystemId; query.StrategyCode = dto.StrategyCode; })); if (!strategy.ID.HasValue) { throw CFException.Create(SYSStrategyOperationAssignResult.StrategyNotFound); } var strategyGroup = this.Get(new EntitySpec <SYSStrategyOperation>(query => { query.OperationID = operation.ID; query.StrategyID = strategy.ID; })); if (strategyGroup.ID.HasValue) { throw CFException.Create(SYSStrategyOperationAssignResult.StrategyOperationAlreadyExist); } var entity = new SYSStrategyOperation { StrategyID = strategy.ID, OperationID = operation.ID, }; this.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(SYSStrategyOperationAssignResult.Fail, ex); } }
/// <summary> /// 通行证绑定系统账号 /// </summary> /// <param name="link"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void PassportLink(SYSPassportLinkDTO link) { if (string.IsNullOrEmpty(link.LoginName) || string.IsNullOrEmpty(link.SystemCode) || string.IsNullOrEmpty(link.UID)) { throw CFException.Create(SYSPassportLinkResult.LoginNameOrUIDNotFound); } try { var passport = _passportRepository.Get(item => item.LoginName == link.LoginName); if (passport.ID == null) { throw CFException.Create(SYSPassportLinkResult.LoginNameInvalid); } var system = _systemRepository.Get(item => item.SystemCode == link.SystemCode); if (system.ID == null) { throw CFException.Create(SYSPassportLinkResult.SystemCodeInvalid); } var account = _accountRepository.Get(item => item.UID == link.UID && item.SystemID == system.ID); if (account.ID == null || account.PassportID != null) { throw CFException.Create(SYSPassportLinkResult.UIDInvalid); } account.PassportID = passport.ID; _accountRepository.Modify(new SYSAccount { ID = account.ID, PassportID = passport.ID }); return; } catch (Exception ex) { throw CFException.Create(SYSPassportLinkResult.Fail, ex.Message); } }
/// <summary> /// 忘记密码 /// </summary> /// <param name="email"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSPassworkForgetDTO PassportForgot(string email) { try { if (string.IsNullOrEmpty(email)) { throw CFException.Create(STDPassworkForgetResult.EmailIncorrect); } var passport = _passportRepository.Get(item => item.Email == email); if (passport == null) { throw CFException.Create(STDPassworkForgetResult.EmailIncorrect); } passport.VerificationCode = ALUtils.GetGUIDShort(); _passportRepository.Modify(passport); return(new SYSPassworkForgetDTO(email, passport.LoginName, passport.VerificationCode)); } catch (Exception ex) { throw CFException.Create(STDPassworkForgetResult.Fail, ex.Message, ex); } }
/// <summary> /// 注销访问令牌 /// </summary> /// <param name="accessToken"></param> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void DestroyToken(string accessToken) { if (string.IsNullOrEmpty(accessToken)) { throw CFException.Create(OperateResult.NotFound); } var entity = _tokenRepository.Get(item => item.AccessToken == accessToken); if (!entity.ID.HasValue) { throw CFException.Create(OperateResult.NotFound); } try { _tokenRepository.Remove(entity); return; } catch (Exception ex) { throw CFException.Create(OperateResult.Fail, ex.Message, ex); } }
/// <summary> /// 系统注册 /// </summary> /// <param name="dto"></param> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public void SystemRegist(SYSSystemRegistDTO dto) { if (string.IsNullOrEmpty(dto.SystemName) || string.IsNullOrEmpty(dto.SystemCode)) { throw CFException.Create(SYSSystemRegistResult.NameOrCodeNotFound); } try { var system = _systemRepository.Get(item => item.SystemCode == dto.SystemCode); if (system.ID.HasValue) { if (system.GetVersion() > dto.GetVersion()) { throw CFException.Create(SYSSystemRegistResult.CodeAlreadyExists); } } else { system = new SYSSystem(dto.SystemCode); } system = CFMapper.Map(dto, system); if (system.ID.HasValue) { _systemRepository.Modify(system); } else { _systemRepository.Add(system); } return; } catch (Exception ex) { throw CFException.Create(SYSSystemRegistResult.Fail, ex.Message, ex); } }
/// <summary> /// 注册系统账号 /// </summary> /// <param name="account"></param> /// <returns></returns> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSAccount AccountRegist(SYSAccountRegistDTO dto) { if (string.IsNullOrEmpty(dto.SystemCode) || string.IsNullOrEmpty(dto.UID)) { throw CFException.Create(SYSAccountRegistResult.UIDInvalid); } try { SYSSystem system = _systemRepository.Get(item => item.SystemCode == dto.SystemCode); if (system.ID == null) { throw CFException.Create(SYSAccountRegistResult.SystemCodeInvalid); } var prevAccount = _accountRepository.Get(item => item.SystemID == system.ID && item.UID == dto.UID); var entity = dto.Map <SYSAccountRegistDTO, SYSAccount>(); if (prevAccount.ID.HasValue) { entity.ID = prevAccount.ID; _accountRepository.Modify(entity); } else { entity.SystemID = system.ID; entity.SystemName = system.SystemName; entity.InputTime = DateTime.Now; entity.InputIP = CFContext.User.IP; _accountRepository.Add(entity); } return(entity); } catch (Exception ex) { throw CFException.Create(SYSAccountRegistResult.Fail, ex.Message, ex); } }
/// <summary> /// 为指定系统颁发新证书 /// </summary> /// <param name="dto"></param> /// <exception cref="BIStudio.Framework.DefinedException"></exception> public SYSSystemCertificate CertificateIssue(SYSSystemCertificateIssueDTO dto) { if (string.IsNullOrEmpty(dto.SystemCode) || string.IsNullOrEmpty(dto.ApiKey) || string.IsNullOrEmpty(dto.CertificateName)) { throw CFException.Create(STDCertificateIssueResult.NameOrCodeNotFound); } try { SYSSystem system = _systemRepository.Get(item => item.SystemCode == dto.SystemCode); if (system.ID == null) { throw CFException.Create(STDCertificateIssueResult.SystemCodeInvalid); } SYSSystemCertificate entity = dto.Map <SYSSystemCertificateIssueDTO, SYSSystemCertificate>(); var prevCertificate = _certificateRepository.Get(item => item.ApiKey == dto.ApiKey); if (prevCertificate.ID.HasValue) { throw CFException.Create(STDCertificateIssueResult.CodeAlreadyExists); } entity.SystemID = system.ID; entity.ApiKey = entity.ApiKey; entity.Secret = ALUtils.GetGUIDShort(); entity.IsValid = true; entity.InputTime = DateTime.Now; entity.Inputer = CFContext.User.UserName; entity.InputerID = CFContext.User.ID; _certificateRepository.Add(entity); return(entity); } catch (Exception ex) { throw CFException.Create(STDCertificateIssueResult.Fail, ex.Message, ex); } }