//public int test(string videoId) //{ // //Connect to the Umbraco DB // var db = _context.GetDatabaseContext(); // var record = db.SingleOrDefault<VideoItem>("WHERE VideoId=@0", videoId); //} public int CreateNewVideoNode(string videoUrl, string videoTitle, string subCategoryIdsList, int monthNodeId) { try { var memberShipHelper = new MembershipHelper(UmbracoContext.Current); var member = (MyMember)_umbracoHelper.TypedMember(memberShipHelper.GetCurrentMemberId()); var newVideoNode = _content.CreateContent(VideoIdExtractor(videoUrl), monthNodeId, "VideoPage", 0); newVideoNode.SetValue("title", videoTitle); newVideoNode.SetValue("videoUrl", videoUrl); newVideoNode.SetValue("videoId", VideoIdExtractor(videoUrl)); newVideoNode.SetValue("date", DateTime.Now); newVideoNode.SetValue("memberName", member.Name); newVideoNode.SetValue("views", 0); newVideoNode.SetValue("likes", 0); newVideoNode.SetValue("dislikes", 0); newVideoNode.SetValue("shares", 0); _content.SaveAndPublishWithStatus(newVideoNode); return _content.SaveAndPublishWithStatus(newVideoNode).Result.StatusType.ToString() == "Success" ? newVideoNode.Id : 0; //new video node creation in Umbraco } catch (Exception e) { return 0; } }
public void SendNotification(Topic topic, string memberName, string url) { var db = ApplicationContext.Current.DatabaseContext.Database; var sql = new Sql().Select("memberId") .From("forumSubscribers") .Where("forumId = @forumId", new { forumId = topic.ParentId }); var results = db.Query<int>(sql).ToList(); using (ContextHelper.EnsureHttpContext()) { var memberShipHelper = new MembershipHelper(UmbracoContext.Current); { foreach (var memberId in results.Where(memberId => memberId != topic.MemberId)) { try { var member = memberShipHelper.GetById(memberId); if (member.GetPropertyValue<bool>("bugMeNot")) continue; var from = new MailAddress(_details.SelectSingleNode("//from/email").InnerText, _details.SelectSingleNode("//from/name").InnerText); var contentService = ApplicationContext.Current.Services.ContentService; var forum = contentService.GetById(topic.ParentId); var subject = _details.SelectSingleNode("//subject").InnerText; subject = string.Format(subject, forum.Name); var domain = _details.SelectSingleNode("//domain").InnerText; var body = _details.SelectSingleNode("//body").InnerText; body = string.Format(body, forum.Name, "https://" + domain + url, memberName, topic.Title, HttpUtility.HtmlDecode(umbraco.library.StripHtml(topic.Body))); var mailMessage = new MailMessage { Subject = subject, Body = body }; mailMessage.To.Add(member.GetPropertyValue<string>("Email")); mailMessage.From = from; using (var smtpClient = new SmtpClient()) { smtpClient.Send(mailMessage); } } catch (Exception exception) { LogHelper.Error<NewForumTopic>( string.Format("Error sending mail to member id {0}", memberId), exception); } } } } }
public static bool IsAdminPosted(int contentID) { bool res = false; MembershipHelper members = new MembershipHelper(UmbracoContext.Current); IContent content = cs.GetById(contentID); string author = (string)content.GetValue("author"); if (!(author == "anonymous")) res = members.GetByUsername(author).IsDocumentType("Admin"); return res; }
public PureMembershipProvider() { pRequiresUniqueEmail = true; ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings["defaultConnectionString"]; if (ConnectionStringSettings == null || ConnectionStringSettings.ConnectionString.Trim() == "") { throw new ProviderException("Connection string cannot be blank."); } _helper = new MembershipHelper(ConnectionStringSettings.ConnectionString); }
public void Widget_should_be_able_to_move_to_another_column() { var profile = default(UserProfile); UserSetup userVisitModel = default(UserSetup); var facade = default(Facade); var widgetInstance = default(WidgetInstance); var userColumns = default(List <Column>); var secondColumn = default(Column); var noOfWidgetsOnSeconColumn = default(int); "Given a new user and a widget on user's page".Context(() => { profile = MembershipHelper.CreateNewAnonUser(); facade = new Facade(new AppContext(string.Empty, profile.UserName)); userVisitModel = facade.FirstVisitHomeTab(profile.UserName, "Test", true, false); userColumns = facade.GetColumnsInTab(userVisitModel.CurrentTab.ID); var firstColumn = userColumns.First(); var widgetsOnColumn = facade.GetWidgetInstancesInZoneWithWidget(firstColumn.WidgetZone.ID); widgetInstance = widgetsOnColumn.First(); }); "When the widget is moved to another column".Do(() => { secondColumn = userColumns.ElementAt(1); noOfWidgetsOnSeconColumn = facade.GetWidgetInstancesInZoneWithWidget(secondColumn.WidgetZone.ID).Count(); facade.MoveWidgetInstance(widgetInstance.Id, secondColumn.WidgetZone.ID, 1); }); "It should remain there permanently".Assert(() => { var newWidgetsOnSecondColumn = facade.GetWidgetInstancesInZoneWithWidget(secondColumn.WidgetZone.ID); var widgetAfterMove = newWidgetsOnSecondColumn.Where(wi => wi.OrderNo == 1).FirstOrDefault(); Assert.NotNull(widgetAfterMove); Assert.Equal(widgetInstance.Id, widgetAfterMove.Id); }); "It should push down other widgets where it is dropped".Assert(() => { var newWidgetsOnSecondColumn = facade.GetWidgetInstancesInZoneWithWidget(secondColumn.WidgetZone.ID); // There should be 1 widget before it Assert.Equal(1, newWidgetsOnSecondColumn.Where(wi => wi.OrderNo < 1).Count()); // There should be N-1 widgets after it where N = before move number of columns Assert.Equal(noOfWidgetsOnSeconColumn - 1, newWidgetsOnSecondColumn.Where(wi => wi.OrderNo > 1).Count()); }); }
public ActionResult ExternalLoginCallback(string returnUrl) { AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(base.Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); if (!result.IsSuccessful) { return(base.RedirectToAction("ExternalLoginFailure")); } bool flag = false; string userName = OAuthWebSecurity.GetUserName(result.Provider, result.ProviderUserId); if (userName != null) { flag = WebSecurity.IsConfirmed(userName); if (flag) { bool createPersistentCookie = false; if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie)) { return(this.RedirectToLocal(returnUrl)); } if (base.User.Identity.IsAuthenticated) { OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, base.User.Identity.Name); return(this.RedirectToLocal(returnUrl)); } } else { string userConfirmationToken = MembershipHelper.GetUserConfirmationToken(WebSecurity.GetUserId(userName)); if (userConfirmationToken != null) { this.SendRegistrationConfirmMail(ConfirmMailOperation.confirm, userName, userConfirmationToken); } } } ((dynamic)base.ViewBag).NotConfirmedEmail = (userName != null) && !flag; string str3 = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId); AuthenticationClientData oAuthClientData = OAuthWebSecurity.GetOAuthClientData(result.Provider); ((dynamic)base.ViewBag).ProviderDisplayName = oAuthClientData.DisplayName; ((dynamic)base.ViewBag).ReturnUrl = returnUrl; RegisterExternalLoginModel model = new RegisterExternalLoginModel { UserName = (result.UserName.Contains("@") && result.UserName.Contains(".")) ? result.UserName : "", ExternalLoginData = str3 }; return(base.View("ExternalLoginConfirmation", model)); }
List<string> GetRecipients(IPublishedContent item, MembershipHelper mbrHelper) { List<string> recipients = new List<string>(); foreach(var childPost in item.Children().Where(x => x.IsVisible())) { var postAuthorEmail = GetAuthorEmail(childPost, mbrHelper); if (!string.IsNullOrWhiteSpace(postAuthorEmail) && !recipients.Contains(postAuthorEmail)) { LogHelper.Info<ForumNotificationMgr>("Adding: {0}", () => postAuthorEmail); recipients.Add(postAuthorEmail); } } return recipients; }
public CounterSet CreateCounterSet(string name, string group = null, string description = null) { string me = whoami(); if (string.IsNullOrEmpty(group)) { group = MembershipHelper.DefaultGroup(me); } else { MembershipHelper.CheckMembership(group, me); } return(_counterManager.CreateCounterSet(group, name, description)); }
public override void Refresh() { IList <UserMember> lst = MembershipManager.ListBySite(); IList <MembershipHelperUser> lstfinal = new List <MembershipHelperUser>(); foreach (UserMember member in lst) { lstfinal.Add(MembershipHelper.GetUser(member.ID)); } DataSource = lstfinal; DataTextField = "FullName"; DataValueField = "UserId"; DataBind(); Items.Insert(0, new ListItem("--Usuario--", "0")); }
public string GetMemberType() { if (HttpContext.Current.Request.IsAuthenticated) { var membershipHelper = new MembershipHelper(UmbracoContext.Current); var member = membershipHelper.GetCurrentMember(); if (member != null) { return member.DocumentTypeAlias; } } return string.Empty; }
public MSDUmbracoHelper(ILog logger) { _umbracoContext = UmbracoContext.Current; if (_umbracoContext != null && _umbracoContext.PublishedContentRequest != null) { CurrentPage = _umbracoContext.PublishedContentRequest.PublishedContent; _umbracoHelper = new UmbracoHelper(_umbracoContext, CurrentPage); } _umbracoMemberService = _umbracoContext.Application.Services.MemberService; _umbracoExamineManager = ExamineManager.Instance; _umbracoMembershipHelper = new MembershipHelper(_umbracoContext); _logger = logger; }
public static IContent CreateUserContent(string name, int parentID, string documentTypeAlias) { IContent content = cs.CreateContent(name, parentID, documentTypeAlias); string author; MembershipHelper members = new MembershipHelper(UmbracoContext.Current); if (members.IsLoggedIn()) author = members.GetCurrentMember().Name; else author = "anonymous"; content.SetValue("isappealed", false); content.SetValue("author", author); return content; }
protected void grid_binding(object sender, GridNeedDataSourceEventArgs e) { DataTable dt = GetDashboardIKU(); if (User.IsInRole("MIA")) { MembershipHelper.GetCurrentUser(); var rows = dt.AsEnumerable() .Where(x => x.Field <string>("Unit") == Session["User.Dept"].ToString()); dt = !rows.Any() ? null : rows.CopyToDataTable(); } RadGrid1.DataSource = dt; //RadGrid1.DataSource = GetDashboardIKU(); //RadGrid1.DataBind(); }
public List <DisplayTopic> SearchTopic(string keyword, [FromUri] string[] group = null) { string me = whoami(); string[] joinedGroup = MembershipHelper.CheckJoinedGroup(me, group); var topiclist = _topicManager.SearchTopic(keyword, joinedGroup); //var disptopiclist = new List<DisplayTopic>(); //foreach (var t in topiclist) //{ // disptopiclist.Add(new DisplayTopic(t, IsFavouriteTopic(t.Id))); //} return(_topicManager.ToDisplayTopicList(topiclist, me)); }
void TopicService_Created(object sender, TopicEventArgs e) { var ns = new NotificationService(ApplicationContext.Current.DatabaseContext); ns.SubscribeToForumTopic(e.Topic.Id, e.Topic.MemberId); //send notification InstantNotification not = new InstantNotification(); //data for notification: var membershipHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current); var member = membershipHelper.GetById(e.Topic.MemberId); var memberName = string.Empty; if (member != null) memberName = member.Name; not.Invoke(Config.ConfigurationFile, Config.AssemblyDir, "NewTopic", e.Topic, e.Topic.GetUrl(), memberName); }
public void Revisit_should_load_the_pages_and_widgets_exactly_the_same() { var profile = default(UserProfile); UserSetup userVisitModel = null; UserSetup userRevisitModel = null; var facade = default(Facade); "Given an anonymous user who visited first".Context(() => { profile = MembershipHelper.CreateNewAnonUser(); facade = new Facade(new AppContext(string.Empty, profile.UserName)); userVisitModel = facade.FirstVisitHomeTab(profile.UserName, string.Empty, true, false); }); "When the same user visits again".Do(() => { userRevisitModel = facade.RepeatVisitHomeTab(profile.UserName, string.Empty, true, false); }); "It should load the exact same pages, column and widgets as the first visit produced".Assert(() => { userVisitModel.UserTabs.Each(firstVisitTab => { Assert.True(userRevisitModel.UserTabs.Exists(page => page.ID == firstVisitTab.ID)); var revisitTab = userRevisitModel.UserTabs.First(page => page.ID == firstVisitTab.ID); var revisitTabColumns = facade.GetColumnsInTab(revisitTab.ID); facade.GetColumnsInTab(firstVisitTab.ID).Each(firstVisitColumn => { var revisitColumn = revisitTabColumns.First(column => column.ID == firstVisitColumn.ID); var firstVisitWidgets = facade.GetWidgetInstancesInZoneWithWidget(firstVisitColumn.WidgetZone.ID); var revisitWidgets = facade.GetWidgetInstancesInZoneWithWidget(revisitColumn.WidgetZone.ID); firstVisitWidgets.Each(firstVisitWidget => Assert.True(revisitWidgets.Where(revisitWidget => revisitWidget.Id == firstVisitWidget.Id).Count() == 1)); }); }); facade.Dispose(); }); }
public ActionResult Index(string topic, string group = null) { string myid = this.Session["userid"].ToString(); UserProfile me = _accManager.FindUser(myid); ViewBag.Myid = me.Userid; ViewBag.Me = me; ViewBag.FeedCategory = "topicline"; Topic t = null; if (string.IsNullOrEmpty(group)) { t = _topicManager.FindTopicByName(topic, MembershipHelper.JoinedGroup(myid)); } else { t = _topicManager.FindTopicByName(topic, group); } if (t == null) { ViewBag.TopicId = -1; ViewBag.Topic = ""; ViewBag.FeedId = ""; ViewBag.IsLiked = false; ViewBag.Group = ""; ViewBag.GroupName = ""; ViewBag.PerfChartName = ""; } else { var g = _groupManag.GetGroupByID(t.GroupID); ViewBag.TopicId = t.Id; ViewBag.Topic = t.Name; ViewBag.FeedId = t.Name; ViewBag.IsLiked = _topicManager.IsFavouriteTopic(me.Userid, t.Id) ? 1 : 0; ViewBag.Group = group; ViewBag.GroupName = g.DisplayName; ViewBag.PerfChartName = group + "_" + t.Name; //ViewBag.PerfChartName = "perf_chart_test"; } return(View()); }
string GetAuthorEmail(IPublishedContent post, MembershipHelper mbrHelper) { if (post == null) return string.Empty; var authorId = post.GetPropertyValue<int>("postAuthor", 0); if ( authorId > 0) { var author = mbrHelper.GetById(authorId); if ( author != null) { // pre 7.2.2 - you can't do get propertyvalue to get // system values like Email return author.AsDynamic().Email; } } return string.Empty; }
void SimpilyForumsController_OnPostSaved(IContent sender, SimpilyForumsEventArgs e) { // we get passed IContent - but as we are going to go get loads of // other content, we will be quicker using IPublishedContent var umbHelper = new UmbracoHelper(UmbracoContext.Current); var mbrHelper = new MembershipHelper(UmbracoContext.Current); var post = umbHelper.TypedContent(sender.Id); if (post == null) return; // for us - the current user will have been the author var author = mbrHelper.GetCurrentMember(); // work out the root of this post (top of the thread) var postRoot = post; if (post.Parent.DocumentTypeAlias == "Simpilypost") { // if we have a parent post, then this is a reply postRoot = post.Parent; } LogHelper.Info<ForumNotificationMgr>("Sending Notification for new post for {0}", () => postRoot.Name); List<string> receipients = GetRecipients(postRoot, mbrHelper); // remove the author from the list. var postAuthor = GetAuthorEmail(post, mbrHelper); if (receipients.Contains(postAuthor)) receipients.Remove(postAuthor); if (receipients.Any()) { SendNotificationEmail(postRoot, post, author, receipients, e.NewPost); } }
/// <summary> /// Initializes a new instance of the <see cref="CustomerContext"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> /// <param name="memberService"> /// The member Service. /// </param> /// <param name="umbracoContext"> /// The umbraco context. /// </param> internal CustomerContext(IMerchelloContext merchelloContext, IMemberService memberService, UmbracoContext umbracoContext) { Mandate.ParameterNotNull(merchelloContext, "merchelloContext"); Mandate.ParameterNotNull(umbracoContext, "umbracoContext"); Mandate.ParameterNotNull(memberService, "memberService"); _merchelloContext = merchelloContext; _umbracoContext = umbracoContext; _customerService = merchelloContext.Services.CustomerService; _memberService = memberService; _cache = merchelloContext.Cache; _membershipHelper = new MembershipHelper(_umbracoContext); Initialize(); }
public override void Initialize(string name, NameValueCollection config) { if (config == null) throw new ArgumentNullException("config"); // Initialize the abstract base class. base.Initialize(name, config); pConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if (pConnectionStringSettings == null || pConnectionStringSettings.ConnectionString.Trim() == "") { throw new ProviderException("Connection string cannot be blank."); } connectionString = pConnectionStringSettings.ConnectionString; _helper = new MembershipHelper(connectionString); }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param> /// <param name="value">The <see cref="T:System.Object" /> to convert.</param> /// <returns> /// An <see cref="T:System.Object" /> that represents the converted value. /// </returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (context == null || context.PropertyDescriptor == null) { return Enumerable.Empty<object>(); } var propertyType = context.PropertyDescriptor.PropertyType; var isGenericType = propertyType.IsGenericType; var targetType = isGenericType ? propertyType.GenericTypeArguments.First() : propertyType; if (value.IsNullOrEmptyString()) { return EnumerableInvocations.Empty(targetType); } // Single IPublishedContent IPublishedContent content = value as IPublishedContent; if (content != null) { return content.As(targetType, culture); } // ReSharper disable once PossibleNullReferenceException var type = value.GetType(); // Multiple IPublishedContent if (type.IsEnumerableOfType(typeof(IPublishedContent))) { return ((IEnumerable<IPublishedContent>)value).As(targetType, culture); } int[] nodeIds = { }; // First try enumerable strings, ints. if (type.IsGenericType || type.IsArray) { if (type.IsEnumerableOfType(typeof(string))) { int n; nodeIds = ((IEnumerable<string>)value) .Select(x => int.TryParse(x, NumberStyles.Any, culture, out n) ? n : -1) .ToArray(); } if (type.IsEnumerableOfType(typeof(int))) { nodeIds = ((IEnumerable<int>)value).ToArray(); } } // Now csv strings. if (!nodeIds.Any()) { var s = value as string ?? value.ToString(); if (!string.IsNullOrWhiteSpace(s)) { int n; nodeIds = XmlHelper.CouldItBeXml(s) ? s.GetXmlIds() : s .ToDelimitedList() .Select(x => int.TryParse(x, NumberStyles.Any, culture, out n) ? n : -1) .Where(x => x > 0) .ToArray(); } } if (nodeIds.Any()) { var umbracoContext = UmbracoContext.Current; var membershipHelper = new MembershipHelper(umbracoContext); var objectType = UmbracoObjectTypes.Unknown; var multiPicker = new List<IPublishedContent>(); // Oh so ugly if you let Resharper do this. // ReSharper disable once LoopCanBeConvertedToQuery foreach (var nodeId in nodeIds) { var item = this.GetPublishedContent(nodeId, ref objectType, UmbracoObjectTypes.Document, umbracoContext.ContentCache.GetById) ?? this.GetPublishedContent(nodeId, ref objectType, UmbracoObjectTypes.Media, umbracoContext.MediaCache.GetById) ?? this.GetPublishedContent(nodeId, ref objectType, UmbracoObjectTypes.Member, membershipHelper.GetById); if (item != null) { multiPicker.Add(item); } } return multiPicker.As(targetType, culture); } return base.ConvertFrom(context, culture, value); }
// // System.Configuration.Provider.ProviderBase.Initialize Method // public override void Initialize(string name, NameValueCollection config) { // // Initialize values from web.config. // if (config == null) throw new ArgumentNullException("config"); if (name.Length == 0) name = "OdbcMembershipProvider"; // Initialize the abstract base class. base.Initialize(name, config); pMaxInvalidPasswordAttempts = Convert.ToInt32(GetConfigValue(config["maxInvalidPasswordAttempts"], "5")); pPasswordAttemptWindow = Convert.ToInt32(GetConfigValue(config["passwordAttemptWindow"], "10")); pMinRequiredNonAlphanumericCharacters = Convert.ToInt32(GetConfigValue(config["minRequiredNonAlphanumericCharacters"], "1")); pMinRequiredPasswordLength = Convert.ToInt32(GetConfigValue(config["minRequiredPasswordLength"], "7")); pPasswordStrengthRegularExpression = Convert.ToString(GetConfigValue(config["passwordStrengthRegularExpression"], "")); pEnablePasswordReset = Convert.ToBoolean(GetConfigValue(config["enablePasswordReset"], "true")); pRequiresUniqueEmail = Convert.ToBoolean(GetConfigValue(config["requiresUniqueEmail"], "true")); SecretHashKey = Encoding.Unicode.GetBytes(ConfigurationManager.AppSettings["SecretHashKey"]); string temp_format = config["passwordFormat"] ?? "Hashed"; if (temp_format != "Hashed") throw new ProviderException("Password format not supported. Only hash with special salt is supported! Choose 'Hashed'."); // // Initialize OdbcConnection. // ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]]; if (ConnectionStringSettings == null || ConnectionStringSettings.ConnectionString.Trim() == "") { throw new ProviderException("Connection string cannot be blank."); } _helper = new MembershipHelper(ConnectionStringSettings.ConnectionString); }