예제 #1
0
        private bool CheckLoginValid(out string errorMessage)
        {
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(TbAdminName.Text))
            {
                errorMessage = "管理员用户名不能为空!";
                return(false);
            }

            if (string.IsNullOrEmpty(TbAdminPassword.Text))
            {
                errorMessage = "管理员密码不能为空!";
                return(false);
            }

            if (TbAdminPassword.Text.Length < 6)
            {
                errorMessage = "管理员密码必须大于6位!";
                return(false);
            }

            if (TbAdminPassword.Text != TbComfirmAdminPassword.Text)
            {
                errorMessage = "两次输入的管理员密码不一致!";
                return(false);
            }
            if (!EUserPasswordRestrictionUtils.IsValid(TbAdminPassword.Text, EUserPasswordRestrictionUtils.GetValue(EUserPasswordRestriction.LetterAndDigit)))
            {
                errorMessage =
                    $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestriction.LetterAndDigit)}";
                return(false);
            }
            return(true);
        }
예제 #2
0
        public bool ChangePassword(string userName, string password, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(password))
            {
                errorMessage = "密码不能为空";
                return(false);
            }
            if (password.Length < ConfigManager.SystemConfigInfo.AdminPasswordMinLength)
            {
                errorMessage = $"密码长度必须大于等于{ConfigManager.SystemConfigInfo.AdminPasswordMinLength}";
                return(false);
            }
            if (
                !EUserPasswordRestrictionUtils.IsValid(password, ConfigManager.SystemConfigInfo.AdminPasswordRestriction))
            {
                errorMessage =
                    $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.AdminPasswordRestriction))}";
                return(false);
            }

            string passwordSalt;

            password = EncodePassword(password, EPasswordFormat.Encrypted, out passwordSalt);
            return(ChangePassword(userName, EPasswordFormat.Encrypted, passwordSalt, password));
        }
예제 #3
0
        private bool InsertValidate(string userName, string email, string mobile, string password, string ipAddress, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (!UserManager.IsIpAddressCached(ipAddress))
            {
                errorMessage = $"同一IP在{ConfigManager.SystemConfigInfo.UserRegistrationMinMinutes}分钟内只能注册一次";
                return(false);
            }
            if (string.IsNullOrEmpty(password))
            {
                errorMessage = "密码不能为空";
                return(false);
            }
            if (password.Length < ConfigManager.SystemConfigInfo.UserPasswordMinLength)
            {
                errorMessage = $"密码长度必须大于等于{ConfigManager.SystemConfigInfo.UserPasswordMinLength}";
                return(false);
            }
            if (!EUserPasswordRestrictionUtils.IsValid(password, ConfigManager.SystemConfigInfo.UserPasswordRestriction))
            {
                errorMessage =
                    $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.UserPasswordRestriction))}";
                return(false);
            }
            if (string.IsNullOrEmpty(userName))
            {
                errorMessage = "用户名为空,请填写用户名";
                return(false);
            }
            if (!string.IsNullOrEmpty(userName) && IsUserNameExists(userName))
            {
                errorMessage = "用户名已被注册,请更换用户名";
                return(false);
            }
            if (!IsUserNameCompliant(userName.Replace("@", string.Empty).Replace(".", string.Empty)))
            {
                errorMessage = "用户名包含不规则字符,请更换用户名";
                return(false);
            }

            if (!string.IsNullOrEmpty(email) && IsEmailExists(email))
            {
                errorMessage = "电子邮件地址已被注册,请更换邮箱";
                return(false);
            }
            if (!string.IsNullOrEmpty(mobile) && IsMobileExists(mobile))
            {
                errorMessage = "手机号码已被注册,请更换手机号码";
                return(false);
            }

            return(true);
        }
예제 #4
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            _userId    = AuthRequest.GetQueryInt("userID");
            _returnUrl = StringUtils.ValueFromUrl(AuthRequest.GetQueryString("returnUrl"));

            if (IsPostBack)
            {
                return;
            }

            VerifySystemPermissions(ConfigManager.AppPermissions.SettingsUser);

            LtlPageTitle.Text = _userId == 0 ? "添加用户" : "编辑用户";

            foreach (var groupInfo in UserGroupManager.GetUserGroupInfoList())
            {
                DdlGroupId.Items.Add(new ListItem(groupInfo.GroupName, groupInfo.Id.ToString()));
            }

            if (_userId > 0)
            {
                var userInfo = UserManager.GetUserInfoByUserId(_userId);
                if (userInfo != null)
                {
                    TbUserName.Text = userInfo.UserName;
                    ControlUtils.SelectSingleItem(DdlGroupId, userInfo.GroupId.ToString());
                    TbUserName.Enabled = false;
                    TbDisplayName.Text = userInfo.DisplayName;
                    PhPassword.Visible = false;
                    TbEmail.Text       = userInfo.Email;
                    TbMobile.Text      = userInfo.Mobile;
                }
            }

            if (!EUserPasswordRestrictionUtils.Equals(ConfigManager.SystemConfigInfo.UserPasswordRestriction, EUserPasswordRestriction.None))
            {
                LtlPasswordTips.Text = $"请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.UserPasswordRestriction))}";
            }

            if (!string.IsNullOrEmpty(_returnUrl))
            {
                BtnReturn.Attributes.Add("onclick", $"window.location.href='{_returnUrl}';return false;");
            }
            else
            {
                BtnReturn.Visible = false;
            }
        }
