public static string PublishUserAction(UserAction userAction, System.Guid userId) { var action = JsonConvert.SerializeObject(userAction); Dictionary<string, object> collection = new Dictionary<string, object>(); collection.Add("userAction", action); collection.Add("scope", "both"); collection.Add("enabledProviders", GlobalConfig.SocialProvidersList); collection.Add("privacy", "public"); collection.Add("shortURLs", "whenRequired"); collection.Add("uid", userId.ToString()); collection.Add("feedID", "UserAction"); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.publishUserAction", GigyaHelpers.buildParameter(collection)); return res.GetData().ToJsonString(); }
public JsonResult _RegisterAndSubscribe(FormCollection fc) { var ReturnCode = new TransactionReturnType() { StatusCode = (int)ErrorCodes.UnknownError, StatusMessage = String.Empty, info = "Registration", TransactionType = "Registration" }; if (!Request.IsAjaxRequest()) { ReturnCode.StatusMessage = "Invalid request"; return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); } bool isSourceAir = false; string url = Url.Action("Register", "User").ToString(); var field_names = new string[] { "uid", "provider", "full_name", "pid", "cmd", "a1", "p1", "t1", "a3", "t3", "p3", "src", "item_name", "amount", "currency", "custom", "ip" }; try { if (TempData["qs"] != null) { var qs = (NameValueCollection)TempData["qs"]; ViewBag.qs = qs; TempData["qs"] = qs; } DateTime registDt = DateTime.Now; Dictionary<string, string> tmpCollection = fc.AllKeys.ToDictionary(k => k, v => fc[v]); bool isMissingRequiredFields = false; foreach (var x in tmpCollection) { if (!field_names.Contains(x.Key)) if (String.IsNullOrEmpty(x.Value)) { isMissingRequiredFields = true; break; } } if (!isMissingRequiredFields) // process form { var ip = Request.GetUserHostAddressFromCloudflare(); if (!String.IsNullOrEmpty(tmpCollection["ip"])) ip = tmpCollection["ip"]; var location = MyUtility.GetLocationBasedOnIpAddress(ip); string FirstName = tmpCollection["first_name"]; string LastName = tmpCollection["last_name"]; string EMail = tmpCollection["p_login_email"]; string ConfirmEmail = tmpCollection["p_login_email_c"]; string Password = tmpCollection["login_pass"]; //autodetect country, city, state string CountryCode = location.countryCode; string City = location.city; string State = location.region; string provider = String.IsNullOrEmpty(tmpCollection["provider"]) ? String.Empty : tmpCollection["provider"]; string uid = String.IsNullOrEmpty(tmpCollection["uid"]) ? String.Empty : tmpCollection["uid"]; System.Guid userId = System.Guid.NewGuid(); string browser = Request.UserAgent; if (FirstName.Length > 32) ReturnCode.StatusMessage = "First Name cannot exceed 32 characters."; if (LastName.Length > 32) ReturnCode.StatusMessage = "Last Name cannot exceed 32 characters."; if (EMail.Length > 64) ReturnCode.StatusMessage = "Email address cannot exceed 64 characters."; if (State.Length > 30) ReturnCode.StatusMessage = "State cannot exceed 30 characters."; if (City.Length > 50) ReturnCode.StatusMessage = "City cannot exceed 50 characters."; if (String.Compare(EMail, ConfirmEmail, true) != 0) ReturnCode.StatusMessage = "Email addresses do not match"; RegexUtilities util = new RegexUtilities(); //if (!MyUtility.isEmail(EMail)) if (!util.IsValidEmail(EMail)) ReturnCode.StatusMessage = "Email address is invalid."; var context = new IPTV2Entities(); User user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EMail, true) == 0); if (user != null) ReturnCode.StatusMessage = "Email address is already taken."; if (GlobalConfig.ExcludedCountriesFromRegistrationDropDown.Split(',').Contains(CountryCode)) // check if country is part of the exclusion list first ReturnCode.StatusMessage = "Country does not exist."; else if (context.Countries.Count(c => String.Compare(c.Code, CountryCode, true) == 0) <= 0) // then check if country is part of the list ReturnCode.StatusMessage = "Country does not exist."; if (context.States.Count(s => String.Compare(s.CountryCode, CountryCode, true) == 0) > 0) if (context.States.Count(s => String.Compare(s.CountryCode, CountryCode, true) == 0 && (String.Compare(s.StateCode, State, true) == 0 || String.Compare(s.Name, State, true) == 0)) <= 0) ReturnCode.StatusMessage = "State is invalid for this country."; if (!String.IsNullOrEmpty(ReturnCode.StatusMessage)) return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); user = new User() { UserId = userId, FirstName = FirstName, LastName = LastName, City = City, State = State, CountryCode = CountryCode, EMail = EMail, Password = MyUtility.GetSHA1(Password), GigyaUID = userId.ToString(), RegistrationDate = registDt, LastUpdated = registDt, RegistrationIp = ip, StatusId = GlobalConfig.Visible, ActivationKey = Guid.NewGuid(), DateVerified = registDt }; try { if (Request.Cookies.AllKeys.Contains("tuid")) user.RegistrationCookie = Request.Cookies["tuid"].Value; else if (Request.Cookies.AllKeys.Contains("regcook")) user.RegistrationCookie = Request.Cookies["regcook"].Value; } catch (Exception) { } ////check for cookie try { var dt = DateTime.Parse(Request.Cookies["rcDate"].Value); if (registDt.Subtract(dt).Days < 45) { ReturnCode.StatusMessage = "We have detected that you have already registered using this machine."; return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); } } catch (Exception) { } string CurrencyCode = GlobalConfig.DefaultCurrency; var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0); if (country != null) CurrencyCode = country.CurrencyCode; var wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0); if (wallet == null) // Wallet does not exist. Create new wallet for User. { wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt); user.UserWallets.Add(wallet); } var transaction = new RegistrationTransaction() { RegisteredState = user.State, RegisteredCity = user.City, RegisteredCountryCode = user.CountryCode, Amount = 0, Currency = CurrencyCode, Reference = isSourceAir ? "New Registration (air)" : "New Registration", Date = registDt, OfferingId = GlobalConfig.offeringId, UserId = user.UserId, StatusId = GlobalConfig.Visible }; user.Transactions.Add(transaction); context.Users.Add(user); if (context.SaveChanges() > 0) { string verification_email = String.Format("{0}/User/Verify?key={1}", GlobalConfig.baseUrl, user.ActivationKey.ToString()); if (isSourceAir) { try { verification_email = String.Format("{0}&source=air", verification_email); var template = MyUtility.GetUrlContent(GlobalConfig.ProjectAirEmailVerificationBodyTemplateUrl); var htmlBody = String.Format(template, FirstName, EMail, verification_email); if (!Request.IsLocal) try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", htmlBody, MailType.HtmlOnly, String.Empty); } catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); } } catch (Exception) { string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email); if (!Request.IsLocal) try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); } catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); } } } else { string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email); if (!Request.IsLocal) try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); } catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); } } GSResponse res = null; if (!String.IsNullOrEmpty(uid) && !String.IsNullOrEmpty(provider)) { Dictionary<string, object> collection = new Dictionary<string, object>(); collection.Add("siteUID", user.UserId); collection.Add("uid", Uri.UnescapeDataString(uid)); collection.Add("cid", String.Format("{0} - New User", provider)); res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", GigyaHelpers.buildParameter(collection)); if (res.GetErrorCode() == 0) //Successful link { if (user != null) { var UserId = user.UserId.ToString(); user.StatusId = GlobalConfig.Visible; //activate account user.DateVerified = DateTime.Now; SetAutheticationCookie(UserId); SetSession(UserId); if (!ContextHelper.SaveSessionInDatabase(context, user)) context.SaveChanges(); } } } else { var info = new GigyaUserInfo() { firstName = FirstName, lastName = LastName, email = EMail }; var registrationInfo = new GigyaNotifyLoginInfo() { siteUID = user.UserId.ToString(), cid = "TFCTV - Registration", sessionExpiration = 0, newUser = true, userInfo = Newtonsoft.Json.JsonConvert.SerializeObject(info) }; GSObject obj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(registrationInfo)); res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", obj); } if (user != null) { if (user.StatusId == GlobalConfig.Visible) { int freeTrialProductId = 0; if (GlobalConfig.IsFreeTrialEnabled) { freeTrialProductId = MyUtility.GetCorrespondingFreeTrialProductId(); if (GlobalConfig.TfcTvFree2StartDate < registDt && GlobalConfig.TfcTvFree2EndDate > registDt) { string UserCountryCode = user.CountryCode; if (!GlobalConfig.isUAT) try { UserCountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy(); } catch (Exception) { } var countryList = GlobalConfig.TfcTvFree2CountryWhiteList.Split(','); if (countryList.Contains(UserCountryCode) && String.Compare(user.CountryCode, UserCountryCode, true) == 0) freeTrialProductId = GlobalConfig.TfcTvFree2ProductId; } PaymentHelper.PayViaWallet(context, userId, freeTrialProductId, SubscriptionProductType.Package, userId, null); } //authenticate user SetAutheticationCookie(user.UserId.ToString()); SendToGigya(user); SetSession(user.UserId.ToString()); ContextHelper.SaveSessionInDatabase(context, user); //add uid cookie HttpCookie uidCookie = new HttpCookie("uid"); uidCookie.Value = user.UserId.ToString(); uidCookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(uidCookie); } } GigyaHelpers.setCookie(res, this.ControllerContext); GigyaUserData2 userData = new GigyaUserData2() { city = user.City, country = user.CountryCode, email = user.EMail, firstName = user.FirstName, lastName = user.LastName, state = user.State }; //GigyaUserDataInfo userDataInfo = new GigyaUserDataInfo() //{ // UID = user.UserId.ToString(), // data = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Formatting.None) //}; TFCTV.Helpers.UserData privacyData = new UserData() { IsExternalSharingEnabled = "true,false", IsInternalSharingEnabled = "true,false", IsProfilePrivate = "false" }; GigyaUserDataInfo2 userDataInfo = new GigyaUserDataInfo2() { UID = user.UserId.ToString(), profile = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Formatting.None), data = Newtonsoft.Json.JsonConvert.SerializeObject(privacyData, Formatting.None) }; GSObject userDataInfoObj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)); //res = GigyaHelpers.createAndSendRequest("gcs.setUserData", userDataInfoObj); res = GigyaHelpers.createAndSendRequest("ids.setAccountInfo", userDataInfoObj); var returnCode = res.GetErrorCode(); //Publish to Activity Feed List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_actionlink_href) }); //mediaItem List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.register_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.register_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_mediaitem_href) }); UserAction action = new UserAction() { actorUID = userId.ToString(), userMessage = SNSTemplates.register_usermessage, title = SNSTemplates.register_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_linkback), description = String.Format(SNSTemplates.register_description, FirstName), actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, userId, "external"); action.userMessage = String.Empty; action.title = String.Empty; action.mediaItems = null; GigyaMethods.PublishUserAction(action, userId, "internal"); TempData["qs"] = null; // empty the TempData upon successful registration ReturnCode.StatusCode = (int)ErrorCodes.Success; ReturnCode.info7 = user.EMail; if (user.StatusId == GlobalConfig.Visible) { ReturnCode.StatusHeader = "Your 7-Day Free Trial Starts Now!"; ReturnCode.StatusMessage = "Congratulations! You are now registered to TFC.tv."; ReturnCode.StatusMessage2 = "Pwede ka nang manood ng mga piling Kapamilya shows at movies!"; ReturnCode.info3 = user.UserId.ToString(); //Change to social registration ReturnCode.info = "SocialRegistration"; ReturnCode.TransactionType = "SocialRegistration"; } else { ReturnCode.StatusHeader = "Email verification sent!"; ReturnCode.StatusMessage = "Congratulations! You are one step away from completing your registration."; ReturnCode.StatusMessage2 = "An email has been sent to you.<br> Verify your email address to complete your registration."; } TempData["ErrorMessage"] = ReturnCode; //if(xoom) if (Request.Cookies.AllKeys.Contains("xoom")) { var userPromo = new UserPromo(); userPromo.UserId = user.UserId; userPromo.PromoId = GlobalConfig.Xoom2PromoId; userPromo.AuditTrail.CreatedOn = registDt; context.UserPromos.Add(userPromo); context.SaveChanges(); } return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); // successful registration } } else ReturnCode.StatusMessage = "Please fill in all required fields."; url = String.Format("{0}?{1}", Request.UrlReferrer.AbsolutePath, MyUtility.DictionaryToQueryString(tmpCollection)); } catch (Exception e) { MyUtility.LogException(e); } return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); }
public ActionResult _Registration(FormCollection fc) { //fc["Email"] = "*****@*****.**"; //fc["Password"] = "******"; //fc["ConfirmPassword"] = "******"; //fc["FirstName"] = "Albin"; //fc["LastName"] = "Lim"; //fc["CountryCode"] = "US"; //fc["City"] = "CA"; //fc["State"] = "CA"; Dictionary<string, object> collection = new Dictionary<string, object>(); ErrorCodes errorCode = ErrorCodes.UnknownError; string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError); collection = MyUtility.setError(errorCode, errorMessage); if (!Request.IsAjaxRequest()) { collection = MyUtility.setError(ErrorCodes.UnknownError, "Your request is invalid."); return Content(MyUtility.buildJson(collection), "application/json"); } bool isConnectedToSocialNetworks = false; string href = "/User/RegisterVerify"; if (MyUtility.isUserLoggedIn()) //User is logged in. return RedirectToAction("Index", "Home"); if (String.IsNullOrEmpty(fc["Email"])) { collection = MyUtility.setError(ErrorCodes.IsEmailEmpty); return Content(MyUtility.buildJson(collection), "application/json"); } if (String.Compare(fc["Password"], fc["ConfirmPassword"], false) != 0) { collection = MyUtility.setError(ErrorCodes.IsMismatchPassword); return Content(MyUtility.buildJson(collection), "application/json"); } if (String.IsNullOrEmpty(fc["FirstName"]) || String.IsNullOrEmpty(fc["LastName"]) || String.IsNullOrEmpty(fc["CountryCode"])) { collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields); return Content(MyUtility.buildJson(collection), "application/json"); } RegexUtilities util = new RegexUtilities(); //if (!MyUtility.isEmail(fc["Email"])) if (!util.IsValidEmail(fc["Email"])) { collection = MyUtility.setError(ErrorCodes.IsNotValidEmail); return Content(MyUtility.buildJson(collection), "application/json"); } try { string FirstName = fc["FirstName"]; string LastName = fc["LastName"]; string CountryCode = fc["CountryCode"]; string EMail = fc["Email"]; string Password = fc["Password"]; string City = fc["City"]; string State = String.IsNullOrEmpty(fc["State"]) ? fc["StateDD"] : fc["State"]; System.Guid userId = System.Guid.NewGuid(); string provider = "tfctv"; if (FirstName.Length > 32) { collection = MyUtility.setError(ErrorCodes.LimitReached, "First Name cannot exceed 32 characters."); return Content(MyUtility.buildJson(collection), "application/json"); } if (LastName.Length > 32) { collection = MyUtility.setError(ErrorCodes.LimitReached, "Last Name cannot exceed 32 characters."); return Content(MyUtility.buildJson(collection), "application/json"); } if (EMail.Length > 64) { collection = MyUtility.setError(ErrorCodes.LimitReached, "Email cannot exceed 64 characters."); return Content(MyUtility.buildJson(collection), "application/json"); } if (!String.IsNullOrEmpty(State)) if (State.Length > 30) { collection = MyUtility.setError(ErrorCodes.LimitReached, "State cannot exceed 30 characters."); return Content(MyUtility.buildJson(collection), "application/json"); } if (!String.IsNullOrEmpty(City)) if (City.Length > 50) { collection = MyUtility.setError(ErrorCodes.LimitReached, "City cannot exceed 50 characters."); return Content(MyUtility.buildJson(collection), "application/json"); } var context = new IPTV2Entities(); User user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EMail, true) == 0); if (user != null) { collection = MyUtility.setError(ErrorCodes.IsExistingEmail); return Content(MyUtility.buildJson(collection), "application/json"); } /***** CHECK FOR COUNTRY CODE ****/ if (context.Countries.Count(c => String.Compare(c.Code, CountryCode, true) == 0) <= 0) { collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields, "Country Code is invalid."); return Content(MyUtility.buildJson(collection), "application/json"); } else if (GlobalConfig.ExcludedCountriesFromRegistrationDropDown.Split(',').Contains(CountryCode)) { collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields, "Country Code is invalid."); return Content(MyUtility.buildJson(collection), "application/json"); } if (String.IsNullOrEmpty(State)) { collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields, "State is required."); return Content(MyUtility.buildJson(collection), "application/json"); } else { if (context.States.Count(c => c.CountryCode == CountryCode.ToUpper()) > 0) { if (context.States.Count(s => s.CountryCode == CountryCode.ToUpper() && (s.StateCode == State || s.Name == State)) == 0) { collection = MyUtility.setError(ErrorCodes.IsMissingRequiredFields, "State is invalid."); return Content(MyUtility.buildJson(collection), "application/json"); } } } DateTime registDt = DateTime.Now; user = new User() { UserId = userId, FirstName = FirstName, LastName = LastName, City = City, State = State, CountryCode = CountryCode, EMail = EMail, Password = MyUtility.GetSHA1(Password), GigyaUID = userId.ToString(), RegistrationDate = registDt, LastUpdated = registDt, RegistrationIp = Request.GetUserHostAddressFromCloudflare(), StatusId = 0, ActivationKey = Guid.NewGuid() }; //UPDATE: FEB 18, 2013 if (MyUtility.isTVECookieValid()) user.IsTVERegistrant = true; string CurrencyCode = GlobalConfig.DefaultCurrency; Country country = context.Countries.FirstOrDefault(c => c.Code == CountryCode); if (country != null) { Currency currency = context.Currencies.FirstOrDefault(c => c.Code == country.CurrencyCode); if (currency != null) CurrencyCode = currency.Code; } UserWallet wallet = user.UserWallets.FirstOrDefault(w => w.Currency == CurrencyCode); if (wallet == null) // Wallet does not exist. Create new wallet for User. { wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt); user.UserWallets.Add(wallet); } var transaction = new RegistrationTransaction() { RegisteredState = user.State, RegisteredCity = user.City, RegisteredCountryCode = user.CountryCode, Amount = 0, Currency = CurrencyCode, Reference = "New Registration", Date = registDt, OfferingId = GlobalConfig.offeringId, UserId = user.UserId, StatusId = GlobalConfig.Visible }; user.Transactions.Add(transaction); context.Users.Add(user); if (context.SaveChanges() > 0) { if (TempData["qs"] != null) { NameValueCollection qs = (NameValueCollection)TempData["qs"]; Dictionary<string, object> GigyaCollection = new Dictionary<string, object>(); collection.Add("uid", qs["UID"]); collection.Add("siteUID", userId); collection.Add("cid", String.Format("{0} - New User", qs["provider"])); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", GigyaHelpers.buildParameter(collection)); provider = qs["provider"]; isConnectedToSocialNetworks = true; } else { Dictionary<string, object> userInfo = new Dictionary<string, object>(); userInfo.Add("firstName", user.FirstName); userInfo.Add("lastName", user.LastName); userInfo.Add("email", user.EMail); Dictionary<string, object> gigyaCollection = new Dictionary<string, object>(); gigyaCollection.Add("siteUID", user.UserId); gigyaCollection.Add("cid", "TFCTV - Registration"); gigyaCollection.Add("sessionExpiration", "0"); gigyaCollection.Add("newUser", true); gigyaCollection.Add("userInfo", MyUtility.buildJson(userInfo)); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", GigyaHelpers.buildParameter(gigyaCollection)); GigyaHelpers.setCookie(res, this.ControllerContext); } //setUserData User usr = context.Users.FirstOrDefault(u => u.EMail == EMail); setUserData(usr.UserId.ToString(), usr); var ActivationKey = usr.ActivationKey; bool isTFCnowCustomer = false; if (TempData["TFCnowCustomer"] != null) { Customer customer = (Customer)TempData["TFCnowCustomer"]; usr.StatusId = 1; usr.DateVerified = registDt; TempData["TFCnowCustomer"] = customer; href = "/Migration/Migrate"; if (context.SaveChanges() > 0) { //SetAutheticationCookie(userId.ToString()); isTFCnowCustomer = true; } } if (isConnectedToSocialNetworks) { usr.StatusId = 1; usr.DateVerified = registDt; context.SaveChanges(); } //If FreeTrial is enabled, insert free trial. //if (GlobalConfig.IsFreeTrialEnabled) //{ // context = new IPTV2Entities(); // if (isConnectedToSocialNetworks) // PaymentHelper.PayViaWallet(context, userId, GlobalConfig.FreeTrial14ProductId, SubscriptionProductType.Package, userId, null); // else // PaymentHelper.PayViaWallet(context, userId, GlobalConfig.FreeTrial7ProductId, SubscriptionProductType.Package, userId, null); // context.SaveChanges(); //} /***** DEC 31 2012 ****/ //UPDATED: FEB 18, 2013 - To include checking for TVE if (usr.IsTVERegistrant == null || usr.IsTVERegistrant == false) { int freeTrialProductId = 0; if (GlobalConfig.IsFreeTrialEnabled) { freeTrialProductId = MyUtility.GetCorrespondingFreeTrialProductId(); context = new IPTV2Entities(); if (GlobalConfig.TfcTvFree2StartDate < registDt && GlobalConfig.TfcTvFree2EndDate > registDt) { string UserCountryCode = user.CountryCode; if (!GlobalConfig.isUAT) try { UserCountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy(); } catch (Exception) { } var countryList = GlobalConfig.TfcTvFree2CountryWhiteList.Split(','); if (countryList.Contains(UserCountryCode) && String.Compare(user.CountryCode, UserCountryCode, true) == 0) freeTrialProductId = GlobalConfig.TfcTvFree2ProductId; } if (Request.Cookies.AllKeys.Contains("vntycok")) { freeTrialProductId = GlobalConfig.FreeTrial14ProductId; } if (isConnectedToSocialNetworks) PaymentHelper.PayViaWallet(context, userId, freeTrialProductId, SubscriptionProductType.Package, userId, null); } } //Publish to Activity Feed List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_actionlink_href) }); //mediaItem List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.register_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.register_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_mediaitem_href) }); UserAction action = new UserAction() { actorUID = userId.ToString(), userMessage = SNSTemplates.register_usermessage, title = SNSTemplates.register_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_linkback), description = String.Format(SNSTemplates.register_description, FirstName), actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, userId, "external"); action.userMessage = String.Empty; action.title = String.Empty; action.mediaItems = null; GigyaMethods.PublishUserAction(action, userId, "internal"); var email_err = String.Empty; //FormsAuthentication.SetAuthCookie(userId.ToString(), true); if (isConnectedToSocialNetworks) { //SetAutheticationCookie(userId.ToString()); if (!Request.IsLocal) { try { MyUtility.SendConfirmationEmail(context, usr); } catch (Exception) { } } href = GlobalConfig.RegistrationConfirmPage; //UPDATED: FEB 18, 2013 if (usr.IsTVERegistrant != null) if ((bool)usr.IsTVERegistrant) { href = GlobalConfig.TVERegistrationPage; MyUtility.RemoveTVECookie(); } } else { if (!isTFCnowCustomer) { //string emailBody = String.Format("Copy and paste this url to activate your TFC.tv Account {0}/User/Verify?email={1}&key={2}", GlobalConfig.baseUrl, usr.EMail, ActivationKey.ToString()); string verification_email = String.Format("{0}/User/Verify?key={1}", GlobalConfig.baseUrl, usr.ActivationKey.ToString()); string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, usr.FirstName, usr.EMail, verification_email); //MyUtility.SendEmailViaSendGrid(usr.EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody); if (!Request.IsLocal) try { //MyUtility.SendEmailViaSendGrid(usr.EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody); MyUtility.SendEmailViaSendGrid(usr.EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); } catch (Exception) { email_err = " But we are not able to send the verification email."; } } } ////UPDATED: FEB 12, 2012 //if (!String.IsNullOrEmpty(fc["TVEverywhere"])) //{ // if (String.Compare(fc["TVEverywhere"], "0", true) == 0) // { // TempData["tempUserId"] = userId; // href = GlobalConfig.TVERegistrationPage; // TempData["isConnectedToSocialNetworks"] = isConnectedToSocialNetworks; // } //} if (usr.StatusId == GlobalConfig.Visible) //UPDATED: MARCH 1, 2013. Only set Authentication Cookie when user is verified. SetAutheticationCookie(userId.ToString()); errorMessage = "Thank you! You are now registered to TFC.tv!" + email_err; collection = MyUtility.setError(ErrorCodes.Success, errorMessage); collection.Add("info", String.Format("{0}|{1}|{2}", user.EMail, Request.GetUserHostAddressFromCloudflare(), provider)); collection.Add("href", href); FlagBetaKey(fc["iid"]); } else { errorMessage = "The system encountered an unidentified error. Please try again."; collection = MyUtility.setError(ErrorCodes.EntityUpdateError, errorMessage); } } catch (Exception e) { collection = MyUtility.setError(ErrorCodes.EntityUpdateError, e.InnerException.InnerException.Message + "<br/>" + e.InnerException.InnerException.StackTrace); } return Content(MyUtility.buildJson(collection), "application/json"); }
public ActionResult ShareEpisode(int? id, string type, string categoryType, bool? isClip, int? sid) { Dictionary<string, object> collection = new Dictionary<string, object>(); ErrorCodes errorCode = ErrorCodes.UnknownError; string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError); collection = MyUtility.setError(errorCode, errorMessage); if (id == null || String.IsNullOrEmpty(type)) return Content(MyUtility.buildJson(collection), "application/json"); if (!MyUtility.isUserLoggedIn()) return Content(MyUtility.buildJson(collection), "application/json"); var context = new IPTV2Entities(); Episode episode = context.Episodes.FirstOrDefault(e => e.EpisodeId == id); if (episode == null) return Content(MyUtility.buildJson(collection), "application/json"); System.Guid userId = new Guid(User.Identity.Name); User user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user == null) return Content(MyUtility.buildJson(collection), "application/json"); EpisodeCategory category = episode.EpisodeCategories.LastOrDefault(e => e.EpisodeId == id); if (category == null) return Content(MyUtility.buildJson(collection), "application/json"); string CategoryName = category.Show.Description; if (sid != null) { var show = context.CategoryClasses.FirstOrDefault(c => c.CategoryId == sid); if (show != null) if (show is Show) CategoryName = ((Show)show).Description; } if (isClip == null) isClip = false; string userMessage = (bool)isClip ? String.Format(SNSTemplates.watch_preview_usermessage, CategoryName) : String.Format(SNSTemplates.watch_usermessage, CategoryName); string actionTitle = SNSTemplates.watch_title; string actionDescription = SNSTemplates.watch_description; if (category.Show is Movie) { actionTitle = SNSTemplates.watch_movie_title; actionDescription = SNSTemplates.watch_movie_description; userMessage = (bool)isClip ? String.Format(SNSTemplates.watch_movie_preview_usermessage, CategoryName) : String.Format(SNSTemplates.watch_movie_usermessage, CategoryName); } List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.watch_actionlink_href) }); List<MediaItem> mediaItems = new List<MediaItem>(); string img = String.IsNullOrEmpty(episode.ImageAssets.ImageVideo) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format(SNSTemplates.watch_mediaitem_src, GlobalConfig.EpisodeImgPath, episode.EpisodeId.ToString(), episode.ImageAssets.ImageVideo); mediaItems.Add(new MediaItem() { type = SNSTemplates.watch_mediaitem_type, src = img, href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.watch_mediaitem_href, episode.EpisodeId)) }); UserAction action = new UserAction() { userMessage = userMessage, title = actionTitle, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.watch_subtitle, episode.EpisodeId.ToString())), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.watch_linkback, episode.EpisodeId.ToString())), description = actionDescription, actionLinks = actionlinks, mediaItems = mediaItems, actorUID = User.Identity.Name }; //var userData = GigyaMethods.GetUserData(user.UserId, "ProfileSetting"); var userData = MyUtility.GetUserPrivacySetting(user.UserId); if (userData.IsExternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "external"); action.description = String.Empty; if (userData.IsInternalSharingEnabled.Contains("true")) return Content(GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal"), "application/json"); collection = MyUtility.setError(ErrorCodes.Success); return this.Json(collection, JsonRequestBehavior.AllowGet); }
public ActionResult PublishAction(int? id, string type) { Dictionary<string, object> collection = new Dictionary<string, object>(); ErrorCodes errorCode = ErrorCodes.UnknownError; string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError); collection = MyUtility.setError(errorCode, errorMessage); if (id == null || String.IsNullOrEmpty(type)) return Content(MyUtility.buildJson(collection), "application/json"); if (!MyUtility.isUserLoggedIn()) return Content(MyUtility.buildJson(collection), "application/json"); var context = new IPTV2Entities(); Episode episode = context.Episodes.FirstOrDefault(e => e.EpisodeId == id); if (episode == null) return Content(MyUtility.buildJson(collection), "application/json"); EpisodeCategory category = episode.EpisodeCategories.FirstOrDefault(e => e.EpisodeId == id); if (category == null) return Content(MyUtility.buildJson(collection), "application/json"); string CategoryName = category.Show.Description; List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = SNSTemplates.watch_actionlink_href }); List<MediaItem> mediaItems = new List<MediaItem>(); string img = String.IsNullOrEmpty(episode.ImageAssets.ImageVideo) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format(SNSTemplates.watch_mediaitem_src, GlobalConfig.EpisodeImgPath, episode.EpisodeId.ToString(), episode.ImageAssets.ImageVideo); mediaItems.Add(new MediaItem() { type = SNSTemplates.watch_mediaitem_type, src = img, href = String.Format(SNSTemplates.watch_mediaitem_href, episode.EpisodeId) }); UserAction action = new UserAction() { userMessage = String.Format(SNSTemplates.watch_usermessage, CategoryName), title = SNSTemplates.watch_title, subtitle = String.Format(SNSTemplates.watch_subtitle, episode.EpisodeId.ToString()), linkBack = String.Format(SNSTemplates.watch_linkback, episode.EpisodeId.ToString()), description = SNSTemplates.watch_description, actionLinks = actionlinks, mediaItems = mediaItems, actorUID = User.Identity.Name }; GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "external"); action.description = String.Empty; return Content(GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal"), "application/json"); }
public ActionResult ShareMedia(string message, string title, string description, string img, string href) { Dictionary<string, object> collection = new Dictionary<string, object>(); ErrorCodes errorCode = ErrorCodes.UnknownError; string errorMessage = MyUtility.getErrorMessage(ErrorCodes.UnknownError); collection = MyUtility.setError(errorCode, errorMessage); if (!MyUtility.isUserLoggedIn()) return Content(MyUtility.buildJson(collection), "application/json"); try { var context = new IPTV2Entities(); System.Guid userId = new Guid(User.Identity.Name); User user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user == null) return Content(MyUtility.buildJson(collection), "application/json"); List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text_generic, href = href }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.watch_mediaitem_type, src = img, href = href }); UserAction action = new UserAction() { userMessage = message, title = title, subtitle = SNSTemplates.subtitle_generic, linkBack = href, description = description, actionLinks = actionlinks, mediaItems = mediaItems, actorUID = User.Identity.Name }; var userData = MyUtility.GetUserPrivacySetting(user.UserId); if (userData.IsExternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "external"); action.description = String.Empty; if (userData.IsInternalSharingEnabled.Contains("true")) return Content(GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal"), "application/json"); collection = MyUtility.setError(ErrorCodes.Success); } catch (Exception) { } return this.Json(collection, JsonRequestBehavior.AllowGet); }
public ActionResult Register(FormCollection fc) { SynapseResponse response = new SynapseResponse(); Dictionary<string, object> collection = new Dictionary<string, object>(); response.errorCode = (int)ErrorCodes.IsAlreadyAuthenticated; response.errorMessage = @"Please go to http://tfc.tv to register."; return this.Json(response, JsonRequestBehavior.AllowGet); if (MyUtility.isUserLoggedIn()) //User is logged in. { response.errorCode = (int)ErrorCodes.IsAlreadyAuthenticated; response.errorMessage = "User is already authenticated."; return this.Json(response, JsonRequestBehavior.AllowGet); } if (String.IsNullOrEmpty(fc["Email"])) { response.errorCode = (int)ErrorCodes.IsEmailEmpty; response.errorMessage = MyUtility.getErrorMessage(ErrorCodes.IsEmailEmpty); return this.Json(response, JsonRequestBehavior.AllowGet); } if (String.Compare(fc["Password"], fc["ConfirmPassword"], false) != 0) { response.errorCode = (int)ErrorCodes.IsMismatchPassword; response.errorMessage = MyUtility.getErrorMessage(ErrorCodes.IsMismatchPassword); return this.Json(response, JsonRequestBehavior.AllowGet); } if (String.IsNullOrEmpty(fc["FirstName"]) || String.IsNullOrEmpty(fc["LastName"]) || String.IsNullOrEmpty(fc["CountryCode"])) { response.errorCode = (int)ErrorCodes.IsMissingRequiredFields; response.errorMessage = MyUtility.getErrorMessage(ErrorCodes.IsMissingRequiredFields); return this.Json(response, JsonRequestBehavior.AllowGet); } try { string FirstName = fc["FirstName"]; string LastName = fc["LastName"]; string CountryCode = fc["CountryCode"]; string EMail = fc["Email"]; string Password = fc["Password"]; string City = fc["City"]; string State = String.IsNullOrEmpty(fc["State"]) ? fc["StateDD"] : fc["State"]; System.Guid userId = System.Guid.NewGuid(); if (FirstName.Length > 32) { response.errorCode = (int)ErrorCodes.LimitReached; response.errorMessage = "First Name cannot exceed 32 characters."; return this.Json(response, JsonRequestBehavior.AllowGet); } if (LastName.Length > 32) { response.errorCode = (int)ErrorCodes.LimitReached; response.errorMessage = "Last Name cannot exceed 32 characters."; return this.Json(response, JsonRequestBehavior.AllowGet); } if (EMail.Length > 64) { response.errorCode = (int)ErrorCodes.LimitReached; response.errorMessage = "Email cannot exceed 64 characters."; return this.Json(response, JsonRequestBehavior.AllowGet); } if (!String.IsNullOrEmpty(State)) if (State.Length > 30) { response.errorCode = (int)ErrorCodes.LimitReached; response.errorMessage = "State cannot exceed 30 characters."; return this.Json(response, JsonRequestBehavior.AllowGet); } if (!String.IsNullOrEmpty(City)) if (City.Length > 50) { response.errorCode = (int)ErrorCodes.LimitReached; response.errorMessage = "City cannot exceed 50 characters."; return this.Json(response, JsonRequestBehavior.AllowGet); } var context = new IPTV2Entities(); User user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EMail, true) == 0); if (user != null) { response.errorCode = (int)ErrorCodes.IsExistingEmail; response.errorMessage = MyUtility.getErrorMessage(ErrorCodes.IsExistingEmail); return this.Json(response, JsonRequestBehavior.AllowGet); } /***** CHECK FOR COUNTRY CODE ****/ if (context.Countries.Count(c => String.Compare(c.Code, CountryCode, true) == 0) <= 0) { response.errorCode = (int)ErrorCodes.IsMissingRequiredFields; response.errorMessage = "Country Code is invalid."; return this.Json(response, JsonRequestBehavior.AllowGet); } else if (GlobalConfig.ExcludedCountriesFromRegistrationDropDown.Split(',').Contains(CountryCode)) { response.errorCode = (int)ErrorCodes.IsMissingRequiredFields; response.errorMessage = "Country Code is invalid."; return this.Json(response, JsonRequestBehavior.AllowGet); } DateTime registDt = DateTime.Now; user = new User() { UserId = userId, FirstName = FirstName, LastName = LastName, City = City, State = State, CountryCode = CountryCode, EMail = EMail, Password = MyUtility.GetSHA1(Password), GigyaUID = userId.ToString(), RegistrationDate = registDt, LastUpdated = registDt, RegistrationIp = Request.GetUserHostAddressFromCloudflare(), StatusId = 1, ActivationKey = Guid.NewGuid(), DateVerified = registDt }; string CurrencyCode = GlobalConfig.DefaultCurrency; Country country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0); if (country != null) { Currency currency = context.Currencies.FirstOrDefault(c => String.Compare(c.Code, country.CurrencyCode, true) == 0); if (currency != null) CurrencyCode = currency.Code; } UserWallet wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0); if (wallet == null) // Wallet does not exist. Create new wallet for User. { wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt); user.UserWallets.Add(wallet); } var transaction = new RegistrationTransaction() { RegisteredState = user.State, RegisteredCity = user.City, RegisteredCountryCode = user.CountryCode, Amount = 0, Currency = CurrencyCode, Reference = "New Registration (Mobile)", Date = registDt, OfferingId = GlobalConfig.offeringId, UserId = user.UserId, StatusId = GlobalConfig.Visible }; user.Transactions.Add(transaction); context.Users.Add(user); if (context.SaveChanges() > 0) { if (!String.IsNullOrEmpty(fc["UID"])) { Dictionary<string, object> GigyaCollection = new Dictionary<string, object>(); collection.Add("uid", fc["UID"]); collection.Add("siteUID", userId); collection.Add("cid", String.Format("{0} - New User", fc["provider"])); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", GigyaHelpers.buildParameter(collection)); } else { Dictionary<string, object> userInfo = new Dictionary<string, object>(); userInfo.Add("firstName", user.FirstName); userInfo.Add("lastName", user.LastName); userInfo.Add("email", user.EMail); Dictionary<string, object> gigyaCollection = new Dictionary<string, object>(); gigyaCollection.Add("siteUID", user.UserId); gigyaCollection.Add("cid", "TFCTV - Registration"); gigyaCollection.Add("sessionExpiration", "0"); gigyaCollection.Add("newUser", true); gigyaCollection.Add("userInfo", MyUtility.buildJson(userInfo)); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", GigyaHelpers.buildParameter(gigyaCollection)); GigyaHelpers.setCookie(res, this.ControllerContext); } //setUserData User usr = context.Users.FirstOrDefault(u => String.Compare(u.EMail, EMail, true) == 0); setUserData(usr.UserId.ToString(), usr); if (usr.IsTVERegistrant == null || usr.IsTVERegistrant == false) { int freeTrialProductId = 0; if (GlobalConfig.IsFreeTrialEnabled) { freeTrialProductId = MyUtility.GetCorrespondingFreeTrialProductId(); context = new IPTV2Entities(); if (GlobalConfig.TfcTvFree2StartDate < registDt && GlobalConfig.TfcTvFree2EndDate > registDt) { string UserCountryCode = user.CountryCode; if (!GlobalConfig.isUAT) try { UserCountryCode = MyUtility.GetCountryCodeViaIpAddressWithoutProxy(); } catch (Exception) { } var countryList = GlobalConfig.TfcTvFree2CountryWhiteList.Split(','); if (countryList.Contains(UserCountryCode) && String.Compare(user.CountryCode, UserCountryCode, true) == 0) freeTrialProductId = GlobalConfig.TfcTvFree2ProductId; } //if (user.StatusId == GlobalConfig.Visible) PaymentHelper.PayViaWallet(context, userId, freeTrialProductId, SubscriptionProductType.Package, userId, null); } } //Publish to Activity Feed List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = SNSTemplates.register_actionlink_href }); UserAction action = new UserAction() { actorUID = userId.ToString(), userMessage = SNSTemplates.register_usermessage, title = SNSTemplates.register_title, subtitle = SNSTemplates.register_subtitle, linkBack = SNSTemplates.register_linkback, description = String.Format(SNSTemplates.register_description, FirstName), actionLinks = actionlinks }; GigyaMethods.PublishUserAction(action, userId, "external"); action.userMessage = String.Empty; action.title = String.Empty; GigyaMethods.PublishUserAction(action, userId, "internal"); //string verification_email = String.Format("{0}/User/Verify?email={1}&key={2}", GlobalConfig.baseUrl, EMail, user.ActivationKey.ToString()); //string emailBody = String.Format(GlobalConfig.EmailVerificationBodyTextOnly, FirstName, EMail, verification_email); //if (!Request.IsLocal) // try { MyUtility.SendEmailViaSendGrid(EMail, GlobalConfig.NoReplyEmail, "Activate your TFC.tv account", emailBody, MailType.TextOnly, emailBody); } // catch (Exception e) { MyUtility.LogException(e, "Unable to send email via SendGrid"); } response.errorCode = (int)ErrorCodes.Success; response.errorMessage = "Registration successful."; GSResponse gres = GetToken(user); if (gres != null) { SynapseToken token = new SynapseToken() { uid = user.UserId.ToString(), token = gres.GetString("access_token", String.Empty), expire = gres.GetInt("expires_in", 0), }; response.data = token; } HttpCookie authCookie = SetAutheticationCookie(user.UserId.ToString()); SynapseCookie cookie = new SynapseCookie() { cookieName = authCookie.Name, cookieDomain = authCookie.Domain, cookiePath = authCookie.Path, cookieValue = authCookie.Value }; response.info = cookie; } else { response.errorCode = (int)ErrorCodes.EntityUpdateError; response.errorMessage = "Unable to register user"; } } catch (Exception e) { response.errorCode = (int)ErrorCodes.UnknownError; response.errorMessage = e.Message; } return this.Json(response, JsonRequestBehavior.AllowGet); }
public ActionResult Share(string url, int? id) { Dictionary<string, object> collection = new Dictionary<string, object>(); collection = MyUtility.setError(ErrorCodes.UnknownError, String.Empty); if (!MyUtility.isUserLoggedIn()) return Content(MyUtility.buildJson(collection), "application/json"); var context = new IPTV2Entities(); if (id == null) id = GlobalConfig.ClickTayoMVEpisodeId; var episode = context.Episodes.FirstOrDefault(e => e.EpisodeId == id); if (episode != null) { System.Guid userId = new Guid(User.Identity.Name); User user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user != null) { string title = String.Empty; var category = episode.EpisodeCategories.FirstOrDefault(e => e.CategoryId != GlobalConfig.FreeTvCategoryId); if (category != null) title = category.Show.Description; List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = url }); List<MediaItem> mediaItems = new List<MediaItem>(); string img = String.IsNullOrEmpty(episode.ImageAssets.ImageVideo) ? GlobalConfig.AssetsBaseUrl + GlobalConfig.BlankGif : String.Format(SNSTemplates.watch_mediaitem_src, GlobalConfig.EpisodeImgPath, episode.EpisodeId.ToString(), episode.ImageAssets.ImageVideo); mediaItems.Add(new MediaItem() { type = SNSTemplates.watch_mediaitem_type, src = img, href = url }); UserAction action = new UserAction() { userMessage = "Saan ka man sa mundo Click Tayo! #ClickTayo", title = title, subtitle = GlobalConfig.baseUrl, linkBack = url, description = episode.Synopsis, actionLinks = actionlinks, mediaItems = mediaItems, actorUID = User.Identity.Name }; if (id != GlobalConfig.ClickTayoMVEpisodeId) { action.userMessage = "I just had my share of Halo-Halo Clicks!"; action.title = episode.EpisodeName; } try { if (episode.EpisodeCategories.Count(c => c.CategoryId == GlobalConfig.KwentoNgPaskoCategoryId) > 0) action.userMessage = "Dumarami ang mga tala ngayong Pasko sa TFC.tv!"; } catch (Exception) { } try { if (episode.EpisodeCategories.Count(c => c.CategoryId == GlobalConfig.HimigHandogCategoryId) > 0) { action.userMessage = "I just sang along with this Himig Handog song!"; action.title = episode.EpisodeName; } } catch (Exception) { } var userData = MyUtility.GetUserPrivacySetting(user.UserId); var privacy = "public"; if (userData.IsProfilePrivate.Contains("true")) privacy = "private"; if (userData.IsExternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "external", privacy); action.description = String.Empty; if (userData.IsInternalSharingEnabled.Contains("true")) { action.userMessage = String.Format("has watched {0}", episode.EpisodeName); return Content(GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal", privacy), "application/json"); } collection = MyUtility.setError(ErrorCodes.Success); } } return this.Json(collection, JsonRequestBehavior.AllowGet); }
private void ReceiveGiftShareToSocialNetwork(Product product, User recipient, User user) { //Publish user action List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_actionlink_href) }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.rgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.rgift_mediaitem_href, recipient.UserId.ToString())) }); UserAction action = new UserAction() { actorUID = recipient.UserId.ToString(), userMessage = String.Format(SNSTemplates.rgift_usermessage_external, product.Description, String.Format("{0} {1}", user.FirstName, user.LastName)), title = SNSTemplates.rgift_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.rgift_linkback, recipient.UserId.ToString())), description = SNSTemplates.rgift_description, actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, recipient.UserId, "external"); //Modify action to suit Internal feed needs mediaItems.Clear(); mediaItems.Add(new MediaItem() { type = SNSTemplates.rgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_mediaitem_src_internal), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.rgift_mediaitem_href, recipient.UserId.ToString())) }); action.userMessage = String.Format(SNSTemplates.rgift_usermessage, product.Description, user.UserId, String.Format("{0} {1}", user.FirstName, user.LastName)); action.description = String.Format(SNSTemplates.rgift_description_internal, product.Description, user.UserId, String.Format("{0} {1}", user.FirstName, user.LastName)); action.mediaItems = mediaItems; GigyaMethods.PublishUserAction(action, recipient.UserId, "internal"); }
private void SendGiftShareToSocialNetwork(Product product, User recipient) { //Publish user action List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.sgift_actionlink_href) }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.sgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.sgift_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.sgift_mediaitem_href, User.Identity.Name)) }); UserAction action = new UserAction() { actorUID = User.Identity.Name, userMessage = String.Format(SNSTemplates.sgift_usermessage_external, product.Description, String.Format("{0} {1}", recipient.FirstName, recipient.LastName)), title = SNSTemplates.sgift_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.sgift_subtitle), linkBack = String.Format(SNSTemplates.sgift_linkback, User.Identity.Name), description = SNSTemplates.sgift_description, actionLinks = actionlinks, mediaItems = mediaItems }; var userId = new Guid(User.Identity.Name); var userData = MyUtility.GetUserPrivacySetting(userId); if (userData.IsExternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "external"); //Modify action to suit Internal feed needs mediaItems.Clear(); mediaItems.Add(new MediaItem() { type = SNSTemplates.sgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.sgift_mediaitem_src_internal), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.sgift_mediaitem_href, User.Identity.Name)) }); action.userMessage = String.Format(SNSTemplates.sgift_usermessage, product.Description, recipient.UserId, String.Format("{0} {1}", recipient.FirstName, recipient.LastName)); action.description = String.Format(SNSTemplates.sgift_description_internal, product.Description, recipient.UserId, String.Format("{0} {1}", recipient.FirstName, recipient.LastName)); action.mediaItems = mediaItems; if (userData.IsInternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal"); }
public ActionResult SetUserAboutInfo(Guid id, string userAboutInfo, string userName) { if (id == new Guid(User.Identity.Name)) { Dictionary<string, object> collection = new Dictionary<string, object>(); collection.Add("UID", id.ToString()); collection.Add("data", new { about = userAboutInfo }); //GSResponse res = GigyaHelpers.createAndSendRequest("gcs.setUserData", GigyaHelpers.buildParameter(collection)); GSResponse res = GigyaHelpers.createAndSendRequest("ids.setAccountInfo", GigyaHelpers.buildParameter(collection)); //Share to Social Network site. List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format(SNSTemplates.status_actionlink_href, User.Identity.Name) }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.status_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.status_mediaitem_src), href = String.Format(SNSTemplates.status_mediaitem_href, User.Identity.Name) }); string gender = GigyaMethods.GetUserInfoByKey(new System.Guid(User.Identity.Name), "gender"); UserAction action = new UserAction() { actorUID = User.Identity.Name, userMessage = String.Format(SNSTemplates.about_description_internal, gender == "f" ? "her" : "him"), title = SNSTemplates.status_title_external, subtitle = SNSTemplates.status_subtitle, linkBack = String.Format(SNSTemplates.status_linkback, User.Identity.Name), description = "\"" + userAboutInfo + "\"", actionLinks = actionlinks, mediaItems = mediaItems }; var userId = new Guid(User.Identity.Name); var userData = MyUtility.GetUserPrivacySetting(userId); if (userData.IsInternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal"); return Content(res.GetData().ToJsonString(), "application/json"); } return Json(new { errorCode = -1 }, JsonRequestBehavior.AllowGet); }
public ActionResult Add(int? id) { Dictionary<string, object> collection = new Dictionary<string, object>(); ErrorCodes errorCode = ErrorCodes.UnknownError; string errorMessage = "ERROR"; collection = MyUtility.setError(errorCode, errorMessage); if (id != null) { if (!IsWishlisted((int)id)) { if (!User.Identity.IsAuthenticated) { collection = MyUtility.setError(ErrorCodes.NotAuthenticated, "NOT AUTHENTICATED"); return Content(MyUtility.buildJson(collection), "application/json"); } var context = new IPTV2Entities(); Product product = context.Products.FirstOrDefault(p => p.ProductId == id && p.OfferingId == GlobalConfig.offeringId && p.StatusId == GlobalConfig.Visible); if (product != null) { Wishlist wishlist = new Wishlist() { UID_s = User.Identity.Name, registDt_d = DateTime.Now.ToString("s"), ProductId_i = product.ProductId, ProductName_s = product.Description }; WishlistModel model = new WishlistModel() { type = "Wishlist", data = wishlist }; string wishlist_json = JsonConvert.SerializeObject(model); GSResponse res = GigyaHelpers.createAndSendRequest("gcs.setObjectData", new GSObject(wishlist_json)); if (res.GetErrorCode() == 0) { //Publish user action List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.wishlist_actionlink_href, User.Identity.Name)) }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.wishlist_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.wishlist_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.wishlist_mediaitem_href, User.Identity.Name)) }); string gender = GigyaMethods.GetUserInfoByKey(new System.Guid(User.Identity.Name), "gender"); UserAction action = new UserAction() { actorUID = User.Identity.Name, userMessage = String.Format(SNSTemplates.wishlist_usermessage, product.Description, gender == "f" ? "her" : "his"), title = SNSTemplates.wishlist_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.wishlist_subtitle, User.Identity.Name)), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.wishlist_linkback, User.Identity.Name)), description = SNSTemplates.wishlist_description, actionLinks = actionlinks, mediaItems = mediaItems }; var userId = new Guid(User.Identity.Name); var userData = MyUtility.GetUserPrivacySetting(userId); if (userData.IsExternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, userId, "external"); //Modify action to suit Internal feed needs mediaItems.Clear(); mediaItems.Add(new MediaItem() { type = SNSTemplates.wishlist_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.wishlist_mediaitem_src_internal), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.wishlist_mediaitem_href, User.Identity.Name)) }); action.description = SNSTemplates.wishlist_description_internal; action.mediaItems = mediaItems; if (userData.IsInternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, userId, "internal"); } return Content(res.GetData().ToJsonString(), "application/json"); } } else { errorCode = ErrorCodes.WishlistItemExists; errorMessage = "ALREADY EXISTS"; collection = MyUtility.setError(errorCode, errorMessage); } } return Content(MyUtility.buildJson(collection), "application/json"); }
private void PublishGigyaActions(User user, GSResponse res) { GigyaHelpers.setCookie(res, this.ControllerContext); GigyaUserData userData = new GigyaUserData() { City = user.City, CountryCode = user.CountryCode, Email = user.EMail, FirstName = user.FirstName, LastName = user.LastName, State = user.State }; GigyaUserDataInfo userDataInfo = new GigyaUserDataInfo() { UID = user.UserId.ToString(), data = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Newtonsoft.Json.Formatting.None) }; GSObject userDataInfoObj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)); //res = GigyaHelpers.createAndSendRequest("gcs.setUserData", userDataInfoObj); res = GigyaHelpers.createAndSendRequest("ids.setAccountInfo", userDataInfoObj); var returnCode = res.GetErrorCode(); //Publish to Activity Feed List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_actionlink_href) }); //mediaItem List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.register_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.register_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_mediaitem_href) }); UserAction action = new UserAction() { actorUID = user.UserId.ToString(), userMessage = SNSTemplates.register_usermessage, title = SNSTemplates.register_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_linkback), description = String.Format(SNSTemplates.register_description, user.FirstName), actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, user.UserId, "external"); action.userMessage = String.Empty; action.title = String.Empty; action.mediaItems = null; GigyaMethods.PublishUserAction(action, user.UserId, "internal"); }
public JsonResult GSocialize() { var ReturnCode = new SocializeReturnCodeObj() { StatusCode = (int)ErrorCodes.UnknownError, StatusMessage = String.Empty }; var registDt = DateTime.Now; var skipValidation = false; try { if (!String.IsNullOrEmpty(Request.QueryString["sv"])) { var svTemp = Convert.ToInt32(Request.QueryString["sv"]); if (svTemp == 1) skipValidation = true; } } catch (Exception) { } try { NameValueCollection qs = Request.QueryString; string gigyaUID = Uri.UnescapeDataString(qs["UID"]); bool isRequestValid = SigUtils.ValidateUserSignature(gigyaUID, Uri.UnescapeDataString(qs["timestamp"]), GlobalConfig.GSsecretkey, Uri.UnescapeDataString(qs["signature"])); if (isRequestValid || skipValidation) { using (var context = new IPTV2Entities()) { User user = null; bool isSiteUID = Convert.ToBoolean(qs["isSiteUID"]); if (isSiteUID) //Old user. Signin to site { var UserId = new Guid(gigyaUID); user = context.Users.FirstOrDefault(u => u.UserId == UserId); if (user != null) { if (user.StatusId == GlobalConfig.Visible) //Successful Login ReturnCode.StatusCode = (int)ErrorCodes.Success; else ReturnCode.StatusMessage = "Account is not verified in our system."; } else { //ReturnCode.StatusMessage = "Social networking account does not exist in our system."; //Create user string FirstName = qs["first_name"]; string LastName = qs["last_name"]; string EMail = qs["login_email"]; string uid = qs["uid"]; string provider = qs["provider"]; string Password = Membership.GeneratePassword(10, 2); string City = String.Empty; string State = String.Empty; string CountryCode = GlobalConfig.DefaultCountry; var id = UserId; var ip = qs["ip"]; try { var location = MyUtility.GetLocationBasedOnIpAddress(ip); City = location.city; CountryCode = location.countryCode; State = String.Compare(CountryCode, GlobalConfig.DefaultCountry, true) == 0 ? location.region : location.regionName; } catch (Exception) { } user = new User() { UserId = id, FirstName = FirstName, LastName = LastName, City = City, State = State, CountryCode = CountryCode, EMail = EMail, Password = MyUtility.GetSHA1(Password), GigyaUID = id.ToString(), RegistrationDate = registDt, LastUpdated = registDt, RegistrationIp = ip ?? MyUtility.GetClientIpAddress(), DateVerified = registDt, StatusId = GlobalConfig.Visible, ActivationKey = Guid.NewGuid() }; var CurrencyCode = GlobalConfig.DefaultCurrency; var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0); if (country != null) CurrencyCode = country.CurrencyCode; var wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0); if (wallet == null) { wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt); user.UserWallets.Add(wallet); } var transaction = new RegistrationTransaction() { RegisteredState = user.State, RegisteredCity = user.City, RegisteredCountryCode = user.CountryCode, Amount = 0, Currency = CurrencyCode, Reference = "New Registration (AIR PLUS)", Date = registDt, OfferingId = GlobalConfig.offeringId, UserId = user.UserId, StatusId = GlobalConfig.Visible }; user.Transactions.Add(transaction); context.Users.Add(user); if (context.SaveChanges() > 0) { ReturnCode.StatusCode = (int)ErrorCodes.Success; GSResponse res = null; GigyaUserData2 userData = new GigyaUserData2() { city = user.City, country = user.CountryCode, email = user.EMail, firstName = user.FirstName, lastName = user.LastName, state = user.State }; TFCTV.Helpers.UserData privacyData = new UserData() { IsExternalSharingEnabled = "true,false", IsInternalSharingEnabled = "true,false", IsProfilePrivate = "false" }; GigyaUserDataInfo2 userDataInfo = new GigyaUserDataInfo2() { UID = user.UserId.ToString(), profile = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Formatting.None), data = Newtonsoft.Json.JsonConvert.SerializeObject(privacyData, Formatting.None) }; GSObject userDataInfoObj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)); //res = GigyaHelpers.createAndSendRequest("gcs.setUserData", userDataInfoObj); res = GigyaHelpers.createAndSendRequest("ids.setAccountInfo", userDataInfoObj); //Publish to Activity Feed List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_actionlink_href) }); //mediaItem List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.register_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.register_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_mediaitem_href) }); UserAction action = new UserAction() { actorUID = user.UserId.ToString(), userMessage = SNSTemplates.register_usermessage, title = SNSTemplates.register_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_linkback), description = String.Format(SNSTemplates.register_description, FirstName), actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, user.UserId, "external"); action.userMessage = String.Empty; action.title = String.Empty; action.mediaItems = null; GigyaMethods.PublishUserAction(action, user.UserId, "internal"); } } } else //New user. allow user to register { bool createUser = true; if (!String.IsNullOrEmpty(qs["email"])) { string email = qs["email"]; user = context.Users.FirstOrDefault(u => String.Compare(u.EMail, email, true) == 0); if (user != null) // link account { Dictionary<string, object> collection = new Dictionary<string, object>(); collection.Add("siteUID", user.UserId); collection.Add("uid", Uri.UnescapeDataString(qs["UID"])); collection.Add("cid", String.Format("{0} - New User", qs["provider"])); GSObject obj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(collection)); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", obj); if (res.GetErrorCode() == 0) //Successful link { createUser = false; var UserId = user.UserId.ToString(); user.StatusId = GlobalConfig.Visible; //activate account user.DateVerified = DateTime.Now; if (context.SaveChanges() > 0) ReturnCode.StatusCode = (int)ErrorCodes.Success; else ReturnCode.StatusMessage = "Create user failed"; } else ReturnCode.StatusMessage = res.GetErrorMessage(); } } if (createUser) { string FirstName = qs["first_name"]; string LastName = qs["last_name"]; string EMail = qs["login_email"]; string uid = qs["uid"]; string provider = qs["provider"]; string Password = Membership.GeneratePassword(10, 2); string City = String.Empty; string State = String.Empty; string CountryCode = GlobalConfig.DefaultCountry; var id = Guid.NewGuid(); var ip = qs["ip"]; try { var location = MyUtility.GetLocationBasedOnIpAddress(ip); City = location.city; CountryCode = location.countryCode; State = String.Compare(CountryCode, GlobalConfig.DefaultCountry, true) == 0 ? location.region : location.regionName; } catch (Exception) { } user = new User() { UserId = id, FirstName = FirstName, LastName = LastName, City = City, State = State, CountryCode = CountryCode, EMail = EMail, Password = MyUtility.GetSHA1(Password), GigyaUID = id.ToString(), RegistrationDate = registDt, LastUpdated = registDt, RegistrationIp = ip ?? MyUtility.GetClientIpAddress(), ActivationKey = Guid.NewGuid() }; var CurrencyCode = GlobalConfig.DefaultCurrency; var country = context.Countries.FirstOrDefault(c => String.Compare(c.Code, CountryCode, true) == 0); if (country != null) CurrencyCode = country.CurrencyCode; var wallet = user.UserWallets.FirstOrDefault(w => String.Compare(w.Currency, CurrencyCode, true) == 0); if (wallet == null) { wallet = ContextHelper.CreateWallet(0, CurrencyCode, registDt); user.UserWallets.Add(wallet); } var transaction = new RegistrationTransaction() { RegisteredState = user.State, RegisteredCity = user.City, RegisteredCountryCode = user.CountryCode, Amount = 0, Currency = CurrencyCode, Reference = "New Registration (AIR PLUS)", Date = registDt, OfferingId = GlobalConfig.offeringId, UserId = user.UserId, StatusId = GlobalConfig.Visible }; user.Transactions.Add(transaction); context.Users.Add(user); if (context.SaveChanges() > 0) { GSResponse res = null; if (!String.IsNullOrEmpty(uid) && !String.IsNullOrEmpty(provider)) { Dictionary<string, object> collection = new Dictionary<string, object>(); collection.Add("siteUID", user.UserId); collection.Add("uid", Uri.UnescapeDataString(uid)); collection.Add("cid", String.Format("{0} - New User", provider)); res = GigyaHelpers.createAndSendRequest("socialize.notifyRegistration", GigyaHelpers.buildParameter(collection)); if (res.GetErrorCode() == 0) //Successful link { if (user != null) { var UserId = user.UserId.ToString(); user.StatusId = GlobalConfig.Visible; //activate account user.DateVerified = DateTime.Now; if (context.SaveChanges() > 0) ReturnCode.StatusCode = (int)ErrorCodes.Success; } } } else ReturnCode.StatusMessage = "Missing parameters uid & provider"; //else //{ // var info = new GigyaUserInfo() // { // firstName = FirstName, // lastName = LastName, // email = EMail // }; // var registrationInfo = new GigyaNotifyLoginInfo() // { // siteUID = user.UserId.ToString(), // cid = "TFCTV - Registration", // sessionExpiration = 0, // newUser = true, // userInfo = Newtonsoft.Json.JsonConvert.SerializeObject(info) // }; // GSObject obj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(registrationInfo)); // res = GigyaHelpers.createAndSendRequest("socialize.notifyLogin", obj); // ReturnCode.StatusCode = (int)ErrorCodes.Success; //} if (ReturnCode.StatusCode == (int)ErrorCodes.Success) { GigyaUserData2 userData = new GigyaUserData2() { city = user.City, country = user.CountryCode, email = user.EMail, firstName = user.FirstName, lastName = user.LastName, state = user.State }; TFCTV.Helpers.UserData privacyData = new UserData() { IsExternalSharingEnabled = "true,false", IsInternalSharingEnabled = "true,false", IsProfilePrivate = "false" }; GigyaUserDataInfo2 userDataInfo = new GigyaUserDataInfo2() { UID = user.UserId.ToString(), profile = Newtonsoft.Json.JsonConvert.SerializeObject(userData, Formatting.None), data = Newtonsoft.Json.JsonConvert.SerializeObject(privacyData, Formatting.None) }; GSObject userDataInfoObj = new GSObject(Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)); //res = GigyaHelpers.createAndSendRequest("gcs.setUserData", userDataInfoObj); res = GigyaHelpers.createAndSendRequest("ids.setAccountInfo", userDataInfoObj); //Publish to Activity Feed List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.register_actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_actionlink_href) }); //mediaItem List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.register_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.register_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_mediaitem_href) }); UserAction action = new UserAction() { actorUID = user.UserId.ToString(), userMessage = SNSTemplates.register_usermessage, title = SNSTemplates.register_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.register_linkback), description = String.Format(SNSTemplates.register_description, FirstName), actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, user.UserId, "external"); action.userMessage = String.Empty; action.title = String.Empty; action.mediaItems = null; GigyaMethods.PublishUserAction(action, user.UserId, "internal"); } } } } if (ReturnCode.StatusCode == (int)ErrorCodes.Success) { ReturnCode.StatusMessage = "Success!"; //GenerateToken SynapseUserInfo uInfo = new SynapseUserInfo() { firstName = user.FirstName, lastName = user.LastName, email = user.EMail }; Dictionary<string, object> collection = new Dictionary<string, object>(); collection.Add("client_id", GlobalConfig.GSapikey); collection.Add("client_secret", GlobalConfig.GSsecretkey); collection.Add("grant_type", "none"); collection.Add("x_siteUID", user.UserId); collection.Add("x_sessionExpiration", 0); collection.Add("x_userInfo", JsonConvert.SerializeObject(uInfo)); GSResponse res = GigyaHelpers.createAndSendRequest("socialize.getToken", GigyaHelpers.buildParameter(collection)); SynapseCookie cookie = new SynapseCookie() { cookieName = FormsAuthentication.FormsCookieName, cookiePath = FormsAuthentication.FormsCookiePath, cookieDomain = FormsAuthentication.CookieDomain }; if (res.GetErrorCode() == 0) { HttpCookie authCookie = SetCookie(user.UserId.ToString()); cookie.cookieValue = authCookie.Value; ContextHelper.SaveSessionInDatabase(context, user, authCookie.Value); SynapseToken token = new SynapseToken() { uid = user.UserId.ToString(), token = res.GetString("access_token", String.Empty), expire = res.GetInt("expires_in", 0), }; ReturnCode.tk = token; ReturnCode.gs = cookie; } else { ReturnCode.StatusCode = res.GetErrorCode(); ReturnCode.StatusMessage = res.GetErrorMessage(); } } } } else ReturnCode.StatusMessage = "Request is not valid"; } catch (Exception e) { MyUtility.LogException(e); ReturnCode.StatusMessage = String.Format("Exception: {0} | Inner Exception: {1}", e.Message, e.InnerException.Message); } return this.Json(ReturnCode, JsonRequestBehavior.AllowGet); }