コード例 #1
0
        public ChangePasswordFormController(
            [NotNull] IUserSettingsManager userSettingsManager,
            [NotNull] IEncryptedStorage encryptedStorage,
            [NotNull] ExceptionHandler exceptionHandler,
            ILogger logger,
            IMessageBoxService messageBoxService,
            IStandardDialogService standardDialogService,
            IEventAggregator eventAggregator = null)
            : base(logger, messageBoxService, standardDialogService, eventAggregator)
        {
            if (userSettingsManager == null)
            {
                throw new ArgumentNullException("userSettingsManager");
            }

            if (encryptedStorage == null)
            {
                throw new ArgumentNullException("encryptedStorage");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            this.userSettingsManager = userSettingsManager;
            this.encryptedStorage    = encryptedStorage;
            this.exceptionHandler    = exceptionHandler;
        }
コード例 #2
0
        // Non-private only to facilitate testing.
        internal NuGetUIContext(
            ISourceRepositoryProvider sourceProvider,
            IServiceBroker serviceBroker,
            IVsSolutionManager solutionManager,
            NuGetSolutionManagerServiceWrapper solutionManagerService,
            NuGetPackageManager packageManager,
            UIActionEngine uiActionEngine,
            IPackageRestoreManager packageRestoreManager,
            IOptionsPageActivator optionsPageActivator,
            IUserSettingsManager userSettingsManager,
            IEnumerable <IVsPackageManagerProvider> packageManagerProviders)
        {
            SourceProvider          = sourceProvider;
            ServiceBroker           = serviceBroker;
            SolutionManager         = solutionManager;
            _solutionManagerService = solutionManagerService;
            PackageManager          = packageManager;
            UIActionEngine          = uiActionEngine;
            PackageManager          = packageManager;
            PackageRestoreManager   = packageRestoreManager;
            OptionsPageActivator    = optionsPageActivator;
            UserSettingsManager     = userSettingsManager;
            PackageManagerProviders = packageManagerProviders;

            ServiceBroker.AvailabilityChanged += OnAvailabilityChanged;
            SolutionManager.ActionsExecuted   += OnActionsExecuted;
        }
コード例 #3
0
        /// <summary>
        /// 验证邮箱
        /// </summary>
        /// <param name="email">待验证的邮箱</param>
        /// <param name="userId">用户Id</param>
        /// <param name="errorMessage">输出出错信息</param>
        /// <returns>是否通过验证</returns>
        public bool ValidateEmail(string email, long userId, out string errorMessage)
        {
            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();

            if (string.IsNullOrEmpty(email))
            {
                errorMessage = ResourceAccessor.GetString("Validate_EmailRequired");
                return(false);
            }

            Regex regex = new Regex(userSettings.EmailRegex, RegexOptions.ECMAScript);

            if (!regex.IsMatch(email))
            {
                errorMessage = ResourceAccessor.GetString("Validate_EmailStyle");
                return(false);
            }

            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        user        = userService.FindUserByEmail(email);

            if (user != null)
            {
                //验证email是否已经存在
                if (userId != user.UserId)
                {
                    errorMessage = "对不起,您输入的帐号邮箱已被使用";
                    return(false);
                }
            }
            errorMessage = string.Empty;
            return(true);
        }
コード例 #4
0
ファイル: Utility.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 验证邮箱
        /// </summary>
        /// <param name="email">待验证的邮箱</param>
        /// <param name="errorMessage">输出出错信息</param>
        /// <returns>是否通过验证</returns>
        public static bool ValidateEmail(string email, out string errorMessage)
        {
            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();

            if (string.IsNullOrEmpty(email))
            {
                errorMessage = ResourceAccessor.GetString("Validate_EmailRequired");
                return(false);
            }

            Regex regex = new Regex(userSettings.EmailRegex, RegexOptions.ECMAScript);

            if (!regex.IsMatch(email))
            {
                errorMessage = ResourceAccessor.GetString("Validate_EmailStyle");
                return(false);
            }

            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        user        = userService.FindUserByEmail(email);

            //验证email是否已经存在
            if (user != null)
            {
                errorMessage = string.Format(ResourceAccessor.GetString("Message_Pattern_RegisterFailedForDuplicateEmailAddress"), SiteUrls.Instance().FindPassword(email));
                return(false);
            }
            errorMessage = string.Empty;
            return(true);
        }
コード例 #5
0
        // Non-private only to facilitate testing.
        internal NuGetUIContext(
            IServiceBroker serviceBroker,
            IReconnectingNuGetSearchService nuGetSearchService,
            IVsSolutionManager solutionManager,
            NuGetSolutionManagerServiceWrapper solutionManagerService,
            NuGetPackageManager packageManager,
            UIActionEngine uiActionEngine,
            IPackageRestoreManager packageRestoreManager,
            IOptionsPageActivator optionsPageActivator,
            IUserSettingsManager userSettingsManager,
            NuGetSourcesServiceWrapper sourceService)
        {
            ServiceBroker             = serviceBroker;
            ReconnectingSearchService = nuGetSearchService;
            SolutionManager           = solutionManager;
            _solutionManagerService   = solutionManagerService;
            PackageManager            = packageManager;
            UIActionEngine            = uiActionEngine;
            PackageManager            = packageManager;
            PackageRestoreManager     = packageRestoreManager;
            OptionsPageActivator      = optionsPageActivator;
            UserSettingsManager       = userSettingsManager;
            _sourceService            = sourceService;

            ServiceBroker.AvailabilityChanged += OnAvailabilityChanged;
            SolutionManager.ActionsExecuted   += OnActionsExecuted;
        }
コード例 #6
0
        public static async ValueTask <NuGetUIContext> CreateAsync(
            IServiceBroker serviceBroker,
            ISourceRepositoryProvider sourceRepositoryProvider,
            ISettings settings,
            IVsSolutionManager solutionManager,
            IPackageRestoreManager packageRestoreManager,
            IOptionsPageActivator optionsPageActivator,
            IUserSettingsManager userSettingsManager,
            IDeleteOnRestartManager deleteOnRestartManager,
            IEnumerable <IVsPackageManagerProvider> packageManagerProviders,
            INuGetLockService lockService,
            CancellationToken cancellationToken)
        {
            Assumes.NotNull(serviceBroker);
            Assumes.NotNull(sourceRepositoryProvider);
            Assumes.NotNull(settings);
            Assumes.NotNull(solutionManager);
            Assumes.NotNull(packageRestoreManager);
            Assumes.NotNull(optionsPageActivator);
            Assumes.NotNull(userSettingsManager);
            Assumes.NotNull(deleteOnRestartManager);
            Assumes.NotNull(packageManagerProviders);
            Assumes.NotNull(lockService);

            cancellationToken.ThrowIfCancellationRequested();

            var solutionManagerServiceWrapper = new NuGetSolutionManagerServiceWrapper();
            INuGetSolutionManagerService solutionManagerService = await GetSolutionManagerServiceAsync(serviceBroker, cancellationToken);

            // The initial Swap(...) should return a null implementation of the interface that does not require disposal.
            // However, there's no harm in following form.
            using (solutionManagerServiceWrapper.Swap(solutionManagerService))
            {
            }

            var packageManager = new NuGetPackageManager(
                sourceRepositoryProvider,
                settings,
                solutionManager,
                deleteOnRestartManager);

            var actionEngine = new UIActionEngine(
                sourceRepositoryProvider,
                packageManager,
                lockService);

            return(new NuGetUIContext(
                       sourceRepositoryProvider,
                       serviceBroker,
                       solutionManager,
                       solutionManagerServiceWrapper,
                       packageManager,
                       actionEngine,
                       packageRestoreManager,
                       optionsPageActivator,
                       userSettingsManager,
                       packageManagerProviders));
        }
コード例 #7
0
        public static async Task <NuGetUI> CreateAsync(
            IServiceBroker serviceBroker,
            ICommonOperations commonOperations,
            NuGetUIProjectContext projectContext,
            ISourceRepositoryProvider sourceRepositoryProvider,
            ISettings settings,
            IVsSolutionManager solutionManager,
            IPackageRestoreManager packageRestoreManager,
            IOptionsPageActivator optionsPageActivator,
            IUserSettingsManager userSettingsManager,
            IDeleteOnRestartManager deleteOnRestartManager,
            SolutionUserOptions solutionUserOptions,
            INuGetLockService lockService,
            INuGetUILogger logger,
            IRestoreProgressReporter restoreProgressReporter,
            CancellationToken cancellationToken,
            params IProjectContextInfo[] projects)
        {
            Assumes.NotNull(serviceBroker);
            Assumes.NotNull(commonOperations);
            Assumes.NotNull(projectContext);
            Assumes.NotNull(sourceRepositoryProvider);
            Assumes.NotNull(settings);
            Assumes.NotNull(solutionManager);
            Assumes.NotNull(packageRestoreManager);
            Assumes.NotNull(optionsPageActivator);
            Assumes.NotNull(userSettingsManager);
            Assumes.NotNull(deleteOnRestartManager);
            Assumes.NotNull(solutionUserOptions);
            Assumes.NotNull(lockService);
            Assumes.NotNull(restoreProgressReporter);
            Assumes.NotNull(logger);

            cancellationToken.ThrowIfCancellationRequested();

            var nuGetUi = new NuGetUI(
                commonOperations,
                projectContext,
                logger)
            {
                UIContext = await NuGetUIContext.CreateAsync(
                    serviceBroker,
                    sourceRepositoryProvider,
                    settings,
                    solutionManager,
                    packageRestoreManager,
                    optionsPageActivator,
                    solutionUserOptions,
                    deleteOnRestartManager,
                    lockService,
                    restoreProgressReporter,
                    cancellationToken)
            };

            nuGetUi.UIContext.Projects = projects;

            return(nuGetUi);
        }
コード例 #8
0
        public async Task <IEnumerable <WorkRoot> > GetWorkRootsAsync(
            CancellationToken cancellationToken)
        {
            IUserSettingsManager settingsManager = _app.GetRequiredService <IUserSettingsManager>();

            UserSettings?settings = await settingsManager.GetAsync(cancellationToken);

            if (settings.WorkRoots.Count() == 0)
            {
                _console.WriteLine("No work roots configured!");
                _console.WriteLine("You can configure you work roots in the UI or directly in:");
                _console.WriteLine($"{SettingsStore.UserSettingsFilePath}.");

                var options = new List <string>
                {
                    "Open UI",
                    "Open User settings in code",
                    $"Add {Directory.GetCurrentDirectory()} as work root",
                    "Cancel"
                };

                var index = _console.ChooseFromList(options);

                switch (index)
                {
                case 0:
                    IWebServer?webServer = _app.GetRequiredService <IWebServer>();
                    var        url       = await webServer.StartAsync(3003);

                    ProcessHelpers.OpenBrowser(url + "/settings");
                    break;

                case 1:
                    //first ensure file exists
                    if (!File.Exists(SettingsStore.UserSettingsFilePath))
                    {
                        await AddCurrentWorkroot(settingsManager, cancellationToken);
                    }
                    IWorkspaceService workspaceService = _app.GetRequiredService <IWorkspaceService>();
                    await workspaceService.OpenFileInCode(SettingsStore.UserSettingsFilePath);

                    break;

                case 2:
                    await AddCurrentWorkroot(settingsManager, cancellationToken);

                    break;

                default:
                    break;
                }
            }

            return(settings.WorkRoots);
        }
コード例 #9
0
        public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService, FileOpenerManager openerManager, IUserSettingsManager userSettingsManager)
        {
            _cryptography               = cryptography;
            _webdavManager              = webdavManager;
            _authenticationService      = authenticationService;
            _tokenManager               = tokenManager;
            _webDavAuthorizationService = webDavAuthorizationService;
            _userSettingsManager        = userSettingsManager;

            _openerManager = new FileOpenerManager();
        }
