public Identity(User user, bool isAuthenticated) { _isAuthenticated = isAuthenticated && user != null; _name = user == null ? string.Empty : user.Name; _email = user == null ? string.Empty : user.Email; _userId = user == null ? 0 : user.Id; }
private static void SetUser(HttpContext context, User user, string[] roles, bool isAutheticated) { Identity identity = new Identity(user, isAutheticated); Principal principal = new Principal(identity, roles); context.User = principal; string langName = string.Empty; if (user == null) { if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length > 0 && HttpContext.Current.Request.UserLanguages[0].Length >= 2) langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2); } else { langName = user.Locale; } var localeProvider = IoCcontainer.Instance.Resolve<ILocaleProvider>(); LocaleData locale = localeProvider.GetCultureByName(langName); RequestContext.SetValue(RequestContext.LocaleKey, locale); }