예제 #5
0
        public bool Insert(AdministratorInfo userInfo, out string errorMessage)
        {
            errorMessage = string.Empty;
            if (string.IsNullOrEmpty(userInfo.UserName))
            {
                errorMessage = "用户名不能为空";
                return(false);
            }
            if (userInfo.UserName.Length < ConfigManager.SystemConfigInfo.AdminUserNameMinLength)
            {
                errorMessage = $"用户名长度必须大于等于{ConfigManager.SystemConfigInfo.AdminUserNameMinLength}";
                return(false);
            }
            if (IsAdminNameExists(userInfo.UserName))
            {
                errorMessage = "用户名已存在,请更换用户名";
                return(false);
            }

            if (string.IsNullOrEmpty(userInfo.Password))
            {
                errorMessage = "密码不能为空";
                return(false);
            }
            if (userInfo.Password.Length < ConfigManager.SystemConfigInfo.AdminPasswordMinLength)
            {
                errorMessage = $"密码长度必须大于等于{ConfigManager.SystemConfigInfo.AdminPasswordMinLength}";
                return(false);
            }
            if (
                !EUserPasswordRestrictionUtils.IsValid(userInfo.Password,
                                                       ConfigManager.SystemConfigInfo.AdminPasswordRestriction))
            {
                errorMessage =
                    $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.AdminPasswordRestriction))}";
                return(false);
            }

            try
            {
                string passwordSalt;
                userInfo.Password     = EncodePassword(userInfo.Password, userInfo.PasswordFormat, out passwordSalt);
                userInfo.PasswordSalt = passwordSalt;
                Insert(userInfo);
                return(true);
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return(false);
            }
        }
예제 #6
0
        private bool InsertValidate(string userName, string password, string email, string mobile, out string errorMessage)
        {
            errorMessage = string.Empty;
            if (string.IsNullOrEmpty(userName))
            {
                errorMessage = "用户名不能为空";
                return(false);
            }
            if (userName.Length < ConfigManager.SystemConfigInfo.AdminUserNameMinLength)
            {
                errorMessage = $"用户名长度必须大于等于{ConfigManager.SystemConfigInfo.AdminUserNameMinLength}";
                return(false);
            }
            if (IsUserNameExists(userName))
            {
                errorMessage = "用户名已存在,请更换用户名";
                return(false);
            }

            if (string.IsNullOrEmpty(password))
            {
                errorMessage = "密码不能为空";
                return(false);
            }
            if (password.Length < ConfigManager.SystemConfigInfo.AdminPasswordMinLength)
            {
                errorMessage = $"密码长度必须大于等于{ConfigManager.SystemConfigInfo.AdminPasswordMinLength}";
                return(false);
            }
            if (
                !EUserPasswordRestrictionUtils.IsValid(password,
                                                       ConfigManager.SystemConfigInfo.AdminPasswordRestriction))
            {
                errorMessage =
                    $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.AdminPasswordRestriction))}";
                return(false);
            }

            if (!string.IsNullOrEmpty(email) && IsEmailExists(email))
            {
                errorMessage = "电子邮件地址已被注册,请更换邮箱";
                return(false);
            }
            if (!string.IsNullOrEmpty(mobile) && IsMobileExists(mobile))
            {
                errorMessage = "手机号码已被注册,请更换手机号码";
                return(false);
            }

            return(true);
        }
