Beispiel #1
0
        public async Task <ActionResult> AuthenticateInstagram()
        {
            int count = 0;

            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");
            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

            try
            {
                count = Convert.ToInt32(profileCount);
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Error while getting profile count.";
                return(RedirectToAction("Index", "Home"));
            }
            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);

            if (count >= MaxCount)
            {
                TempData["Error"] = "Max profile Count reached.";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                HttpContext.Session.SetObjectAsJson("Instagram", "Instagram_Account");
                string authUrl = _appSettings.InsagramAuthUrl + "&client_id=" + _appSettings.InstagramClientKey + "&redirect_uri=" + _appSettings.InstagramCallBackURL;
                return(Redirect(authUrl));
            }
        }
Beispiel #2
0
        public async Task <ActionResult> AddGoogleAccount(string Op)
        {
            int count = 0;

            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");

            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

            try
            {
                count = Convert.ToInt32(profileCount);
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Error while getting profile count.";
                return(RedirectToAction("Index", "Home"));
            }

            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);

            if (count >= MaxCount)
            {
                TempData["Error"] = "Max profile Count reached.";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (string.IsNullOrEmpty(Op))
                {
                    HttpContext.Session.SetObjectAsJson("Google", "Gplus_Account");
                    string googleurl = "https://accounts.google.com/o/oauth2/auth?client_id=" + _appSettings.GoogleConsumerKey + "&redirect_uri=" + _appSettings.GoogleRedirectUri + "&scope=https://www.googleapis.com/auth/youtube+https://www.googleapis.com/auth/youtube.readonly+https://www.googleapis.com/auth/youtubepartner+https://www.googleapis.com/auth/youtubepartner-channel-audit+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/plus.me&response_type=code&access_type=offline&approval_prompt=force";
                    return(Redirect(googleurl));
                }
                else
                {
                    HttpContext.Session.SetObjectAsJson("Google", "Ganalytics_Account");
                    string googleurl = "https://accounts.google.com/o/oauth2/auth?approval_prompt=force&access_type=offline&client_id=" + _appSettings.GoogleConsumerKey + "&redirect_uri=" + _appSettings.GoogleRedirectUri + "&scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/analytics+https://www.googleapis.com/auth/analytics.edit+https://www.googleapis.com/auth/analytics.readonly&response_type=code";
                    return(Redirect(googleurl));
                }
            }
        }
