/// <summary> /// Validate the model /// </summary> /// <param name="context">the validation context</param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(ValidationContext context) { var userService = HostContainer.GetInstance <IUserService>(); var remoteService = HostContainer.GetInstance <IRemoteUserService>(); var localizedResourceService = HostContainer.GetInstance <IEzCMSLocalizedResourceService>(); var user = userService.GetById(UserId); if (!user.IsRemoteAccount) { var hashPass = user.Password; var hashPassCompare = PasswordUtilities.CreateHashPassword(OldPassword, user.PasswordSalt); if (!hashPass.Equals(hashPassCompare)) { yield return(new ValidationResult(localizedResourceService.T("User_Message_InvalidOldPassword"))); } } else { var username = string.IsNullOrEmpty(user.Username) ? user.Email : user.Username; if (!remoteService.ValidateUsernamePassword(username, OldPassword)) { yield return(new ValidationResult(localizedResourceService.T("User_Message_InvalidOldPassword"))); } } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (!string.IsNullOrEmpty(_publicKey) && !string.IsNullOrEmpty(_privateKey)) { var localizedResourceService = HostContainer.GetInstance <ILocalizedResourceService>(); var controller = (Controller)HttpContext.Current.Items[FrameworkConstants.EzCurrentController]; RecaptchaVerificationHelper recaptchaHelper = controller.GetRecaptchaVerificationHelper(_privateKey); if (string.IsNullOrEmpty(recaptchaHelper.Response)) { filterContext.Controller.ViewData.ModelState.AddModelError(Name, localizedResourceService.T("CaptchaValidation_Message_EmptyCaptcha")); } RecaptchaVerificationResult recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse(); if (recaptchaResult != RecaptchaVerificationResult.Success) { filterContext.Controller.ViewData.ModelState.AddModelError(Name, localizedResourceService.T("CaptchaValidation_Message_InvalidCaptchaAnswer")); } } base.OnActionExecuting(filterContext); }
public EmailValidationAttribute() : base(@"^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$") { var localizedResourceServies = HostContainer.GetInstance <ILocalizedResourceService>(); ErrorMessage = localizedResourceServies.T("System_Message_InvalidEmailFormat"); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var localizedResourceService = HostContainer.GetInstance <IEzCMSLocalizedResourceService>(); var type = Type.GetType(DataType); if (type != null) { var razorValidMessage = string.Empty; try { var cacheName = Subject.GetTemplateCacheName(Body); EzRazorEngineHelper.TryCompileAndAddTemplate(Body, cacheName, type); } catch (TemplateParsingException exception) { razorValidMessage = exception.Message; } catch (TemplateCompilationException exception) { razorValidMessage = string.Join("\n", exception.CompilerErrors.Select(e => e.ErrorText)); } catch (Exception exception) { razorValidMessage = exception.Message; } if (!string.IsNullOrEmpty(razorValidMessage)) { yield return(new ValidationResult(string.Format(localizedResourceService.T("EmailTemplate_Message_TemplateCompileFailure"), razorValidMessage), new[] { "Body" })); } } }
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userService = HostContainer.GetInstance <IUserService>(); try { var user = userService.CheckLogin(context.UserName, context.Password); if (user != null) { var id = new ClaimsIdentity("Embedded"); id.AddClaim(new Claim("sub", context.UserName)); id.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); id.AddClaim(new Claim(ClaimTypes.Role, string.Join(FrameworkConstants.Colon, user.UserUserGroups.Select(i => i.UserGroup.Name)))); context.Validated(id); } else { context.Rejected(); } } catch (Exception) { context.Rejected(); } return(base.GrantResourceOwnerCredentials(context)); }
/// <summary> /// Validate the model /// </summary> /// <param name="context">the validation context</param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(ValidationContext context) { var templateService = HostContainer.GetInstance <IWidgetTemplateService>(); var localizedResourceService = HostContainer.GetInstance <IEzCMSLocalizedResourceService>(); if (templateService.IsTemplateNameExisted(Id, Name)) { yield return(new ValidationResult(localizedResourceService.T("WidgetTemplate_Message_ExistingName"), new[] { "Name" })); } var type = Type.GetType(DataType); if (type != null) { var razorValidMessage = EzRazorEngineHelper.ValidateTemplate(Name, FullContent, type); if (!string.IsNullOrEmpty(razorValidMessage)) { yield return(new ValidationResult(string.Format(localizedResourceService.T("WidgetTemplate_Message_FullContentCompileFailure"), razorValidMessage), new[] { "FullContent" })); } //Generate content from widgets var content = WidgetHelper.GetFullTemplate(Content, string.Empty, string.Empty, DataType, Shortcuts); razorValidMessage = EzRazorEngineHelper.ValidateTemplate(Name, content, type); if (!string.IsNullOrEmpty(razorValidMessage)) { yield return(new ValidationResult(string.Format(localizedResourceService.T("WidgetTemplate_Message_ContentCompileFailure"), razorValidMessage), new[] { "Content" })); } razorValidMessage = EzRazorEngineHelper.ValidateTemplate(Name, Script, type); if (!string.IsNullOrEmpty(razorValidMessage)) { yield return(new ValidationResult(string.Format(localizedResourceService.T("WidgetTemplate_Message_ScriptCompileFailure"), razorValidMessage), new[] { "Script" })); } razorValidMessage = EzRazorEngineHelper.ValidateTemplate(Name, Style, type); if (!string.IsNullOrEmpty(razorValidMessage)) { yield return(new ValidationResult(string.Format(localizedResourceService.T("WidgetTemplate_Message_StyleCompileFailure"), razorValidMessage), new[] { "Style" })); } if (Shortcuts != null) { var widgetValidationMessages = new Dictionary <string, string>(); foreach (var widget in Shortcuts) { razorValidMessage = EzRazorEngineHelper.ValidateTemplate(widget.Name, widget.Content, type); if (!string.IsNullOrEmpty(razorValidMessage)) { widgetValidationMessages.Add(widget.Name, razorValidMessage); } } if (widgetValidationMessages.Any()) { var message = string.Join(FrameworkConstants.BreakLine, widgetValidationMessages.Select(widget => localizedResourceService.TFormat("WidgetTemplate_Message_WidgetCompileFailure", widget.Key, widget.Value))); yield return(new ValidationResult(message, new[] { "Widgets" })); } } } }
/// <summary> /// Validate the model /// </summary> /// <param name="context">the validation context</param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(ValidationContext context) { var userService = HostContainer.GetInstance <IUserService>(); var localizedResourceService = HostContainer.GetInstance <IEzCMSLocalizedResourceService>(); if (Id <= 0) { if (string.IsNullOrWhiteSpace(Email)) { yield return(new ValidationResult(localizedResourceService.T("User_Message_EmailRequired"), new[] { "Email" })); } if (string.IsNullOrWhiteSpace(Password)) { yield return(new ValidationResult(localizedResourceService.T("User_Message_PasswordRequired"), new[] { "Password" })); } } var username = string.IsNullOrEmpty(Username) ? Email : Username; if (userService.IsUsernameExisted(Id, username)) { if (string.IsNullOrEmpty(Username)) { yield return(new ValidationResult(localizedResourceService.T("User_Message_ExistingEmail"), new[] { "Email" })); } else { yield return(new ValidationResult(localizedResourceService.T("User_Message_ExistingUsername"), new[] { "Username" })); } } }
public EventScheduleWidget(EventSchedule eventSchedule, string dateFormat, string timeFormat) : this(eventSchedule) { var eventScheduleService = HostContainer.GetInstance <IEventScheduleService>(); TimeFrame = eventScheduleService.GetEventScheduleTimeFrame(TimeStart, TimeEnd, dateFormat, timeFormat); }
public SimpleUserModel(string username) : this() { var userService = HostContainer.GetInstance <IUserService>(); var user = userService.GetByUsername(username); if (user != null) { FullName = user.FullName; Username = string.IsNullOrEmpty(user.Username) ? user.Email : user.Username; if (string.IsNullOrEmpty(user.AvatarFileName) || !File.Exists( HttpContext.Current.Server.MapPath(EzCMSContants.AvatarFolder + user.AvatarFileName))) { AvatarPath = EzCMSContants.NoAvatar; } else { AvatarPath = EzCMSContants.AvatarFolder + user.AvatarFileName; } } else { FullName = username; Username = username; } }
/// <summary> /// Execute the background task /// </summary> /// <param name="context"></param> public void Run(BackgroundTaskExecuteContext context) { var logger = HostContainer.GetInstance <ILogger>(); var countUsers = 0; if (Interlocked.CompareExchange(ref _hasActiveTask, 1, 0) == 0) { try { logger.Info(string.Format("[{0}] Start deactivation expired accounts task", EzCMSContants.DeactivationExpiredAccountsTaskName)); //Update the background task last running time var backgroundTaskService = HostContainer.GetInstance <IEzBackgroundTaskService>(); backgroundTaskService.UpdateLastRunningTimeTask(GetType()); var userService = HostContainer.GetInstance <IUserService>(); var usersNeedDeactive = userService.GetUsersNeedDeactive().ToList(); foreach (var user in usersNeedDeactive) { userService.DeactiveExpiredAccount(user); userService.SendDeactivationEmail(user); countUsers++; } } catch (Exception exception) { logger.Error(exception); } logger.Info(string.Format("[{0}] End deactivation expired accounts task. Deactivate {1} account(s)", EzCMSContants.DeactivationExpiredAccountsTaskName, countUsers)); Interlocked.Exchange(ref _hasActiveTask, 0); } }
public RotatingImageManageModel() { _rotatingImageGroupService = HostContainer.GetInstance <IRotatingImageGroupService>(); Groups = _rotatingImageGroupService.GetRotatingImageGroups(); UrlTargets = EnumUtilities.GenerateSelectListItems <CommonEnums.UrlTarget>(GenerateEnumType.DescriptionValueAndDescriptionText); Url = "#"; }
public SiteSettingSearchModel() { var siteSettingService = HostContainer.GetInstance <ISiteSettingService>(); SettingTypeNames = new List <string>(); SettingTypes = siteSettingService.GetSettingTypes(); }
public LinkManageModel() { _linkTypeService = HostContainer.GetInstance <ILinkTypeService>(); LinkTypes = _linkTypeService.GetLinkTypes(); UrlTargets = EnumUtilities.GenerateSelectListItems <CommonEnums.UrlTarget>(GenerateEnumType.DescriptionValueAndDescriptionText); }
public FormComponentFieldManageModel() { _formComponentService = HostContainer.GetInstance <IFormComponentService>(); FormComponents = _formComponentService.GetFormComponents(); Attributes = new FormComponentFieldAttributeModel(); }
public UserServices(PXHotelEntities entities) { _localizedResourceServices = HostContainer.GetInstance <ILocalizedResourceServices>(); _userGroupServices = HostContainer.GetInstance <IUserGroupServices>(); _userRepository = new UserRepository(entities); _userInGroupRepository = new UserInGroupRepository(entities); }
public PageManageModel(Page page) { _pageServices = HostContainer.GetInstance <IPageServices>(); var pageTemplateServices = HostContainer.GetInstance <IPageTemplateServices>(); var fileTemplateServices = HostContainer.GetInstance <IFileTemplateServices>(); int position; int relativePageId; var relativePages = _pageServices.GetRelativePages(out position, out relativePageId, page.Id, page.ParentId); Id = page.Id; Content = page.Content; Title = page.Title; FriendlyUrl = page.FriendlyUrl; Caption = page.Caption; Status = page.Status; StatusList = _pageServices.GetStatus(); ParentId = page.ParentId; Parents = _pageServices.GetPossibleParents(page.Id); FileTemplateId = page.FileTemplateId; FileTemplates = fileTemplateServices.GetFileTemplateSelectList(page.FileTemplateId); PageTemplateId = page.PageTemplateId; PageTemplates = pageTemplateServices.GetPageTemplateSelectList(page.PageTemplateId); Position = position; Positions = EnumUtilities.GetSelectListFromEnum <PageEnums.PositionEnums>(); RelativePageId = relativePageId; RelativePages = relativePages; IncludeInSiteNavigation = page.IncludeInSiteNavigation; Tags = page.PageTags.Select(t => t.TagId).ToList(); TagList = _pageServices.GetPageTags(page.Id); StartPublishingDate = page.StartPublishingDate; EndPublishingDate = page.EndPublishingDate; RecordOrder = page.RecordOrder; RecordActive = page.RecordActive; }
public SettingServices(PXHotelEntities entities) { _localizedResourceServices = HostContainer.GetInstance <ILocalizedResourceServices>(); _settingTypeServices = HostContainer.GetInstance <ISettingTypeServices>(); _siteSettingRepository = new SiteSettingRepository(entities); _settingTypeRepository = new SettingTypeRepository(entities); }
public FileTemplateServices(PXHotelEntities entities) { _localizedResourceServices = HostContainer.GetInstance <ILocalizedResourceServices>(); _pageTemplateServices = HostContainer.GetInstance <IPageTemplateServices>(); _fileTemplateRepository = new FileTemplateRepository(entities); _pageRepository = new PageRepository(entities); }
public RequiredIntegerAttribute() : base(FrameworkConstants.Zero, int.MaxValue) { var localizedResourceService = HostContainer.GetInstance <ILocalizedResourceService>(); ErrorMessage = localizedResourceService.T("System_Message_Required"); }
public ContactCookieModel(User user) : this() { var contactService = HostContainer.GetInstance <IContactService>(); var contact = contactService.FetchFirst(c => c.UserId == user.Id); if (contact != null) { ContactId = contact.Id; Email = contact.Email; FirstName = contact.FirstName; LastName = contact.LastName; Phone = contact.PreferredPhoneNumber ?? contact.PhoneHome ?? contact.PhoneWork ?? contact.MobilePhone; Address = contact.AddressLine1 ?? contact.AddressLine2; AnonymousContactId = WorkContext.CurrentContact.AnonymousContactId; CookieKey = WorkContext.CurrentContact.CookieKey; IpAddress = WorkContext.CurrentContact.IpAddress; } else { Email = user.Email; FirstName = user.FirstName; LastName = user.LastName; Phone = user.Phone; Address = user.Address; AnonymousContactId = WorkContext.CurrentContact.AnonymousContactId; CookieKey = WorkContext.CurrentContact.CookieKey; IpAddress = WorkContext.CurrentContact.IpAddress; } }
public EmailValidationAttribute() : base(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*") { var localizedResourceServies = HostContainer.GetInstance <ILocalizedResourceServices>(); ErrorMessage = localizedResourceServies.T("AdminModule:::Users:::ValidationMessages:::InvalidEmail:::Email is invalid"); }
public NewsServices(PXHotelEntities entities) { _localizedResourceServices = HostContainer.GetInstance <ILocalizedResourceServices>(); _newsCategoryServices = HostContainer.GetInstance <INewsCategoryServices>(); _newsRepository = new NewsRepository(entities); _newsNewsCategoryRepository = new NewsNewsCategoryRepository(entities); }
public UsernameValidationAttribute() : base(@"^[0-9a-zA-Z]{3,}$") { var localizedResourceServies = HostContainer.GetInstance <ILocalizedResourceService>(); ErrorMessage = localizedResourceServies.T("User_Message_InvalidUsernameFormat"); }
public int Main(int argc, string[] argv) { if (argc < 1) { Console.WriteLine("{app} [args]"); return(-1); } int exitCode = 0; #if DESKTOP // CORECLR_TODO: Classic tracing var listener = new ConsoleTraceListener(); Trace.Listeners.Add(listener); Trace.AutoFlush = true; #endif string path = Path.GetFullPath(argv[0]); _container = new HostContainer(); AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; var host = new RootHost(path); using (_container.AddHost(host)) { exitCode = ExecuteMain(path, argv.Skip(1).ToArray()); } AppDomain.CurrentDomain.AssemblyResolve -= OnAssemblyResolve; return(exitCode); }
/// <summary> /// Get current contact info /// </summary> /// <returns></returns> public static ContactCookieModel GetCurrentContact() { var currentContact = StateManager.GetCookie <ContactCookieModel>(EzCMSContants.CurrentContactInformation); /* * This is the first time user come to site and has no cookie. We will * - Create new cookie * - Create an anonymous contact for user */ if (currentContact == null) { //Create new anonymous contact var annonymousContactRepository = HostContainer.GetInstance <IRepository <AnonymousContact> >(); var annonymousContact = new AnonymousContact { CookieKey = PasswordUtilities.GenerateUniqueKey(), IpAddress = HttpContext.Current.GetUserAgentInformationFromRequest().IpAddress }; annonymousContactRepository.Insert(annonymousContact); //Setup contact currentContact = new ContactCookieModel { AnonymousContactId = annonymousContact.Id, CookieKey = annonymousContact.CookieKey, IpAddress = annonymousContact.IpAddress }; //Set current contact to cookie StateManager.SetCookie(EzCMSContants.CurrentContactInformation, currentContact, DateTime.UtcNow.AddYears(1)); } return(currentContact); }
/// <summary> /// Generate virtual file from template /// </summary> /// <param name="virtualPath"></param> /// <param name="template"></param> public MyVirtualFile(string virtualPath, PageTemplate template) : base(virtualPath) { var pageTemplateServices = HostContainer.GetInstance <IPageTemplateServices>(); var pageServices = HostContainer.GetInstance <IPageServices>(); var curlyBracketServices = HostContainer.GetInstance <ICurlyBracketServices>(); var pageId = HttpContext.Current.Request["activePageId"].ToNullableInt(); var page = pageServices.GetById(pageId); var model = page != null ? new PageRenderModel(page) : new PageRenderModel(); var content = pageTemplateServices.RenderPageTemplate(template.Id, model); content = curlyBracketServices.Render(content); //Convert content to Unicode //using (var memoryStream = new MemoryStream()) //{ // using (var writer = new StreamWriter(memoryStream, new UnicodeEncoding())) // { // writer.Write(content); // _data = memoryStream.ToArray(); // } //} _data = Encoding.UTF8.GetBytes(content); var firstBytes = new byte[] { 239, 187, 191 }; int newSize = firstBytes.Length + _data.Length; var ms = new MemoryStream(new byte[newSize], 0, newSize, true, true); ms.Write(firstBytes, 0, firstBytes.Length); ms.Write(_data, 0, _data.Length); _data = ms.GetBuffer(); }
public SubscriptionResolver() { _subscriptionService = HostContainer.GetInstance <ISubscriptionService>(); _widgetTemplateService = HostContainer.GetInstance <IWidgetTemplateService>(); _pageService = HostContainer.GetInstance <IPageService>(); _siteSettingService = HostContainer.GetInstance <ISiteSettingService>(); }
public BuildFormSetupModel() { var formService = HostContainer.GetInstance <IFormService>(); Step = ForNavigationms.FormSetupStep.SetupForm; ComponentTemplates = formService.GetFormTemplates(); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var languageServices = HostContainer.GetInstance <ILanguageServices>(); var language = (string)filterContext.RouteData.Values["language"] ?? string.Empty; var culture = (string)filterContext.RouteData.Values["culture"] ?? string.Empty; if (string.IsNullOrEmpty(language) && string.IsNullOrEmpty(culture)) { if (string.IsNullOrEmpty(WorkContext.WorkContext.CurrentCuture)) { var threadCuture = Thread.CurrentThread.CurrentCulture.Name; var country = languageServices.GetById(threadCuture); if (country != null) { WorkContext.WorkContext.CurrentCuture = threadCuture; } } } else { var currentLanguage = languageServices.GetById(string.Format("{0}-{1}", language, culture)); if (currentLanguage != null) { WorkContext.WorkContext.CurrentCuture = currentLanguage.Id; } else { filterContext.Result = new HttpNotFoundResult(); } } }
public SelectWidgetModel() { var widgetService = HostContainer.GetInstance <IWidgetService>(); Types = EnumUtilities.GetAllItems <WidgetType>(); Widgets = widgetService.GetAllWidgets(); }