예제 #7
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            _userId    = Body.GetQueryInt("userID");
            _returnUrl = StringUtils.ValueFromUrl(Body.GetQueryString("returnUrl"));

            if (IsPostBack)
            {
                return;
            }

            var pageTitle = _userId == 0 ? "添加用户" : "编辑用户";

            BreadCrumbUser(AppManager.User.LeftMenu.UserConfiguration, pageTitle, AppManager.User.Permission.UserConfiguration);

            LtlPageTitle.Text = pageTitle;
            if (_userId > 0)
            {
                var userInfo = BaiRongDataProvider.UserDao.GetUserInfo(_userId);
                if (userInfo != null)
                {
                    TbUserName.Text    = userInfo.UserName;
                    TbUserName.Enabled = false;
                    TbDisplayName.Text = userInfo.DisplayName;
                    PhPassword.Visible = false;
                    TbEmail.Text       = userInfo.Email;
                    TbMobile.Text      = userInfo.Mobile;
                }
            }

            if (ConfigManager.UserConfigInfo.RegisterPasswordRestriction != EUserPasswordRestriction.None)
            {
                LtlPasswordTips.Text =
                    $"(请包含{EUserPasswordRestrictionUtils.GetText(ConfigManager.UserConfigInfo.RegisterPasswordRestriction)})";
            }

            if (!string.IsNullOrEmpty(_returnUrl))
            {
                BtnReturn.Attributes.Add("onclick", $"window.location.href='{_returnUrl}';return false;");
            }
            else
            {
                BtnReturn.Visible = false;
            }
        }
예제 #8
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            _userId    = Body.GetQueryInt("userID");
            _returnUrl = StringUtils.ValueFromUrl(Body.GetQueryString("returnUrl"));

            if (IsPostBack)
            {
                return;
            }

            VerifyAdministratorPermissions(ConfigManager.Permissions.Settings.User);

            LtlPageTitle.Text = _userId == 0 ? "添加用户" : "编辑用户";

            if (_userId > 0)
            {
                var userInfo = DataProvider.UserDao.GetUserInfo(_userId);
                if (userInfo != null)
                {
                    TbUserName.Text    = userInfo.UserName;
                    TbUserName.Enabled = false;
                    TbDisplayName.Text = userInfo.DisplayName;
                    PhPassword.Visible = false;
                    TbEmail.Text       = userInfo.Email;
                    TbMobile.Text      = userInfo.Mobile;
                }
            }

            if (!EUserPasswordRestrictionUtils.Equals(ConfigManager.SystemConfigInfo.UserPasswordRestriction, EUserPasswordRestriction.None))
            {
                LtlPasswordTips.Text = $"请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.UserPasswordRestriction))}";
            }

            if (!string.IsNullOrEmpty(_returnUrl))
            {
                BtnReturn.Attributes.Add("onclick", $"window.location.href='{_returnUrl}';return false;");
            }
            else
            {
                BtnReturn.Visible = false;
            }
        }
예제 #9
0
 public bool IsPasswordCorrect(string password, out string errorMessage)
 {
     errorMessage = null;
     if (string.IsNullOrEmpty(password))
     {
         errorMessage = "密码不能为空";
         return(false);
     }
     if (password.Length < ConfigManager.SystemConfigInfo.UserPasswordMinLength)
     {
         errorMessage = $"密码长度必须大于等于{ConfigManager.SystemConfigInfo.UserPasswordMinLength}";
         return(false);
     }
     if (!EUserPasswordRestrictionUtils.IsValid(password, ConfigManager.SystemConfigInfo.UserPasswordRestriction))
     {
         errorMessage =
             $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.UserPasswordRestriction))}";
         return(false);
     }
     return(true);
 }
예제 #10
0
        public bool ChangePassword(string userName, string password, out string errorMessage)
        {
            errorMessage = null;
            if (password.Length < ConfigManager.SystemConfigInfo.UserPasswordMinLength)
            {
                errorMessage = $"密码长度必须大于等于{ConfigManager.SystemConfigInfo.UserPasswordMinLength}";
                return(false);
            }
            if (!EUserPasswordRestrictionUtils.IsValid(password, ConfigManager.SystemConfigInfo.UserPasswordRestriction))
            {
                errorMessage =
                    $"密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestrictionUtils.GetEnumType(ConfigManager.SystemConfigInfo.UserPasswordRestriction))}";
                return(false);
            }

            var passwordFormat = EPasswordFormat.Encrypted;
            var passwordSalt   = GenerateSalt();

            password = EncodePassword(password, passwordFormat, passwordSalt);
            ChangePassword(userName, passwordFormat, passwordSalt, password);
            return(true);
        }