コード例 #10
0
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="user">待创建的用户</param>
        /// <param name="ignoreDisallowedUsername">是否忽略禁用的用户名称</param>
        /// <param name="userCreateStatus">用户帐号创建状态</param>
        /// <returns>创建成功返回IUser,创建失败返回null</returns>
        public IUser CreateUser(User user, bool ignoreDisallowedUsername, out UserCreateStatus userCreateStatus)
        {
            userCreateStatus = UserCreateStatus.UnknownFailure;

            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();

            if (!ignoreDisallowedUsername)
            {
                if (userSettings.DisallowedUserNames.Split(new char[] { ',', ',' }).Any(n => n.Equals(user.UserName, StringComparison.CurrentCultureIgnoreCase)))
                {
                    //用户输入字段为禁用字段
                    userCreateStatus = UserCreateStatus.DisallowedUsername;
                    return(null);
                }
            }

            //判断用户名是否唯一
            if (GetUserIdByUserName(user.UserName) > 0)
            {
                userCreateStatus = UserCreateStatus.DuplicateUsername;
                return(null);
            }

            if (GetUser(user.UserId) != null)
            {
                userCreateStatus = UserCreateStatus.DuplicateUsername;
                return(null);
            }

            //判断邮箱是否唯一
            if (GetUserIdByEmail(user.AccountEmail) > 0)
            {
                userCreateStatus = UserCreateStatus.DuplicateEmailAddress;
                return(null);
            }
            //如果不允许手机号重复的时候
            if (!userSettings.RequiresUniqueMobile)
            {
                if (GetUserIdByMobile(user.AccountMobile) > 0)
                {
                    userCreateStatus = UserCreateStatus.DuplicateMobile;
                    return(null);
                }
            }
            user.UserId = IdGenerator.Next();
            object userId_objcet = base.Insert(user);

            if (userId_objcet != null && (long)userId_objcet > 0)
            {
                userCreateStatus = UserCreateStatus.Created;
            }
            return(user);
        }
