public async Task<ActionResult> Youtube()
        {
            string AddYoutubeAccount = string.Empty;
            string AddGPlusAccount = string.Empty;
            Domain.Socioboard.Domain.User objUser = (Domain.Socioboard.Domain.User)Session["User"];
            Domain.Socioboard.Domain.User checkuserexist = (Domain.Socioboard.Domain.User)Session["User"];
            string code = (String)Request.QueryString["code"];
            Api.Youtube.Youtube apiobjYoutube = new Api.Youtube.Youtube();
            Api.GooglePlus.GooglePlus ApiobjGooglePlus = new Api.GooglePlus.GooglePlus();
            Api.GoogleAnalytics.GoogleAnalytics ApiGoogleAnalytics = new Api.GoogleAnalytics.GoogleAnalytics();
            Api.User.User ApiobjUser = new Api.User.User();
            if (Session["googlepluslogin"] != "youtube")
            {
                if (!string.IsNullOrEmpty(code))
                {
                    if (Session["googlepluslogin"].ToString() == "googlepluslogin")
                    {
                        string Googleloginreturn = apiobjYoutube.GoogleLogin(code);
                        string[] arrgoogleloginreturn = Regex.Split(Googleloginreturn, "_#_");
                        objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrgoogleloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                        Session["AccesstokenFblogin"] = arrgoogleloginreturn[1];
                        Session["googlepluslogin"] = "******";
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        if (checkuserexist != null)
                        {
                            objUser = checkuserexist;
                            Session["User"] = checkuserexist;
                            Session["group"] = await SBHelper.LoadGroups(objUser.Id);
                            Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                            try
                            {
                                Dictionary<string, string> re = await ac.GetTokenDictionary(checkuserexist.EmailId, checkuserexist.Password);
                                Session["access_token"] = re["access_token"];
                            }
                            catch (Exception e)
                            {
                                return RedirectToAction("Index", "Home");
                            }

                            daysremaining = 0;
                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"] = "******";
                                    Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                    Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["Paid_User"] = "******";
                            }
                            Response.Cookies.Add(FormsAuthentication.GetAuthCookie(objUser.UserName, true));
                            ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());

                            HttpCookie myCookie = new HttpCookie("referal_url");
                            myCookie = Request.Cookies["referal_url"];
                            if (myCookie != null)
                            {
                                Response.Redirect(".." + myCookie.Value);
                            }

                            return RedirectToAction("Index", "Home");
                        }
                        else
                        {
                            objUser.ActivationStatus = "1";
                            Session["User"] = objUser;
                            return RedirectToAction("Registration", "Index");
                        }
                    }
                    else if (Session["googlepluslogin"].ToString() == "gplugin")
                    {
                        string Googleloginreturn = apiobjYoutube.GoogleLogin(code);
                        string[] arrgoogleloginreturn = Regex.Split(Googleloginreturn, "_#_");
                        objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrgoogleloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                        Session["AccesstokenFblogin"] = arrgoogleloginreturn[1];
                      
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        if (checkuserexist != null)
                        {
                            objUser = checkuserexist;
                            Session["User"] = checkuserexist;
                            FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                            ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(objUser.EmailId))
                            {
                                string user = ApiobjUser.Register(objUser.EmailId, "", "Free", objUser.UserName, "1");
                                objUser = (Domain.Socioboard.Domain.User)new JavaScriptSerializer().Deserialize(user, typeof(Domain.Socioboard.Domain.User));
                                Session["User"] = objUser;
                            }
                            else {
                                return RedirectToAction("Index", "Index", new { hint = "plugin" });
                            }
                        }
                        Session["group"] = await SBHelper.LoadGroups(objUser.Id);
                        Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                        try
                        {
                            Dictionary<string, string> re = await ac.GetTokenDictionary(checkuserexist.EmailId, checkuserexist.Password);
                            Session["access_token"] = re["access_token"];
                        }
                        catch (Exception e)
                        {
                            return RedirectToAction("Index", "Home");
                        }
                        daysremaining = 0;
                        try
                        {
                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                        }
                        catch (Exception ex)
                        {
                        }
                        #region Count Used Accounts
                        try
                        {
                            Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                            Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                        }
                        catch (Exception ex)
                        {
                            Session["ProfileCount"] = 0;
                            Session["TotalAccount"] = 0;
                        }
                        #endregion
                        if (daysremaining > 0)
                        {
                            Session["Paid_User"] = "******";
                        }
                        else
                        {
                            Session["Paid_User"] = "******";
                        }
                        Session["googlepluslogin"] = "******";
                        return RedirectToAction("Index", "Home", new { hint = "plugin" });
                    }
                    else if (Session["googlepluslogin"].ToString() == "gplus")
                    {
                        AddGPlusAccount = ApiobjGooglePlus.AddGPlusAccount(ConfigurationManager.AppSettings["YtconsumerKey"], ConfigurationManager.AppSettings["YtconsumerSecret"], ConfigurationManager.AppSettings["Ytredirect_uri"], objUser.Id.ToString(), Session["group"].ToString(), code);
                        if (AddGPlusAccount == "Refresh Token Not Found")
                        {
                            AuthenticateYoutube(Session["googlepluslogin"].ToString());
                        }
                        else
                        {
                            Session["SocialManagerInfo"] = AddGPlusAccount;
                        }
                    }
                    else if (Session["googlepluslogin"].ToString() == "ga")
                    {
                        string ret_data = ApiGoogleAnalytics.GetAnalyticsProfile(code);

                        if (ret_data == "Refresh Token Not Found")
                        {
                            AuthenticateYoutube(Session["googlepluslogin"].ToString());
                        }
                        else
                        {
                            List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = (List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles>)new JavaScriptSerializer().Deserialize(ret_data, typeof(List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles>));
                            Session["GAProfiles"] = lstGoogleAnalyticsProfiles;
                        }
                        
                        return RedirectToAction("Index", "Home", new { hint = "gaprofile" });
                    }
                }
                else
                {
                    if (Session["googlepluslogin"].ToString() == "gplugin")
                    {
                        Session["googlepluslogin"] = null;
                        return RedirectToAction("Index", "Index", new { hint = "plugin" });
                    }
                    
                    return RedirectToAction("Index", "Index");
                }
            }
            else
            {
                try
                {
                    AddYoutubeAccount = apiobjYoutube.AddYoutubeAccount(ConfigurationManager.AppSettings["YtconsumerKey"], ConfigurationManager.AppSettings["YtconsumerSecret"], ConfigurationManager.AppSettings["Ytredirect_uri"], objUser.Id.ToString(), Session["group"].ToString(), code);
                    if (AddYoutubeAccount == "Refresh Token Not Found")
                    {
                        AuthenticateYoutube("");
                    }
                    else
                    {
                        Session["SocialManagerInfo"] = AddYoutubeAccount;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return RedirectToAction("Index", "Home");
        }
 public ActionResult AddGaProfiles(string arrId)
 {
     Domain.Socioboard.Domain.User _User=(Domain.Socioboard.Domain.User)Session["User"];
     Api.GoogleAnalytics.GoogleAnalytics ApiGoogleAnalytics = new Api.GoogleAnalytics.GoogleAnalytics();
     string [] arrProfiles=arrId.Split(',');
     List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = (List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles>)Session["GAProfiles"];
     lstGoogleAnalyticsProfiles = lstGoogleAnalyticsProfiles.Where(t => arrId.Contains(t.ProfileId)).ToList();
     string strGoogleAnalyticsProfiles = new JavaScriptSerializer().Serialize(lstGoogleAnalyticsProfiles);
     string ret = ApiGoogleAnalytics.AddAnalyticsProfiles(strGoogleAnalyticsProfiles, _User.Id.ToString(), Session["group"].ToString());
     return Content("Success");
 }
示例#3
0
        public async Task <ActionResult> Youtube()
        {
            string AddYoutubeAccount = string.Empty;
            string AddGPlusAccount   = string.Empty;

            Domain.Socioboard.Domain.User objUser        = (Domain.Socioboard.Domain.User)Session["User"];
            Domain.Socioboard.Domain.User checkuserexist = (Domain.Socioboard.Domain.User)Session["User"];
            string code = (String)Request.QueryString["code"];

            Api.Youtube.Youtube                 apiobjYoutube      = new Api.Youtube.Youtube();
            Api.GooglePlus.GooglePlus           ApiobjGooglePlus   = new Api.GooglePlus.GooglePlus();
            Api.GoogleAnalytics.GoogleAnalytics ApiGoogleAnalytics = new Api.GoogleAnalytics.GoogleAnalytics();
            Api.User.User ApiobjUser = new Api.User.User();
            if (Session["googlepluslogin"] != "youtube")
            {
                if (!string.IsNullOrEmpty(code))
                {
                    if (Session["googlepluslogin"].ToString() == "googlepluslogin")
                    {
                        string   Googleloginreturn    = apiobjYoutube.GoogleLogin(code);
                        string[] arrgoogleloginreturn = Regex.Split(Googleloginreturn, "_#_");
                        objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrgoogleloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                        Session["AccesstokenFblogin"] = arrgoogleloginreturn[1];
                        Session["googlepluslogin"]    = "******";
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        if (checkuserexist != null)
                        {
                            objUser          = checkuserexist;
                            Session["User"]  = checkuserexist;
                            Session["group"] = await SBHelper.LoadGroups(objUser.Id);

                            Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                            try
                            {
                                Dictionary <string, string> re = await ac.GetTokenDictionary(checkuserexist.EmailId, checkuserexist.Password);

                                Session["access_token"] = re["access_token"];
                            }
                            catch (Exception e)
                            {
                                return(RedirectToAction("Index", "Home"));
                            }

                            daysremaining = 0;
                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"]    = "******";
                                    Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                    Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["Paid_User"] = "******";
                            }
                            Response.Cookies.Add(FormsAuthentication.GetAuthCookie(objUser.UserName, true));
                            ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());

                            HttpCookie myCookie = new HttpCookie("referal_url");
                            myCookie = Request.Cookies["referal_url"];
                            if (myCookie != null)
                            {
                                Response.Redirect(".." + myCookie.Value);
                            }

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            objUser.ActivationStatus = "1";
                            Session["User"]          = objUser;
                            return(RedirectToAction("Registration", "Index"));
                        }
                    }
                    else if (Session["googlepluslogin"].ToString() == "gplugin")
                    {
                        string   Googleloginreturn    = apiobjYoutube.GoogleLogin(code);
                        string[] arrgoogleloginreturn = Regex.Split(Googleloginreturn, "_#_");
                        objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrgoogleloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                        Session["AccesstokenFblogin"] = arrgoogleloginreturn[1];

                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        if (checkuserexist != null)
                        {
                            objUser         = checkuserexist;
                            Session["User"] = checkuserexist;
                            FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                            ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(objUser.EmailId))
                            {
                                string user = ApiobjUser.Register(objUser.EmailId, "", "Free", objUser.UserName, "1");
                                objUser         = (Domain.Socioboard.Domain.User) new JavaScriptSerializer().Deserialize(user, typeof(Domain.Socioboard.Domain.User));
                                Session["User"] = objUser;
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Index", new { hint = "plugin" }));
                            }
                        }
                        Session["group"] = await SBHelper.LoadGroups(objUser.Id);

                        Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                        try
                        {
                            Dictionary <string, string> re = await ac.GetTokenDictionary(checkuserexist.EmailId, checkuserexist.Password);

                            Session["access_token"] = re["access_token"];
                        }
                        catch (Exception e)
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        daysremaining = 0;
                        try
                        {
                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                        }
                        catch (Exception ex)
                        {
                        }
                        #region Count Used Accounts
                        try
                        {
                            Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                            Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                        }
                        catch (Exception ex)
                        {
                            Session["ProfileCount"] = 0;
                            Session["TotalAccount"] = 0;
                        }
                        #endregion
                        if (daysremaining > 0)
                        {
                            Session["Paid_User"] = "******";
                        }
                        else
                        {
                            Session["Paid_User"] = "******";
                        }
                        Session["googlepluslogin"] = "******";
                        return(RedirectToAction("Index", "Home", new { hint = "plugin" }));
                    }
                    else if (Session["googlepluslogin"].ToString() == "gplus")
                    {
                        AddGPlusAccount = ApiobjGooglePlus.AddGPlusAccount(ConfigurationManager.AppSettings["YtconsumerKey"], ConfigurationManager.AppSettings["YtconsumerSecret"], ConfigurationManager.AppSettings["Ytredirect_uri"], objUser.Id.ToString(), Session["group"].ToString(), code);
                        if (AddGPlusAccount == "Refresh Token Not Found")
                        {
                            AuthenticateYoutube(Session["googlepluslogin"].ToString());
                        }
                        else
                        {
                            Session["SocialManagerInfo"] = AddGPlusAccount;
                        }
                    }
                    else if (Session["googlepluslogin"].ToString() == "ga")
                    {
                        string ret_data = ApiGoogleAnalytics.GetAnalyticsProfile(code);

                        if (ret_data == "Refresh Token Not Found")
                        {
                            AuthenticateYoutube(Session["googlepluslogin"].ToString());
                        }
                        else
                        {
                            List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = (List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles>) new JavaScriptSerializer().Deserialize(ret_data, typeof(List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles>));
                            Session["GAProfiles"] = lstGoogleAnalyticsProfiles;
                        }

                        return(RedirectToAction("Index", "Home", new { hint = "gaprofile" }));
                    }
                }
                else
                {
                    if (Session["googlepluslogin"].ToString() == "gplugin")
                    {
                        Session["googlepluslogin"] = null;
                        return(RedirectToAction("Index", "Index", new { hint = "plugin" }));
                    }

                    return(RedirectToAction("Index", "Index"));
                }
            }
            else
            {
                try
                {
                    AddYoutubeAccount = apiobjYoutube.AddYoutubeAccount(ConfigurationManager.AppSettings["YtconsumerKey"], ConfigurationManager.AppSettings["YtconsumerSecret"], ConfigurationManager.AppSettings["Ytredirect_uri"], objUser.Id.ToString(), Session["group"].ToString(), code);
                    if (AddYoutubeAccount == "Refresh Token Not Found")
                    {
                        AuthenticateYoutube("");
                    }
                    else
                    {
                        Session["SocialManagerInfo"] = AddYoutubeAccount;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }