protected override DriverResult Editor(FacebookAccountPart part, IUpdateModel updater, dynamic shapeHelper) { FacebookAccountVM vm = new FacebookAccountVM(); updater.TryUpdateModel(vm, Prefix, null, null); Mapper.Initialize(cfg => { cfg.CreateMap <FacebookAccountVM, FacebookAccountPart>(); }); Mapper.Map(vm, part); return(Editor(part, shapeHelper)); }
protected override DriverResult Editor(FacebookAccountPart part, IUpdateModel updater, dynamic shapeHelper) { FacebookAccountVM vm = new FacebookAccountVM(); updater.TryUpdateModel(vm, Prefix, null, null); var mapperConfiguration = new MapperConfiguration(cfg => { cfg.CreateMap <FacebookAccountVM, FacebookAccountPart>(); }); IMapper _mapper = mapperConfiguration.CreateMapper(); _mapper.Map(vm, part); return(Editor(part, shapeHelper)); }
protected override DriverResult Editor(FacebookAccountPart part, dynamic shapeHelper) { FacebookAccountVM vm = new FacebookAccountVM(); Mapper.Initialize(cfg => { cfg.CreateMap <FacebookAccountPart, FacebookAccountVM>(); }); Mapper.Map(part, vm); return(ContentShape("Parts_FacebookAccount", () => shapeHelper.EditorTemplate(TemplateName: "Parts/FacebookAccount", Model: vm, Prefix: Prefix))); }
protected override DriverResult Editor(FacebookAccountPart part, dynamic shapeHelper) { FacebookAccountVM vm = new FacebookAccountVM(); var mapperConfiguration = new MapperConfiguration(cfg => { cfg.CreateMap <FacebookAccountPart, FacebookAccountVM>(); }); IMapper _mapper = mapperConfiguration.CreateMapper(); _mapper.Map(part, vm); return(ContentShape("Parts_FacebookAccount", () => shapeHelper.EditorTemplate(TemplateName: "Parts/FacebookAccount", Model: vm, Prefix: Prefix))); }
private void OrchardRegister(FacebookAccountVM fvm) { string displayas = ""; string AccountType = ""; if (string.IsNullOrEmpty(fvm.PageName)) { string json = new WebClient().DownloadString("https://graph.facebook.com/me?access_token=" + fvm.UserToken); displayas = (JObject.Parse(json))["name"].ToString(); AccountType = "User"; } else { displayas = fvm.PageName; AccountType = "Page"; } IContentQuery <ContentItem> contentQuery = _orchardServices.ContentManager.Query().ForType(contentType); Int32 currentiduser = _orchardServices.WorkContext.CurrentUser.Id; fvm.IdPage = fvm.IdPage ?? ""; Int32 elementi = contentQuery.List().Where(x => x.As <FacebookAccountPart>().IdUser == currentiduser && (x.As <FacebookAccountPart>().DisplayAs == displayas)).Count(); if (elementi > 0) { if (string.IsNullOrEmpty(fvm.IdPage)) { _notifier.Add(NotifyType.Warning, T("User Facebook Account can't be added, is duplicated")); } else { _notifier.Add(NotifyType.Warning, T("Facebook Page {0} can't be added, is duplicated", fvm.PageName)); } } else { var newContent = _orchardServices.ContentManager.New(contentType); _orchardServices.ContentManager.Create(newContent); newContent.As <FacebookAccountPart>().IdUser = currentiduser; newContent.As <FacebookAccountPart>().AccountType = AccountType; newContent.As <FacebookAccountPart>().DisplayAs = displayas; newContent.As <FacebookAccountPart>().SocialName = "Facebook"; newContent.As <FacebookAccountPart>().UserToken = fvm.UserToken; newContent.As <FacebookAccountPart>().Valid = false; newContent.As <FacebookAccountPart>().PageName = fvm.PageName; newContent.As <FacebookAccountPart>().PageToken = fvm.PageToken; newContent.As <FacebookAccountPart>().IdPage = fvm.IdPage ?? ""; newContent.As <FacebookAccountPart>().Shared = false; newContent.As <FacebookAccountPart>().UserIdFacebook = fvm.UserIdFacebook ?? ""; newContent.As <FacebookAccountPart>().UserName = fvm.UserName ?? ""; if (string.IsNullOrEmpty(fvm.IdPage)) { _notifier.Add(NotifyType.Warning, T("User Facebook Account added")); } else { _notifier.Add(NotifyType.Warning, T("Facebook Page {0} added", fvm.PageName)); } } }
public ActionResult GetPostTokenFacebook() { var pcr = _providerConfigurationService.Get("Facebook"); if (pcr == null) { _notifier.Add(NotifyType.Error, T("No facebook account setting added, add one in Settings -> Open Authentication")); return(RedirectToAction("Index", "FacebookAccount", new { area = "Laser.Orchard.Facebook", id = -10 })); } string app_id = pcr.ProviderIdKey; string app_secret = pcr.ProviderSecret; string scope = "publish_actions,manage_pages,publish_pages,user_photos";//user_status status_updated nelle extended permission if (Request["code"] == null) { string url = string.Format( "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}", app_id, Request.Url.AbsoluteUri, scope); Response.Redirect(url, false); } else { Dictionary <string, string> tokens = new Dictionary <string, string>(); string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}", app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret); HttpWebRequest request = System.Net.WebRequest.Create(url) as HttpWebRequest; string access_token = ""; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); string vals = reader.ReadToEnd(); var json = JObject.Parse(vals); if ((json["access_token"]).Type != JTokenType.Null) { access_token = (json["access_token"] ?? "").ToString(); } } var client = new FacebookClient(access_token); // FacebookPostSettingPart getpart = _orchardServices.WorkContext.CurrentSite.As<FacebookPostSettingPart>(); // getpart.FacebookAccessToken = access_token; object taskresult = client.Get("/me"); var result = (IDictionary <string, object>)taskresult; string facebookUserId = (string)result["id"]; string facebookUserName = (string)result["name"]; FacebookAccountVM fvm = new FacebookAccountVM(); fvm.UserToken = access_token; fvm.UserIdFacebook = facebookUserId; fvm.UserName = facebookUserName; OrchardRegister(fvm); JsonObject jsonResponse = client.Get("me/accounts") as JsonObject; Uri profilePictureUrl = new Uri(string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", facebookUserId, "small", access_token)); var mediaPath = HostingEnvironment.IsHosted ? HostingEnvironment.MapPath("~/Media/") ?? "" : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media"); WebClient webClient = new WebClient(); webClient.DownloadFile(profilePictureUrl, mediaPath + _shellSettings.Name + @"\facebook_" + facebookUserId + ".jpg"); Dictionary <string, string> ElencoPagine = new Dictionary <string, string>(); foreach (var account in (JsonArray)jsonResponse["data"]) { string accountName = (string)(((JsonObject)account)["name"]); fvm = new FacebookAccountVM(); fvm.UserToken = access_token; fvm.PageName = accountName; fvm.PageToken = (string)(((JsonObject)account)["access_token"]); fvm.IdPage = (string)(((JsonObject)account)["id"]); profilePictureUrl = new Uri(string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", fvm.IdPage, "small", access_token)); webClient = new WebClient(); webClient.DownloadFile(profilePictureUrl, mediaPath + _shellSettings.Name + @"\facebook_" + fvm.IdPage + ".jpg"); fvm.UserIdFacebook = fvm.IdPage; fvm.UserName = accountName; OrchardRegister(fvm); } return(RedirectToAction("Index", "FacebookAccount", new { area = "Laser.Orchard.Facebook", id = -10 })); } return(null); }