コード例 #11
0
        public async Task <bool> SaveWorkRootsAsync(
            [Service] IUserSettingsManager settingsManager,
            SaveWorkRootsInput input,
            CancellationToken cancellationToken)
        {
            await settingsManager.SaveWorkRootsAsync(
                input.WorkRoots,
                cancellationToken);

            return(true);
        }
コード例 #12
0
        public async Task <bool> SaveTokenGeneratorSettings(
            [Service] IUserSettingsManager settingsManager,
            SaveTokenGeneratorSettingsInput input,
            CancellationToken cancellationToken)
        {
            await settingsManager.SaveTokenGeneratorSettingsAsync(
                input.Settings,
                cancellationToken);

            return(true);
        }
コード例 #13
0
ファイル: Utility.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 验证用户名
        /// </summary>
        /// <param name="userName">待验证的用户名</param>
        /// <param name="errorMessage">输出出错信息</param>
        /// <returns>是否通过验证</returns>
        public static bool ValidateUserName(string userName, out string errorMessage)
        {
            if (string.IsNullOrEmpty(userName))
            {
                errorMessage = ResourceAccessor.GetString("Validate_UserNameRequired");
                return(false);
            }
            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();

            if (userName.Length < userSettings.MinUserNameLength)
            {
                errorMessage = string.Format(ResourceAccessor.GetString("Validate_UserNameTooShort"), userSettings.MinUserNameLength);
                return(false);
            }

            if (userName.Length > userSettings.MaxUserNameLength)
            {
                errorMessage = string.Format(ResourceAccessor.GetString("Validate_UserNameTooLong"), userSettings.MaxUserNameLength);
                return(false);
            }

            Regex regex = new Regex(userSettings.UserNameRegex);

            if (!regex.IsMatch(userName))
            {
                errorMessage = ResourceAccessor.GetString("Validate_UserNameRegex");
                return(false);
            }

            AuthorizationService authorizationService = new AuthorizationService();

            authorizationService.IsSuperAdministrator(UserContext.CurrentUser);
            //验证UserName是否被禁止使用
            if (!authorizationService.IsSuperAdministrator(UserContext.CurrentUser) &&
                userSettings.DisallowedUserNames.Split(',', ',').Any(n => n.Equals(userName, StringComparison.CurrentCultureIgnoreCase)))
            {
                errorMessage = ResourceAccessor.GetString("Validate_UserNameIsDisallowed");
                return(false);
            }


            //验证UserName是否已经存在
            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        user        = userService.GetUser(userName);

            if (user != null)
            {
                errorMessage = ResourceAccessor.GetString("Validate_UserNameIsExisting");
                return(false);
            }
            errorMessage = string.Empty;
            return(true);
        }
コード例 #14
0
        public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService, FileOpenerManager openerManager, IUserSettingsManager userSettingsManager)
        {
            _cryptography = cryptography;
            _webdavManager = webdavManager;
            _authenticationService = authenticationService;
            _tokenManager = tokenManager;
            _webDavAuthorizationService = webDavAuthorizationService;
            _userSettingsManager = userSettingsManager;

            _openerManager = new FileOpenerManager();
        }
コード例 #15
0
        /*private struct SomeStruct
         * {
         *  private CBInfo.CBItem m_CbItem;
         *  private EventHandler m_EventHandler;
         *
         *  public EventHandler _EventHandler
         *  {
         *      get { return m_EventHandler; }
         *      set { m_EventHandler = value; }
         *  }
         *
         *  public CBInfo.CBItem CbItem
         *  {
         *      get { return m_CbItem; }
         *      set { m_CbItem = value; }
         *  }
         *
         *  public SomeStruct(CBInfo.CBItem cbItem, EventHandler del)
         *  {
         *      m_CbItem = cbItem;
         *      m_EventHandler = del;
         *  }
         * }*/

        internal Menu(Main.MainWnd mainWnd, IUserSettings iUserSettings, IMediaManager iMediaManager, IUserSettingsManager iUserSettingsManager)
        {
            InitializeComponent();
            m_IUserSettings        = iUserSettings;
            m_IMediaManager        = iMediaManager;
            m_IUserSettingsManager = iUserSettingsManager;

            InitVolumeTab();
            InitPriceTab();
            InitUsersTab();
        }
