示例#1
0
 /// <summary>
 /// Vrati aktualne nastaveny jazyk pre prichadzajuci request
 /// </summary>
 /// <param name="language">Jazyk z hlavicky requestu</param>
 /// <returns>Aktualne nastaveny jazyk, alebo default</returns>
 public static Nullable <LanguageTypes> GetLanguage(String language)
 {
     foreach (LanguageTypes item in Enum.GetValues(typeof(LanguageTypes)))
     {
         FieldInfo           fieldInfo  = item.GetType().GetField(item.ToString());
         LanguageAttribute[] attributes = (LanguageAttribute[])fieldInfo.GetCustomAttributes(typeof(LanguageAttribute), false);
         if (attributes != null && attributes.Length > 0)
         {
             foreach (LanguageAttribute attribute in attributes)
             {
                 if (String.Compare(attribute.Culture, language, true) == 0 || String.Compare(attribute.IsoCode, language) == 0)
                 {
                     UserBase.InternalSetCurrentLanguage(item);
                     return(item);
                 }
             }
         }
     }
     return(null);
 }
示例#2
0
        /// <summary>
        /// Vrati aktualne nastaveny jazyk pre prichadzajuci request
        /// </summary>
        /// <returns>Aktualne nastaveny jazyk, alebo default</returns>
        private static LanguageTypes InternalGetCurrentLanguage()
        {
            HttpContext current      = HttpContext.Current;
            var         languageItem = current.Items[UserBase.LanguageCookieName];

            if (languageItem == null || languageItem.GetType() != typeof(LanguageTypes))
            {
                Nullable <LanguageTypes> language = null;
                if (current != null)
                {
                    HttpRequest request = current.Request;
                    if (request != null)
                    {
                        HttpCookie cookie = request.Cookies.Get(UserBase.LanguageCookieName);
                        if (cookie != null)
                        {
                            language = UserBase.GetLanguage(cookie.Value);
                        }
                        else if (request.UserLanguages != null && request.UserLanguages.Length > 0)
                        {
                            for (int i = 0; i < request.UserLanguages.Length; i++)
                            {
                                language = UserBase.GetLanguage(request.UserLanguages[i]);
                                if (language != null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (language == null)
                {
                    language = UserBase.InternalGetDefaultLanguage();
                }
                return(language.Value);
            }
            return((LanguageTypes)languageItem);
        }
示例#3
0
        /// <summary>
        /// Odhlasi aktualneho uzivatela
        /// </summary>
        public static UserBase CurrentUserLogOff()
        {
            UserBase user = UserBase.InternalGetCurrentUser();

            if (user != null)
            {
                HttpContext current = HttpContext.Current;
                if (current != null)
                {
                    HttpRequest request = current.Request;
                    if (request != null)
                    {
                        HttpCookie cookie = request.Cookies.Get(UserBase.UserCookieName);
                        if (cookie != null)
                        {
                            String token = cookie.Value;
                            if (!String.IsNullOrWhiteSpace(token))
                            {
                                if (UserBase.InternalUserBaseValidateToken(token, UserBase.InternalGetHostAddress()))
                                {
                                    Nullable <Guid> userId = UserBase.InternalUserBaseGetUserLoginIdFromToken(token, UserBase.InternalGetHostAddress());
                                    if (userId != null)
                                    {
                                        UserBase.InternalUserBaseUserLogOff(userId.Value);
                                    }
                                }
                                cookie.Value   = String.Empty;
                                cookie.Expires = DateTime.Now;
                                current.Response.SetCookie(cookie);
                            }
                        }
                    }
                }
            }
            return(user);
        }
示例#4
0
 /// <summary>
 /// Ulozi aktualneho uzivatela do CurrentUser
 /// </summary>
 /// <param name="user">Uzivatel ktoreho chceme ulozit</param>
 private static void InternalSetCurrentUser(UserBase user)
 {
     HttpContext current = HttpContext.Current;
     if (current != null)
     {
         if (current.Items.Contains(UserBase.UserCookieName))
         {
             //update
             current.Items[UserBase.UserCookieName] = user;
         }
         else
         {
             //insert
             current.Items.Add(UserBase.UserCookieName, user);
         }
     }
 }
示例#5
0
 /// <summary>
 /// Vrati host adress pre aktualneho uzivatela
 /// </summary>
 /// <returns>Host address</returns>
 public static String GetHostAddress()
 {
     return(UserBase.InternalGetHostAddress());
 }
示例#6
0
 /// <summary>
 /// Vykona prihlasenie uzivatela
 /// </summary>
 /// <param name="name">Meno uzivatela</param>
 /// <param name="password">Heslo uzivatela</param>
 /// <returns>Prihlaseny uzivatel alebo null</returns>
 public static UserBase Login(String name, String password)
 {
     return(UserBase.InternalLogin(name, password));
 }