예제 #11
0
        public static async Task Execute(IJobContext context)
        {
            if (!CliUtils.ParseArgs(Options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            try
            {
                if (string.IsNullOrEmpty(_userName))
                {
                    await CliUtils.PrintErrorAsync("未设置参数管理员用户名:{userName} !");

                    return;
                }

                if (string.IsNullOrEmpty(_password))
                {
                    await CliUtils.PrintErrorAsync("未设置参数管理员密码:{password} !");

                    return;
                }

                if (_password.Length < 6)
                {
                    await CliUtils.PrintErrorAsync("管理员密码必须大于6位 !");

                    return;
                }

                if (!EUserPasswordRestrictionUtils.IsValid(_password, EUserPasswordRestrictionUtils.GetValue(EUserPasswordRestriction.LetterAndDigit)))
                {
                    await CliUtils.PrintErrorAsync($"管理员密码不符合规则,请包含{EUserPasswordRestrictionUtils.GetText(EUserPasswordRestriction.LetterAndDigit)}");

                    return;
                }

                var webConfigPath = PathUtils.Combine(CliUtils.PhysicalApplicationPath, "web.config");
                if (!FileUtils.IsFileExists(webConfigPath))
                {
                    await CliUtils.PrintErrorAsync($"系统配置文件不存在:{webConfigPath}!");

                    return;
                }

                if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString))
                {
                    await CliUtils.PrintErrorAsync("web.config 中数据库连接字符串 connectionString 未设置");

                    return;
                }

                WebConfigUtils.Load(CliUtils.PhysicalApplicationPath, "web.config");

                await Console.Out.WriteLineAsync($"数据库类型: {WebConfigUtils.DatabaseType.Value}");

                await Console.Out.WriteLineAsync($"连接字符串: {WebConfigUtils.ConnectionString}");

                await Console.Out.WriteLineAsync($"系统文件夹: {CliUtils.PhysicalApplicationPath}");

                if (!DataProvider.DatabaseDao.IsConnectionStringWork(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString))
                {
                    await CliUtils.PrintErrorAsync("系统无法连接到 web.config 中设置的数据库");

                    return;
                }

                if (!SystemManager.IsNeedInstall())
                {
                    await CliUtils.PrintErrorAsync("系统已安装在 web.config 指定的数据库中,命令执行失败");

                    return;
                }

                WebConfigUtils.UpdateWebConfig(WebConfigUtils.IsProtectData, WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString, WebConfigUtils.AdminDirectory, StringUtils.GetShortGuid(), false);

                DataProvider.Reset();

                SystemManager.InstallDatabase(_userName, _password);
            }
            catch (Exception e)
            {
                await CliUtils.PrintErrorAsync(e.Message);

                return;
            }

            await Console.Out.WriteLineAsync("恭喜,系统安装成功!");
        }
예제 #12
0
        public void Page_Load(object sender, EventArgs e)
        {
            if (IsForbidden)
            {
                return;
            }

            _userId    = Body.GetQueryInt("userID");
            _returnUrl = StringUtils.ValueFromUrl(Body.GetQueryString("returnUrl"));

            if (IsPostBack)
            {
                return;
            }

            var pageTitle = _userId == 0 ? "添加用户" : "编辑用户";

            BreadCrumbUser(AppManager.User.LeftMenu.UserConfiguration, pageTitle, AppManager.User.Permission.UserConfiguration);

            LtlPageTitle.Text = pageTitle;
            if (_userId > 0)
            {
                var userInfo = BaiRongDataProvider.UserDao.GetUserInfoAll(_userId);
                if (userInfo != null)
                {
                    TbUserName.Text              = userInfo.UserName;
                    TbUserName.Enabled           = false;
                    TbDisplayName.Text           = userInfo.DisplayName;
                    PhPassword.Visible           = false;
                    TbEmail.Text                 = userInfo.Email;
                    TbMobile.Text                = userInfo.Mobile;
                    TbGender.Text                = userInfo.Gender;
                    TbIdCode.Text                = userInfo.IdCode;
                    TbPublishmentSystemName.Text = PublishmentSystemManager.GetPublishmentSystemInfo(userInfo.PublishmentSystemId).PublishmentSystemName;
                    TbPosition.Text              = userInfo.Position;
                    TbFlowPartyMember.Text       = userInfo.FlowPartyMember.ToString();
                    TbNation.Text                = userInfo.Nation;
                    TbNativePlace.Text           = userInfo.NativePlace;
                    TbTelePhone.Text             = userInfo.Additional.TelePhone;
                    TbEmergencyName.Text         = userInfo.Additional.EmergencyName;
                    TbEmergencyMobile.Text       = userInfo.Additional.EmergencyMobile;
                    TbEmergencyRalationship.Text = userInfo.Additional.EmergencyRalationShip;
                    TbAddress.Text               = userInfo.Additional.PostalAddress;
                }
            }

            if (ConfigManager.UserConfigInfo.RegisterPasswordRestriction != EUserPasswordRestriction.None)
            {
                LtlPasswordTips.Text =
                    $"(请包含{EUserPasswordRestrictionUtils.GetText(ConfigManager.UserConfigInfo.RegisterPasswordRestriction)})";
            }

            if (!string.IsNullOrEmpty(_returnUrl))
            {
                BtnReturn.Attributes.Add("onclick", $"window.location.href='{_returnUrl}';return false;");
            }
            else
            {
                BtnReturn.Visible = false;
            }
        }