コード例 #16
0
 public CloneRepositoryCommand(
     IGitRemoteSearchService searchService,
     IConnectedServiceManager serviceManager,
     IUserSettingsManager settingsManager,
     IDefaultShellService defaultShellService,
     ILocalRepositoryIndexer localRepositoryIndexer)
 {
     _searchService          = searchService;
     _serviceManager         = serviceManager;
     _settingsManager        = settingsManager;
     _shellService           = defaultShellService;
     _localRepositoryIndexer = localRepositoryIndexer;
 }
コード例 #17
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public AuthorizationService()
        {
            tenantAuthorizationHandlerDictionary = new ConcurrentDictionary <string, ITenantAuthorizationHandler>();
            foreach (var tenantAuthorizationHandler in DIContainer.Resolve <IEnumerable <ITenantAuthorizationHandler> >())
            {
                tenantAuthorizationHandlerDictionary[tenantAuthorizationHandler.TenantTypeId] = tenantAuthorizationHandler;
            }

            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();

            this.AnonymousRoleName          = userSettings.AnonymousRoleName;
            this.SuperAdministratorRoleName = userSettings.SuperAdministratorRoleName;
            this.permissionService          = new PermissionService();
        }
コード例 #18
0
        private async Task AddCurrentWorkroot(
            IUserSettingsManager settingsManager,
            CancellationToken cancellationToken)
        {
            var workroots = new List <WorkRoot>()
            {
                new WorkRoot
                {
                    Name      = "AutoAdded",
                    Path      = Directory.GetCurrentDirectory(),
                    IsDefault = true,
                }
            };

            await settingsManager.SaveWorkRootsAsync(workroots, cancellationToken);
        }
コード例 #19
0
        public TestForUserEditModel GetUserSettings()
        {
            //根据站点配置设置用户属性
            IUserSettingsManager         userSettingsManager         = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings                 userSettings                = userSettingsManager.Get();
            IInviteFriendSettingsManager inviteFriendSettingsManager = DIContainer.Resolve <IInviteFriendSettingsManager>();
            InviteFriendSettings         inviteFriendSettings        = inviteFriendSettingsManager.Get();

            return(new TestForUserEditModel
            {
                registrationMode = userSettings.RegistrationMode,
                EnableNotActivatedUsersToLogin = userSettings.EnableNotActivatedUsersToLogin,
                MyHomePageAsSiteEntry = userSettings.MyHomePageAsSiteEntry,
                AllowInvitationCodeUseOnce = inviteFriendSettings.AllowInvitationCodeUseOnce,
                UserPasswordFormat = userSettings.UserPasswordFormat
            });
        }
