private void Init() { var context = Html.ViewContext.RequestContext.HttpContext; var page = App.Get().CurrentPage; UserDecorator user = context.Request.IsAuthenticated ? App.Get().User : null; if (page != null && page.Widgets != null) { var cache = Context.Cache; var key = "page" + page.ID + "_widgets"; List <WidgetInstance> widgets = null; if (cache[key] != null) { widgets = (List <WidgetInstance>)cache[key]; } else { widgets = page.Widgets.Where(w => w.IsExpanded).Select(w => w.Model).ToList(); cache.Add(key, widgets, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } var instances = widgets.Where(w => w.ZoneID.Equals(Component.Id, StringComparison.OrdinalIgnoreCase)) .Select(w => new WidgetInstanceDecorator(w, App.Get().DataContext.Widgets)) .OrderBy(w => w.ZoneID) .ThenBy(w => w.Pos) .ToList(); foreach (var instance in instances) { if (instance.Roles != null && instance.Roles.Count() > 0) { if (!context.Request.IsAuthenticated) { continue; } var inrole = false; foreach (var r in instance.Roles) { if (user.IsInRole(r)) { inrole = true; break; } } if (!inrole) { continue; } } Component.Widgets.Add(new Widget() { Name = "widget_" + instance.ID.ToString(), Model = instance, Html = this.Html }); } } }
public static void Show() { User user = new User() { Name = "Eleven", Password = "******" }; IUserProcessor processor = new UserProcessor(); processor = new UserDecorator(processor); processor.RegUser(user); }
public ActionResult Validate(string token, string pwd, string confirmPwd) { var user = App.Get().DataContext.Find <User>(u => !string.IsNullOrEmpty(u.RetrievalToken) && u.RetrievalToken.Equals(token)); if (user != null) { var userWarpper = new UserDecorator(user, App.Get().DataContext); userWarpper.ChangePassword(pwd, confirmPwd); user.RetrievalToken = ""; user.IsVaildMail = true; App.Get().DataContext.SaveChanges(); FormsAuthentication.SetAuthCookie(user.UserName, true); } return(View(user)); }
public ActionResult Login(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { var username = model.UserName; var member = dbContext.Users.Find(username); if (member == null) { member = dbContext.Users.Find(u => u.Email.Equals(username)); } if (member != null && dbContext.Users.Validate(model.UserName, model.Password)) { WebCache.Remove("_Identity_Cache"); member.LastLoginDate = DateTime.Now; member.LastLoginIP = Request.UserHostAddress; FormsAuthentication.SetAuthCookie(username, model.RememberMe); this.Trigger("Login", model); //EventDispatcher.RaiseUserLogin(username); if (!Request.IsAjaxRequest()) { if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } else { return(Redirect("~/")); } } } else { var user = new UserDecorator(member, dbContext); string json = JsonConvert.SerializeObject(user.ToObject(), new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }); return(Content(json, "application/json", Encoding.UTF8)); } } else { if (member == null) { ModelState.AddModelError("UserName", String.Format(Resources.Validations.NotExists_Format, model.UserName)); } else { ModelState.AddModelError("Password", Resources.Validations.Password_Incorrect); } } } return(View()); }
LdClient(Configuration configuration, User user, TimeSpan startWaitTime) { if (user == null) { throw new ArgumentNullException(nameof(user)); } _config = configuration ?? throw new ArgumentNullException(nameof(configuration)); var diagnosticStore = _config.DiagnosticOptOut ? null : new ClientDiagnosticStore(_config, startWaitTime); var diagnosticDisabler = _config.DiagnosticOptOut ? null : new DiagnosticDisablerImpl(); _context = new LdClientContext(configuration, this, diagnosticStore, diagnosticDisabler); _log = _context.BaseLogger; _taskExecutor = _context.TaskExecutor; diagnosticStore?.SetContext(_context); _log.Info("Starting LaunchDarkly Client {0}", Version); var persistenceConfiguration = (configuration.PersistenceConfigurationBuilder ?? Components.Persistence()) .CreatePersistenceConfiguration(_context); _dataStore = new FlagDataManager( configuration.MobileKey, persistenceConfiguration, _log.SubLogger(LogNames.DataStoreSubLog) ); _userDecorator = new UserDecorator(configuration.DeviceInfo ?? new DefaultDeviceInfo(), _dataStore.PersistentStore); _user = _userDecorator.DecorateUser(user); // If we had cached data for the new user, set the current in-memory flag data state to use // that data, so that any Variation calls made before Identify has completed will use the // last known values. var cachedData = _dataStore.GetCachedData(_user); if (cachedData != null) { _log.Debug("Cached flag data is available for this user"); _dataStore.Init(_user, cachedData.Value, false); // false means "don't rewrite the flags to persistent storage" } var dataSourceUpdateSink = new DataSourceUpdateSinkImpl( _dataStore, configuration.Offline, _taskExecutor, _log.SubLogger(LogNames.DataSourceSubLog) ); _dataSourceUpdateSink = dataSourceUpdateSink; _dataSourceStatusProvider = new DataSourceStatusProviderImpl(dataSourceUpdateSink); _flagTracker = new FlagTrackerImpl(dataSourceUpdateSink); var dataSourceFactory = configuration.DataSourceFactory ?? Components.StreamingDataSource(); _connectivityStateManager = Factory.CreateConnectivityStateManager(configuration); var isConnected = _connectivityStateManager.IsConnected; diagnosticDisabler?.SetDisabled(!isConnected || configuration.Offline); _eventProcessor = (configuration.EventProcessorFactory ?? Components.SendEvents()) .CreateEventProcessor(_context); _eventProcessor.SetOffline(configuration.Offline || !isConnected); _connectionManager = new ConnectionManager( _context, dataSourceFactory, _dataSourceUpdateSink, _eventProcessor, diagnosticDisabler, configuration.EnableBackgroundUpdating, _user, _log ); _connectionManager.SetForceOffline(configuration.Offline); _connectionManager.SetNetworkEnabled(isConnected); if (configuration.Offline) { _log.Info("Starting LaunchDarkly client in offline mode"); } _connectivityStateManager.ConnectionChanged += networkAvailable => { _log.Debug("Setting online to {0} due to a connectivity change event", networkAvailable); _ = _connectionManager.SetNetworkEnabled(networkAvailable); // do not await the result }; // Send an initial identify event, but only if we weren't explicitly set to be offline if (!configuration.Offline) { _eventProcessor.RecordIdentifyEvent(new EventProcessorTypes.IdentifyEvent { Timestamp = UnixMillisecondTime.Now, User = user }); } _backgroundModeManager = _config.BackgroundModeManager ?? new DefaultBackgroundModeManager(); _backgroundModeManager.BackgroundModeChanged += OnBackgroundModeChanged; }
public ActionResult Validate(string token, string pwd, string confirmPwd) { var user = App.Get().DataContext.Find<User>(u => !string.IsNullOrEmpty(u.RetrievalToken) && u.RetrievalToken.Equals(token)); if (user != null) { var userWarpper = new UserDecorator(user, App.Get().DataContext); userWarpper.ChangePassword(pwd, confirmPwd); user.RetrievalToken = ""; user.IsVaildMail = true; App.Get().DataContext.SaveChanges(); FormsAuthentication.SetAuthCookie(user.UserName, true); } return View(user); }
public ActionResult Login(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { var username = model.UserName; var member = dbContext.Users.Find(username); if (member == null) member = dbContext.Users.Find(u => u.Email.Equals(username)); if (member != null && dbContext.Users.Validate(model.UserName, model.Password)) { WebCache.Remove("_Identity_Cache"); member.LastLoginDate = DateTime.Now; member.LastLoginIP = Request.UserHostAddress; FormsAuthentication.SetAuthCookie(username, model.RememberMe); this.Trigger("Login", model); //EventDispatcher.RaiseUserLogin(username); if (!Request.IsAjaxRequest()) { if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl)) return Redirect(returnUrl); else return Redirect("~/"); } } else { var user = new UserDecorator(member, dbContext); string json = JsonConvert.SerializeObject(user.ToObject(), new JsonSerializerSettings() { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }); return Content(json, "application/json", Encoding.UTF8); } } else { if (member == null) ModelState.AddModelError("UserName", String.Format(Resources.Validations.NotExists_Format, model.UserName)); else ModelState.AddModelError("Password", Resources.Validations.Password_Incorrect); } } return View(); }