Ejemplo n.º 1
0
        public ActionResult Youtube()
        {
            string AddYoutubeAccount = 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.User.User       ApiobjUser    = new Api.User.User();
            if (Session["googlepluslogin"] != null)
            {
                objUser        = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(apiobjYoutube.GoogleLogin(code), typeof(Domain.Socioboard.Domain.User)));
                checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                if (checkuserexist != null)
                {
                    Session["User"] = checkuserexist;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    Session["User"] = objUser;
                    return(RedirectToAction("Registration", "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 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.User.User ApiobjUser = new Api.User.User();
            if (Session["googlepluslogin"] != null)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    if (Session["googlepluslogin"].ToString() == "googlepluslogin")
                    {
                        //objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(apiobjYoutube.GoogleLogin(code), typeof(Domain.Socioboard.Domain.User)));
                        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)
                        {
                            Session["User"] = checkuserexist;
                            int daysremaining = 0;

                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"] = "******";
                                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                    Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["Paid_User"] = "******";
                            }
                            FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                            ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());
                            return RedirectToAction("Index", "Home");
                        }
                        else
                        {
                            objUser.ActivationStatus = "1";
                            Session["User"] = objUser;
                            return RedirectToAction("Registration", "Index");
                        }
                    }
                    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
                {
                    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");
        }
Ejemplo n.º 3
0
        public ActionResult Youtube()
        {
            string AddYoutubeAccount = 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.User.User       ApiobjUser    = new Api.User.User();
            if (Session["googlepluslogin"] != null)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    objUser        = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(apiobjYoutube.GoogleLogin(code), typeof(Domain.Socioboard.Domain.User)));
                    checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                    if (checkuserexist != null)
                    {
                        Session["User"] = checkuserexist;
                        int daysremaining = 0;

                        daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                        if (daysremaining > 0)
                        {
                            #region Count Used Accounts
                            try
                            {
                                Session["Paid_User"] = "******";
                                Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            #endregion
                        }
                        else
                        {
                            Session["Paid_User"] = "******";
                        }
                        FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        Session["User"] = objUser;
                        return(RedirectToAction("Registration", "Index"));
                    }
                }
                else
                {
                    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 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 Youtube()
        {
            string AddYoutubeAccount = string.Empty;
            string status = "";
            string AddGPlusAccount = string.Empty;
            Domain.Myfashion.Domain.User objUser = (Domain.Myfashion.Domain.User)Session["User"];
            Domain.Myfashion.Domain.User checkuserexist = (Domain.Myfashion.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.User.User ApiobjUser = new Api.User.User();

            if (Session["googlepluslogin"] != null)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    if (Session["googlepluslogin"].ToString() == "googlepluslogin")
                    {
                        //objUser = (Domain.Myfashion.Domain.User)(new JavaScriptSerializer().Deserialize(apiobjYoutube.GoogleLogin(code), typeof(Domain.Myfashion.Domain.User)));
                        string Googleloginreturn = apiobjYoutube.GoogleLogin(code);
                        string[] arrgoogleloginreturn = Regex.Split(Googleloginreturn, "_#_");
                        objUser = (Domain.Myfashion.Domain.User)(new JavaScriptSerializer().Deserialize(arrgoogleloginreturn[0], typeof(Domain.Myfashion.Domain.User)));
                        Session["AccesstokenFblogin"] = arrgoogleloginreturn[1];
                        Session["googlepluslogin"] = "******";
                        checkuserexist = (Domain.Myfashion.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Myfashion.Domain.User)));
                        string pid = checkuserexist.PuId;
                        string puid = pid.Substring(36, pid.Length - 36);
                        SortedDictionary<string, string> strdic = new SortedDictionary<string, string>();
                        strdic.Add("username", checkuserexist.EmailId);
                        strdic.Add("password", puid);
                        string data = CustomHttpWebRequest.HttpWebRequest("GET", "myfashion/loginService.action", strdic);
                        data = data.Replace("func({", "{");
                        data = data.Replace("});", "}");
                        JObject jo = JObject.Parse(data);
                        status = Server.UrlDecode((string)jo["code"]);

                        if (checkuserexist != null)
                        {
                            Session["User"] = checkuserexist;
                            int daysremaining = 0;

                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"] = "******";
                                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                    //Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["Paid_User"] = "******";
                            }
                            FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                            //ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());
                            if (status == "101")
                            {
                                return RedirectToAction("Index", "Home");
                            }
                            else
                            {
                                return RedirectToAction("Index", "Index");
                            }
                        }
                        else
                        {
                            objUser.ActivationStatus = "1";
                            Session["User"] = objUser;
                            return RedirectToAction("SignUp", "Index");
                        }
                    }
                    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
                {
                    return RedirectToAction("SocialMedia", "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("SocialMedia", "Home");
        }
        public ActionResult Youtube()
        {
            string AddYoutubeAccount = string.Empty;
            string status            = "";
            string AddGPlusAccount   = string.Empty;

            Domain.Myfashion.Domain.User objUser        = (Domain.Myfashion.Domain.User)Session["User"];
            Domain.Myfashion.Domain.User checkuserexist = (Domain.Myfashion.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.User.User             ApiobjUser       = new Api.User.User();

            if (Session["googlepluslogin"] != null)
            {
                if (!string.IsNullOrEmpty(code))
                {
                    if (Session["googlepluslogin"].ToString() == "googlepluslogin")
                    {
                        //objUser = (Domain.Myfashion.Domain.User)(new JavaScriptSerializer().Deserialize(apiobjYoutube.GoogleLogin(code), typeof(Domain.Myfashion.Domain.User)));
                        string   Googleloginreturn    = apiobjYoutube.GoogleLogin(code);
                        string[] arrgoogleloginreturn = Regex.Split(Googleloginreturn, "_#_");
                        objUser = (Domain.Myfashion.Domain.User)(new JavaScriptSerializer().Deserialize(arrgoogleloginreturn[0], typeof(Domain.Myfashion.Domain.User)));
                        Session["AccesstokenFblogin"] = arrgoogleloginreturn[1];
                        Session["googlepluslogin"]    = "******";
                        checkuserexist = (Domain.Myfashion.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Myfashion.Domain.User)));
                        string pid  = checkuserexist.PuId;
                        string puid = pid.Substring(36, pid.Length - 36);
                        SortedDictionary <string, string> strdic = new SortedDictionary <string, string>();
                        strdic.Add("username", checkuserexist.EmailId);
                        strdic.Add("password", puid);
                        string data = CustomHttpWebRequest.HttpWebRequest("GET", "myfashion/loginService.action", strdic);
                        data = data.Replace("func({", "{");
                        data = data.Replace("});", "}");
                        JObject jo = JObject.Parse(data);
                        status = Server.UrlDecode((string)jo["code"]);

                        if (checkuserexist != null)
                        {
                            Session["User"] = checkuserexist;
                            int daysremaining = 0;

                            daysremaining = (checkuserexist.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"] = "******";
                                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                    //Session["ProfileCount"] = Convert.ToInt32(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["Paid_User"] = "******";
                            }
                            FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                            //ApiobjUser.UpdateLastLoginTime(checkuserexist.Id.ToString());
                            if (status == "101")
                            {
                                return(RedirectToAction("Index", "Home"));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Index"));
                            }
                        }
                        else
                        {
                            objUser.ActivationStatus = "1";
                            Session["User"]          = objUser;
                            return(RedirectToAction("SignUp", "Index"));
                        }
                    }
                    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
                {
                    return(RedirectToAction("SocialMedia", "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("SocialMedia", "Home"));
        }
Ejemplo n.º 7
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"));
        }