コード例 #20
0
        public static bool SetScheduleExpanded(string flowId, bool isExpanded, string currentUsername, HttpSessionState sessionState,
                                               IUserSettingsManager userSettingsManager)
        {
            SessionStateDataStorage sessionStateData = ValidateSessionStateData(currentUsername, sessionState, userSettingsManager);

            if (!isExpanded)
            {
                if (!sessionStateData.HiddenSchedules.Contains(flowId))
                {
                    sessionStateData.HiddenSchedules.Add(flowId);
                }
            }
            else
            {
                sessionStateData.HiddenSchedules.Remove(flowId);
            }
            userSettingsManager.SaveAdminSchedulePageHiddenScheduleIds(currentUsername, sessionStateData.HiddenSchedules);
            return(isExpanded);
        }
コード例 #21
0
 public NuGetUIContext(
     ISourceRepositoryProvider sourceProvider,
     ISolutionManager solutionManager,
     NuGetPackageManager packageManager,
     UIActionEngine uiActionEngine,
     IPackageRestoreManager packageRestoreManager,
     IOptionsPageActivator optionsPageActivator,
     IUserSettingsManager userSettingsManager,
     IEnumerable <IVsPackageManagerProvider> packageManagerProviders)
 {
     SourceProvider          = sourceProvider;
     SolutionManager         = solutionManager;
     PackageManager          = packageManager;
     UIActionEngine          = uiActionEngine;
     PackageManager          = packageManager;
     PackageRestoreManager   = packageRestoreManager;
     OptionsPageActivator    = optionsPageActivator;
     UserSettingsManager     = userSettingsManager;
     PackageManagerProviders = packageManagerProviders;
 }
コード例 #22
0
        public StorageSelectionFormController(
            ILogger logger,
            IMessageBoxService messageBoxService,
            IStandardDialogService standardDialogService,
            IUserSettingsManager userSettingsManager,
            IEncryptedStorage storage)
            : base(logger, messageBoxService, standardDialogService)
        {
            if (userSettingsManager == null)
            {
                throw new ArgumentNullException("userSettingsManager");
            }

            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            this.userSettingsManager = userSettingsManager;
            this.storage             = storage;
        }
コード例 #23
0
ファイル: Utility.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 检测用户密码是否适合站点设置
        /// </summary>
        /// <param name="newPassword">Password to be verified.</param>
        /// <param name="errorMessage">Error message to return.</param>
        /// <returns>True if compliant, otherwise False.</returns>
        public static bool ValidatePassword(string newPassword, out string errorMessage)
        {
            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();
            int minRequiredPasswordLength            = userSettings.MinPasswordLength;
            int minRequiredNonAlphanumericCharacters = userSettings.MinRequiredNonAlphanumericCharacters;

            errorMessage = "";

            if (string.IsNullOrEmpty(newPassword))
            {
                errorMessage = ResourceAccessor.GetString("Validate_RequiredPassword");
                return(false);
            }

            if (newPassword.Length < minRequiredPasswordLength)
            {
                errorMessage = string.Format(ResourceAccessor.GetString("Validate_Pattern_MinRequiredPasswordLength"), minRequiredPasswordLength);
                return(false);
            }

            int nonAlphaNumChars = 0;

            for (int i = 0; i < newPassword.Length; i++)
            {
                if (!char.IsLetterOrDigit(newPassword, i))
                {
                    nonAlphaNumChars++;
                }
            }
            if (nonAlphaNumChars < minRequiredNonAlphanumericCharacters)
            {
                errorMessage = string.Format(ResourceAccessor.GetString("Validate_Pattern_MinRequiredNonAlphanumericCharacters"), minRequiredNonAlphanumericCharacters);
                return(false);
            }

            return(true);
        }
コード例 #24
0
 public MenuPass(IUserSettingsManager iUserSettingsManager)
 {
     InitializeComponent();
     Debug.Assert(iUserSettingsManager != null);
     foreach (UserSettings usTemp in iUserSettingsManager.GetAllItems())
     {
         comboBox1.Items.Add(usTemp);
     }
     Debug.Assert(comboBox1.Items.Count > 0);
     comboBox1.SelectedIndex = 0;
     foreach (Button btnTemp in new Button[]
     {
         btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0
     })
     {
         btnTemp.Click += delegate(Object sender, EventArgs e)
         {
             tbPassword.Text += ((Button)sender).Text;
         };
     }
     btnClear.Click += new EventHandler(btnClear_Click);
     btnOK.Click    += new EventHandler(btnOK_Click);
 }