Beispiel #3
0
        public async Task <ActionResult> AuthenticateLinkedin(string Op)
        {
            int    count = 0;
            Random ran   = new Random();
            int    x     = ran.Next(8976557);

            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");

            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

            try
            {
                count = Convert.ToInt32(profileCount);
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Error while getting profile count.";
                return(RedirectToAction("Index", "Home"));
            }

            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);

            if (count >= MaxCount)
            {
                TempData["Error"] = "Max profile Count reached.";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (string.IsNullOrEmpty(Op))
                {
                    HttpContext.Session.SetObjectAsJson("linSocial", "lin_Account");
                    return(Redirect("https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=" + _appSettings.LinkedinApiKey + "&redirect_uri=" + _appSettings.LinkedinCallBackURL + "&state=" + x.ToString() + "&?scope=r_basicprofile+w_share"));
                }
                else
                {
                    HttpContext.Session.SetObjectAsJson("linSocial", "lin_Page");
                    return(Redirect("https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=" + _appSettings.LinkedinApiKey + "&redirect_uri=" + _appSettings.LinkedinCallBackURL + "&state=" + x.ToString() + "&?scope=r_basicprofile+w_share+rw_company_admin"));
                }
            }
        }
        public async Task <ActionResult> AddFacebookAcc(string Op)
        {
            int count = 0;

            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");

            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

            try
            {
                count = Convert.ToInt32(profileCount);
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Error while getting profile count.";
                return(RedirectToAction("Index", "Home"));
            }

            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);

            if (count >= MaxCount)
            {
                TempData["Error"] = "Max profile Count reached.";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (string.IsNullOrEmpty(Op))
                {
                    HttpContext.Session.SetObjectAsJson("fbSocial", "Fb_Account");
                }
                else
                {
                    HttpContext.Session.SetObjectAsJson("fbSocial", "Fb_Page");
                }
                return(Redirect(Socioboard.Facebook.Auth.Authentication.GetFacebookRedirectLink(_appSettings.FacebookAuthUrl, _appSettings.FacebookClientId, _appSettings.FacebookRedirectUrl)));
            }
        }
        public async Task <IActionResult> AddTwitterAccount(bool follow)
        {
            int count = 0;

            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");
            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

            try
            {
                count = Convert.ToInt32(profileCount);
            }
            catch (Exception ex)
            {
                TempData["Error"] = "Error while getting profile count.";
                return(RedirectToAction("Index", "Home"));
            }
            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);

            if (count >= MaxCount)
            {
                TempData["Error"] = "Max profile Count reached.";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                if (follow)
                {
                    HttpContext.Session.SetObjectAsJson("Twitter", "Twitter_Account_Follow");
                }
                else
                {
                    HttpContext.Session.SetObjectAsJson("Twitter", "Twitter_Account");
                }
                OAuthCredentials credentials = new OAuthCredentials()
                {
                    Type              = OAuthType.RequestToken,
                    SignatureMethod   = OAuthSignatureMethod.HmacSha1,
                    ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                    ConsumerKey       = _appSettings.twitterConsumerKey,
                    ConsumerSecret    = _appSettings.twitterConsumerScreatKey,
                    CallbackUrl       = _appSettings.twitterRedirectionUrl
                };
                // Use Hammock to create a rest client
                var client = new RestClient
                {
                    Authority   = "https://api.twitter.com/oauth",
                    Credentials = credentials,
                };
                // Use Hammock to create a request
                var request = new RestRequest
                {
                    Path = "request_token"
                };
                // Get the response from the request
                var response   = client.Request(request);
                var collection = HttpUtility.ParseQueryString(response.Content);
                //string str = collection[1].ToString();
                //HttpContext.Current.Session["requestSecret"] = collection[1];
                string rest = "https://api.twitter.com/oauth/authorize?oauth_token=" + collection[0];
                HttpContext.Session.SetObjectAsJson("requestSecret", collection[1]);

                return(Redirect(rest));
            }
        }
        public async Task <IActionResult> Index()
        {
            Domain.Socioboard.Models.User user = HttpContext.Session.GetObjectFromJson <Domain.Socioboard.Models.User>("User");

            if (user == null)
            {
                return(RedirectToAction("Index", "Index"));
            }

            try
            {
                if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Free)
                {
                    ViewBag.AccountType = "Free";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Deluxe)
                {
                    ViewBag.AccountType = "Deluxe";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Premium)
                {
                    ViewBag.AccountType = "Premium";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Topaz)
                {
                    ViewBag.AccountType = "Topaz";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Platinum)
                {
                    ViewBag.AccountType = "Platinum";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Gold)
                {
                    ViewBag.AccountType = "Gold";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Ruby)
                {
                    ViewBag.AccountType = "Ruby";
                }
                else if (user.AccountType == Domain.Socioboard.Enum.SBAccountType.Standard)
                {
                    ViewBag.AccountType = "Standard";
                }
                if (user.ExpiryDate < DateTime.UtcNow)
                {
                    //return RedirectToAction("UpgradePlans", "Index");
                    if (user.TrailStatus != Domain.Socioboard.Enum.UserTrailStatus.inactive)
                    {
                        List <KeyValuePair <string, string> > Param = new List <KeyValuePair <string, string> >();
                        Param.Add(new KeyValuePair <string, string>("Id", user.Id.ToString()));
                        HttpResponseMessage respon = await WebApiReq.PostReq("/api/User/UpdateTrialStatus", Param, "", "", _appSettings.ApiDomain);

                        if (respon.IsSuccessStatusCode)
                        {
                            Domain.Socioboard.Models.User _user = await respon.Content.ReadAsAsync <Domain.Socioboard.Models.User>();

                            HttpContext.Session.SetObjectAsJson("User", _user);
                            user = _user;
                        }
                    }
                }
                else if ((user.PayPalAccountStatus == Domain.Socioboard.Enum.PayPalAccountStatus.notadded || user.PayPalAccountStatus == Domain.Socioboard.Enum.PayPalAccountStatus.inprogress) && (user.AccountType != Domain.Socioboard.Enum.SBAccountType.Free))
                {
                    return(RedirectToAction("PayPalAccount", "Home", new { emailId = user.EmailId, IsLogin = true }));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "Index"));
            }
            HttpResponseMessage response = await WebApiReq.GetReq("/api/Groups/GetUserGroups?userId=" + user.Id, "", "", _appSettings.ApiDomain);

            if (response.IsSuccessStatusCode)
            {
                try
                {
                    List <Domain.Socioboard.Models.Groups> groups = await response.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groups> >();

                    ViewBag.groups = Newtonsoft.Json.JsonConvert.SerializeObject(groups);
                    string sessionSelectedGroupId = HttpContext.Session.GetObjectFromJson <string>("selectedGroupId");
                    if (!string.IsNullOrEmpty(sessionSelectedGroupId))
                    {
                        ViewBag.selectedGroupId = sessionSelectedGroupId;
                        HttpResponseMessage groupProfilesResponse = await WebApiReq.GetReq("/api/GroupProfiles/GetGroupProfiles?groupId=" + sessionSelectedGroupId, "", "", _appSettings.ApiDomain);

                        if (groupProfilesResponse.IsSuccessStatusCode)
                        {
                            List <Domain.Socioboard.Models.Groupprofiles> groupProfiles = await groupProfilesResponse.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groupprofiles> >();

                            ViewBag.groupProfiles = Newtonsoft.Json.JsonConvert.SerializeObject(groupProfiles);
                            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

                            int count    = Convert.ToInt32(profileCount);
                            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);
                            ViewBag.profileCount = count;
                            ViewBag.MaxCount     = MaxCount;
                            ViewBag.AccountType  = user.AccountType;
                            if (count > MaxCount)
                            {
                                ViewBag.downgrade = "true";
                            }
                            else
                            {
                                ViewBag.downgrade = "false";
                            }
                        }
                    }
                    else
                    {
                        long selectedGroupId = groups.FirstOrDefault(t => t.groupName == Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName).id;
                        HttpContext.Session.SetObjectAsJson("selectedGroupId", selectedGroupId);
                        ViewBag.selectedGroupId = selectedGroupId;
                        HttpResponseMessage groupProfilesResponse = await WebApiReq.GetReq("/api/GroupProfiles/GetGroupProfiles?groupId=" + selectedGroupId, "", "", _appSettings.ApiDomain);

                        if (groupProfilesResponse.IsSuccessStatusCode)
                        {
                            List <Domain.Socioboard.Models.Groupprofiles> groupProfiles = await groupProfilesResponse.Content.ReadAsAsync <List <Domain.Socioboard.Models.Groupprofiles> >();

                            ViewBag.groupProfiles = Newtonsoft.Json.JsonConvert.SerializeObject(groupProfiles);
                            string profileCount = await ProfilesHelper.GetUserProfileCount(user.Id, _appSettings, _logger);

                            int count    = Convert.ToInt32(profileCount);
                            int MaxCount = Domain.Socioboard.Helpers.SBHelper.GetMaxProfileCount(user.AccountType);
                            ViewBag.profileCount = count;
                            ViewBag.MaxCount     = MaxCount;
                            if (count > MaxCount)
                            {
                                ViewBag.downgrade = "true";
                            }
                            else
                            {
                                ViewBag.downgrade = "false";
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    HttpContext.Session.Remove("User");
                    HttpContext.Session.Remove("selectedGroupId");
                    HttpContext.Session.Clear();
                    ViewBag.user            = null;
                    ViewBag.selectedGroupId = null;
                    ViewBag.groupProfiles   = null;
                    TempData["Error"]       = "Some thing went wrong.";
                    return(RedirectToAction("Index", "Index"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Index"));
            }
            ViewBag.user = Newtonsoft.Json.JsonConvert.SerializeObject(user);
            return(View());
        }