コード例 #1
0
        public static void Authorize(Login login)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(Localizer.SupportedLanguages[bv.common.Core.Localizer.lngEn]);
            Thread.CurrentThread.CurrentCulture   = Thread.CurrentThread.CurrentUICulture;

            if (string.IsNullOrEmpty(login.language) || !Localizer.SupportedLanguages.ContainsKey(login.language))
            {
                throw new AuthLanguageException();
            }

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(Localizer.SupportedLanguages[login.language]);
            Thread.CurrentThread.CurrentCulture   = Thread.CurrentThread.CurrentUICulture;

            if (!string.IsNullOrEmpty(login.externalSystem) && !SupportedExternalSystem.ContainsKey(login.externalSystem))
            {
                throw new AuthExternalException();
            }

            var security = new EidssSecurityManager();
            var result   = security.LogIn(login.organization, login.user, login.password);

            switch (result)
            {
            case 0:
                break;

            case 1:
                throw new AuthEmptyException();

            case 2:
                throw new AuthNotFoundException();

            case 3:
            case 4:
            case 5:
                throw new AuthVersionException();

            case 6:
                throw new AuthLockedException(security.GetAccountLockTimeout(login.organization, login.user));

            case 9:
                throw new AuthExpiredException();

            default:
                throw new AuthFailedException();
            }

            EidssUserContext.CurrentLanguage = login.language;
        }
コード例 #2
0
        /*public bool ValidateOnChange()
         * {
         *  if (NewPassword != ConfirmPassword)
         *  {
         *      ErrorMessage = Translator.GetMessageString("msgConfirmPasswordError");
         *      return false;
         *  }
         *  var security = new EidssSecurityManager();
         *  var result = security.LogIn(Organization, UserName, OldPassword);
         *  if (result == 0) //authorized
         *  {
         *      return true;
         *  }
         *  else
         *  {
         *      ErrorMessage = SecurityMessages.GetLoginErrorMessage(result);
         *      return false;
         *  }
         * }*/

        public bool Authorize()
        {
            var security = new EidssSecurityManager();
            var result   = security.LogIn(Organization, UserName, Password);

            switch (result)
            {
            case 0:
                EidssUserContext.CurrentLanguage = Cultures.GetLanguageAbbreviation(LanguagePreference);
                System.Web.Security.FormsAuthentication.SetAuthCookie(this.UserName, false);
                return(true);

            case 6:
                int    lockInMinutes = security.GetAccountLockTimeout(this.Organization, this.UserName);
                string err           = BvMessages.Get("ErrLoginIsLocked", "You have exceeded the number of incorrect login attempts. Please try again in {0} minutes.");
                ErrorMessage = string.Format(err, lockInMinutes);
                return(false);

            default:
                ErrorMessage = SecurityMessages.GetLoginErrorMessage(result);
                return(false);
            }
        }