コード例 #25
0
        protected static SessionStateDataStorage ValidateSessionStateData(string currentUsername, HttpSessionState sessionState,
                                                                          IUserSettingsManager userSettingsManager)
        {
            ExceptionUtils.ThrowIfEmptyString(currentUsername);
            ExceptionUtils.ThrowIfNull(sessionState);
            ExceptionUtils.ThrowIfNull(userSettingsManager);

            SessionStateDataStorage sessionStateData = sessionState[SCHEDULE_PAGE_SESSION_STATE_KEY] as SessionStateDataStorage;

            if (sessionStateData == null)
            {
                sessionStateData = new SessionStateDataStorage();
                sessionState[SCHEDULE_PAGE_SESSION_STATE_KEY] = sessionStateData;

                sessionStateData.HiddenSchedules = userSettingsManager.LoadAdminSchedulePageHiddenScheduleIds(currentUsername);

                if (sessionStateData.HiddenSchedules == null)
                {
                    sessionStateData.HiddenSchedules = new CaseInsensitiveList();
                }
            }
            return(sessionStateData);
        }
コード例 #26
0
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="user">待创建的用户</param>
        /// <param name="password">密码</param>
        /// <param name="passwordQuestion">密码问题</param>
        /// <param name="passwordAnswer">密码答案</param>
        /// <param name="ignoreDisallowedUsername">是否忽略禁用的用户名称</param>
        /// <param name="userCreateStatus">用户帐号创建状态</param>
        /// <returns>创建成功返回IUser,创建失败返回null</returns>
        public IUser CreateUser(IUser user, string password, string passwordQuestion, string passwordAnswer, bool ignoreDisallowedUsername, out UserCreateStatus userCreateStatus)
        {
            User user_object = user as User;

            if (user_object == null)
            {
                userCreateStatus = UserCreateStatus.UnknownFailure;
                return(null);
            }

            //密码不合法
            string errorMessage = string.Empty;

            if (!Utility.ValidatePassword(password, out errorMessage))
            {
                userCreateStatus = UserCreateStatus.InvalidPassword;
                return(null);
            }

            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();

            user_object.PasswordFormat   = (int)userSettings.UserPasswordFormat;
            user_object.Password         = UserPasswordHelper.EncodePassword(password, userSettings.UserPasswordFormat);
            user_object.PasswordQuestion = passwordQuestion;
            user_object.PasswordAnswer   = passwordAnswer;
            user_object.IsModerated      = userSettings.AutomaticModerated;
            EventBus <User, CreateUserEventArgs> .Instance().OnBefore(user_object, new CreateUserEventArgs(password));

            user = userRepository.CreateUser(user_object, ignoreDisallowedUsername, out userCreateStatus);

            if (userCreateStatus == UserCreateStatus.Created)
            {
                EventBus <User, CreateUserEventArgs> .Instance().OnAfter(user_object, new CreateUserEventArgs(password));
            }
            return(user);
        }
コード例 #27
0
        public ConnectionManager(
            IConnectionFactory connectionFactory,
            IUserSettingsManager userSettings,
            ISharedSettingsManager sharedSettingsManager)
        {
            if (connectionFactory == null)
            {
                throw new ArgumentNullException("connectionFactory");
            }
            if (userSettings == null)
            {
                throw new ArgumentNullException("userSettings");
            }
            if (sharedSettingsManager == null)
            {
                throw new ArgumentNullException("sharedSettingsManager");
            }

            this.connectionFactory = connectionFactory;
            this.userSettings = userSettings;
            this.sharedSettingsManager = sharedSettingsManager;

            this.SyncContext = SynchronizationContext.Current;
        }
コード例 #28
0
        public ConnectionManager(
            IConnectionFactory connectionFactory,
            IUserSettingsManager userSettings,
            ISharedSettingsManager sharedSettingsManager)
        {
            if (connectionFactory == null)
            {
                throw new ArgumentNullException("connectionFactory");
            }
            if (userSettings == null)
            {
                throw new ArgumentNullException("userSettings");
            }
            if (sharedSettingsManager == null)
            {
                throw new ArgumentNullException("sharedSettingsManager");
            }

            this.connectionFactory     = connectionFactory;
            this.userSettings          = userSettings;
            this.sharedSettingsManager = sharedSettingsManager;

            this.SyncContext = SynchronizationContext.Current;
        }
コード例 #29
0
ファイル: GitMutations.cs プロジェクト: SwissLife-OSS/Boost
        public async Task <int> IndexWorkRootsAsync(
            [Service] IHubContext <ConsoleHub> hubContext,
            [Service] ILocalRepositoryIndexer repositoryIndexer,
            [Service] IUserSettingsManager settingsManager,
            CancellationToken cancellationToken)
        {
            UserSettings settings = await settingsManager.GetAsync(cancellationToken);

            var session = new MessageSession();

            Action <string> handler = async(string msg) =>
            {
                await hubContext.Clients.All.SendAsync("consoleData",
                                                       new ShellMessage(session.Next(), "Info", msg));
            };

            int indexCount = 0;

            foreach (WorkRoot wr in settings.WorkRoots)
            {
                var count = await repositoryIndexer.IndexWorkRootAsync(
                    wr,
                    handler,
                    cancellationToken);

                indexCount += count;
            }

            await hubContext.Clients.All.SendAsync("consoleData",
                                                   new ShellMessage(session.Next(), "end", $"Scan completed: {indexCount}")
            {
                Tags = new string[] { "success" }
            });

            return(indexCount);
        }
コード例 #30
0
 public Task <UserSettings> GetUserSettingsAsync(
     [Service] IUserSettingsManager settingsManager,
     CancellationToken cancellationToken)
 {
     return(settingsManager.GetAsync(cancellationToken));
 }
コード例 #31
0
ファイル: AuditService.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 判断是否需要在一定的严格程度上需要审核
        /// </summary>
        /// <param name="userId">UserId</param>
        /// <param name="auditable">可审核实体</param>
        /// <param name="strictDegree">审核严格程度</param>
        /// <returns></returns>
        private bool NeedAudit(long userId, IAuditable auditable, AuditStrictDegree strictDegree)
        {
            var user = DIContainer.Resolve <IUserService>().GetUser(userId);

            //匿名用户需要审核
            if (user == null)
            {
                return(true);
            }
            IUserSettingsManager userSettingsManager = DIContainer.Resolve <IUserSettingsManager>();
            UserSettings         userSettings        = userSettingsManager.Get();
            RoleService          roleService         = new RoleService();

            //不启用审核
            if (!userSettings.EnableAudit)
            {
                return(false);
            }

            //如果用户处于免审核角色,则直接通过
            if (roleService.IsUserInRoles(userId, userSettings.NoAuditedRoleNames.ToArray()))
            {
                return(false);
            }


            //获取用户所属的角色,并附加上注册用户角色
            IEnumerable <Role> rolesOfUser     = roleService.GetRolesOfUser(userId);
            IList <string>     roleNamesOfUser = rolesOfUser.Select(n => n.RoleName).ToList();

            roleNamesOfUser.Add(RoleNames.Instance().RegisteredUsers());
            if (user.IsModerated)
            {
                roleNamesOfUser.Add(RoleNames.Instance().ModeratedUser());
            }
            //判断每个用户角色的设置是否可用
            foreach (var roleName in roleNamesOfUser)
            {
                IEnumerable <AuditItemInUserRole> auditItemInUserRoles = GetAuditItemsInUserRole(roleName);
                foreach (var auditItemInUserRole in auditItemInUserRoles)
                {
                    if (auditItemInUserRole.ItemKey.Equals(auditable.AuditItemKey))
                    {
                        if (auditItemInUserRole.StrictDegree == AuditStrictDegree.None)
                        {
                            return(false);
                        }
                        else if (auditItemInUserRole.StrictDegree == AuditStrictDegree.NotSet)
                        {
                            break;
                        }
                        else if ((int)auditItemInUserRole.StrictDegree >= (int)strictDegree)
                        {
                            return(true);
                        }
                    }
                }
            }

            //如果用户处于免审核用户等级,也直接通过
            if (user.Rank >= userSettings.MinNoAuditedUserRank)
            {
                return(false);
            }

            return(false);
        }
コード例 #32
0
 public DefaultShellService(IUserSettingsManager userSettingService)
 {
     _userSettingService = userSettingService;
 }