public async System.Threading.Tasks.Task <ActionResult> test()
 {
     Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider("http://*****:*****@globussoft.com", "asd123");
     }
     catch (Exception e)
     { }
     return(View());
 }
 public async System.Threading.Tasks.Task<ActionResult> test()
 {
     Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider("http://*****:*****@globussoft.com", "asd123");
     }
     catch (Exception e)
     { }
     return View();
 }
        //[HttpPost]
        public async System.Threading.Tasks.Task<ActionResult> AjaxLogin(string username, string password)
        {
            Session.Clear();
            Session.RemoveAll();
            string returnmsg = string.Empty;
            User objUser = new User();
            string uname = Request.QueryString["username"].ToString();
            string pass = Request.QueryString["password"].ToString();
            Api.User.User obj = new Api.User.User();
            HttpResponseMessage response = await WebApiReq.GetReq("api/ApiUser/Login?EmailId=" + uname + "&PasswordHash=" + SBUtils.MD5Hash(pass), "", "");
            if (response.IsSuccessStatusCode)
            {
                objUser = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.User>();
                if (objUser != null)
                {
                    Response.Cookies.Add(FormsAuthentication.GetAuthCookie(objUser.UserName, true));
                    // FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                    Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                    try
                    {
                        Dictionary<string, string> re = await ac.GetTokenDictionary(username, SBUtils.MD5Hash(pass));
                        Session["access_token"] = re["access_token"];
                    }
                    catch (Exception e)
                    {
                        objUser = null;

                        // Edited by Antima 

                        HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                        myCookie.Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies.Add(myCookie);

                        returnmsg = "Invalid Email or Password";
                        return Content(returnmsg);
                    }

                    if (objUser != null)
                    {
                        if (objUser.ActivationStatus == "1")
                        {
                            int daysremaining = 0;

                            daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                Session["User"] = objUser;
                                Session["group"] = await SBHelper.LoadGroups(objUser.Id);
                                returnmsg = "user";
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"] = "******";
                                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                    Session["ProfileCount"] = Convert.ToInt16(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                    Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["User"] = objUser;
                                Session["Paid_User"] = "******";
                                returnmsg = "unpaid";
                            }
                        }
                        else if (objUser.ActivationStatus == "2")
                        {
                            returnmsg = "User Not Exist!";
                        }
                        else
                        {
                            returnmsg = "notactivated";
                        }
                    }
                    if (objUser.UserType == "SuperAdmin")
                    {
                        returnmsg = "SuperAdmin";
                        Session["User"] = objUser;
                    }
                }
            }
            else
            {
                objUser = null;
                HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);
                returnmsg = "Invalid Email or Password";
                return Content(returnmsg);
            }
            return Content(returnmsg);
        }
        public async System.Threading.Tasks.Task<ActionResult> AjaxPluginLogin()
        {
            Session.Clear();
            Session.RemoveAll();

            string returnmsg = string.Empty;

            string uname = Request.Form["email"].ToString();
            string pass = Request.Form["password"].ToString();
            User objUser = new User();
            Api.User.User ApiUser = new Api.User.User();
            string logindata = ApiUser.Login(uname, pass);
            string str = logindata.Replace("\"", string.Empty).Trim();
            if (str != "Not Exist" && !str.Equals("Email Not Exist"))
            {
                objUser = (User)(new JavaScriptSerializer().Deserialize(logindata, typeof(User)));
                FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                try
                {
                    Dictionary<string, string> re = await ac.GetTokenDictionary(uname, SBUtils.MD5Hash(pass));
                    Session["access_token"] = re["access_token"];
                }
                catch (Exception e)
                {
                    returnmsg = "Invalid Email or Password";
                    return Content(returnmsg);
                }
            }
            else if (str.Equals("Email Not Exist"))
            {
                returnmsg = "Sorry, " + ConfigurationManager.AppSettings["domain"] + " doesn't recognize that username.";
                return Content(returnmsg);
            }
            else
            {
                returnmsg = "Invalid Email or Password";
                return Content(returnmsg);
            }

            if (objUser != null)
            {
                if (objUser.ActivationStatus == "1")
                {
                    int daysremaining = 0;
                    daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                    #region Count Used Accounts
                    try
                    {
                        Session["ProfileCount"] = Convert.ToInt16(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["User"] = objUser;
                        returnmsg = "user";
                        Session["Paid_User"] = "******";
                    }
                    else
                    {
                        Session["User"] = objUser;
                        Session["Paid_User"] = "******";
                        returnmsg = "unpaid";
                    }
                }
                else if (objUser.ActivationStatus == "2")
                {
                    returnmsg = "User Not Exist!";
                }
                else
                {
                    returnmsg = "notactivated";
                }
            }

            return Content(returnmsg);
        }
Beispiel #5
0
        //[CustomAuthorize]
        public async Task <ActionResult> Facebook(string code)
        {
            if (Session["fblogin"] != null)
            {
                if ((string)Session["fblogin"] == "fblogin")
                {
                    Session["fblogin"] = null;
                    if (String.IsNullOrEmpty(code))
                    {
                        return(RedirectToAction("Index", "Index"));
                    }
                    Domain.Socioboard.Domain.User objUser        = (Domain.Socioboard.Domain.User)Session["User"];
                    Domain.Socioboard.Domain.User checkuserexist = (Domain.Socioboard.Domain.User)Session["User"];
                    string facebookcode = code;

                    string   fbloginreturn    = apiobjFacebook.FacebookLogin(code);
                    string[] arrfbloginreturn = Regex.Split(fbloginreturn, "_#_");
                    objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrfbloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                    Session["AccesstokenFblogin"] = arrfbloginreturn[1];
                    Session["fblogin"]            = "******";
                    try
                    {
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        FormsAuthentication.SetAuthCookie(checkuserexist.UserName, false);
                    }
                    catch (Exception e)
                    {
                        checkuserexist = null;
                    }
                    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());
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            #endregion
                        }
                        else
                        {
                            Session["Paid_User"] = "******";
                        }
                        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 ((string)Session["fblogin"] == "page")
                {
                    Session["fblogin"] = null;
                    Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();
                    List <Domain.Socioboard.Domain.AddFacebookPage> lstAddFacebookPage = new List <Domain.Socioboard.Domain.AddFacebookPage>();
                    lstAddFacebookPage = (List <Domain.Socioboard.Domain.AddFacebookPage>)(new JavaScriptSerializer().Deserialize(apiobjFacebook.GetFacebookPages(code), typeof(List <Domain.Socioboard.Domain.AddFacebookPage>)));
                    Session["fbpage"]  = lstAddFacebookPage;
                    return(RedirectToAction("Index", "Home", new { hint = "fbpage" }));
                }
                else if ((string)Session["fblogin"] == "fbgroup")
                {
                    Session["fblogin"] = null;

                    Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();
                    List <Domain.Socioboard.Domain.AddFacebookGroup> lstAddFacebookGroup = new List <Domain.Socioboard.Domain.AddFacebookGroup>();
                    lstAddFacebookGroup = (List <Domain.Socioboard.Domain.AddFacebookGroup>)(new JavaScriptSerializer().Deserialize(apiobjFacebook.GetFacebookGroups(code), typeof(List <Domain.Socioboard.Domain.AddFacebookGroup>)));
                    Session["fbgrp"]    = lstAddFacebookGroup;
                    return(RedirectToAction("Index", "Home", new { hint = "fbgrp" }));
                }
                else if ((string)Session["fblogin"] == "fbplugin")
                {
                    Session["fblogin"] = null;
                    if (String.IsNullOrEmpty(code))
                    {
                        return(RedirectToAction("Index", "Index", new { hint = "plugin" }));
                    }
                    Domain.Socioboard.Domain.User objUser        = (Domain.Socioboard.Domain.User)Session["User"];
                    Domain.Socioboard.Domain.User checkuserexist = (Domain.Socioboard.Domain.User)Session["User"];
                    Api.Facebook.Facebook         apiobjFacebook = new Api.Facebook.Facebook();
                    Api.User.User ApiobjUser       = new Api.User.User();
                    string        fbloginreturn    = apiobjFacebook.FacebookLogin(code);
                    string[]      arrfbloginreturn = Regex.Split(fbloginreturn, "_#_");

                    objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrfbloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                    Session["AccesstokenFblogin"] = arrfbloginreturn[1];
                    try
                    {
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        FormsAuthentication.SetAuthCookie(checkuserexist.UserName, false);
                    }
                    catch (Exception e)
                    {
                        checkuserexist = null;
                    }
                    if (checkuserexist != null)
                    {
                        objUser         = checkuserexist;
                        Session["User"] = checkuserexist;
                        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"));
                    }
                    #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
                    daysremaining = 0;
                    daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                    if (daysremaining > 0)
                    {
                        Session["Paid_User"] = "******";
                    }
                    else
                    {
                        Session["Paid_User"] = "******";
                    }
                    Session["fblogin"] = "******";
                    return(RedirectToAction("Index", "Home", new { hint = "plugin" }));
                }
            }
            else
            {
                Domain.Socioboard.Domain.User objUser = (Domain.Socioboard.Domain.User)Session["User"];
                string facebookcode = code;
                Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();

                apiobjFacebook.Timeout = 120 * 1000;

                //string AddfacebookAccount = apiobjFacebook.AddFacebookAccount(facebookcode, objUser.Id.ToString(), Session["group"].ToString());
                string AddfacebookAccount = "";
                Domain.Socioboard.Domain.FacebookAccount objfacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                try
                {
                    var res_addFacebook = apiobjFacebook.AddFacebookAccount(facebookcode, objUser.Id.ToString(), Session["group"].ToString());
                    AddfacebookAccount = res_addFacebook;
                    try
                    {
                        objfacebookAccount = (Domain.Socioboard.Domain.FacebookAccount) new JavaScriptSerializer().Deserialize(res_addFacebook, typeof(Domain.Socioboard.Domain.FacebookAccount));
                        AddfacebookAccount = objfacebookAccount.FbUserId;
                    }
                    catch (Exception)
                    {
                    }
                }
                catch (Exception)
                {
                    AddfacebookAccount = "issue_access_token";
                }

                if (AddfacebookAccount == "issue_access_token")
                {
                    Response.Redirect(Helper.SBUtils.GetFacebookRedirectLink());
                }
                else if (AddfacebookAccount == "Account already Exist !")
                {
                }
                else
                {
                    Session["SocialManagerInfo"] = AddfacebookAccount;

                    //To enable the Facebook Message Pop up
                    TempData["IsFacebookAccountAdded"] = 1;
                    TempData["FacebookAccount"]        = objfacebookAccount;
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        //[HttpPost]
        public async System.Threading.Tasks.Task<ActionResult> AjaxLogin(string username, string password)
        {
            Session.Clear();
            Session.RemoveAll();
            string returnmsg = string.Empty;
            User objUser = new User();
            string uname = Request.QueryString["username"].ToString();
            string pass = Request.QueryString["password"].ToString();
            Api.User.User obj = new Api.User.User();
            string logindata = obj.Login(uname, pass);
            string str = logindata.Replace("\"", string.Empty).Trim();
            if (str != "Not Exist" && !str.Equals("Email Not Exist"))
            {
                 objUser = (User)(new JavaScriptSerializer().Deserialize(logindata, typeof(User)));
                FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                try
                {
                    Dictionary<string, string> re = await ac.GetTokenDictionary(username, password);
                    Session["access_token"] = re["access_token"];
                }
                catch (Exception e)
                {
                    objUser = null;

                    // Edited by Antima 

                    HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                    myCookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(myCookie);

                    returnmsg = "Invalid Email or Password";
                    return Content(returnmsg);
                }
            }
            else if (str.Equals("Email Not Exist")) 
            {
                returnmsg = "Sorry, Socioboard doesn't recognize that username.";
                return Content(returnmsg);
            }
            else
            {
                objUser = null;

                // Edited by Antima 

                HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);

                returnmsg = "Invalid Email or Password";
                return Content(returnmsg);
            }

            #region Unused code
            //JObject profile = JObject.Parse(obj.Login(uname, pass));
            //objUser.Id = Guid.Parse(profile["Id"].ToString());
            //objUser.UserName = profile["UserName"].ToString();
            //objUser.AccountType = profile["AccountType"].ToString();
            //objUser.ProfileUrl = profile["ProfileUrl"].ToString();
            //objUser.EmailId = profile["EmailId"].ToString();
            //objUser.CreateDate = Convert.ToDateTime(profile["CreateDate"].ToString());
            //objUser.ExpiryDate = Convert.ToDateTime(profile["ExpiryDate"].ToString());
            //objUser.UserStatus = Convert.ToInt16(profile["UserStatus"].ToString());
            //objUser.Password = profile["Password"].ToString();
            //objUser.TimeZone = profile["TimeZone"].ToString();
            //objUser.PaymentStatus = profile["PaymentStatus"].ToString();
            //objUser.ActivationStatus = profile["ActivationStatus"].ToString();
            //objUser.CouponCode = profile["CouponCode"].ToString();
            //objUser.ReferenceStatus = profile["ReferenceStatus"].ToString();
            //objUser.RefereeStatus = profile["RefereeStatus"].ToString();
            //objUser.UserType = profile["UserType"].ToString(); 
            #endregion
            if (objUser.UserType != "SuperAdmin")
            {
                if (objUser != null)
                {
                    if (objUser.ActivationStatus == "1")
                    {
                        int daysremaining = 0;

                        daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                        if (daysremaining > 0)
                        {
                            Session["User"] = objUser;
                            returnmsg = "user";
                            #region Count Used Accounts
                            try
                            {
                                Session["Paid_User"] = "******";
                                Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                Session["ProfileCount"] = Convert.ToInt16(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            #endregion
                        }
                        else
                        {
                            Session["User"] = objUser;
                            Session["Paid_User"] = "******";
                            returnmsg = "unpaid";
                        }
                    }
                    else if (objUser.ActivationStatus == "2")
                    {
                        returnmsg = "User Not Exist!";
                    }
                    else
                    {
                        returnmsg = "notactivated";
                    }
                }
            }
            else
            {
                returnmsg = "SuperAdmin";
                Session["User"] = objUser;
            }
            return Content(returnmsg);
        }
        //[HttpPost]
        public async System.Threading.Tasks.Task <ActionResult> AjaxLogin(string username, string password)
        {
            Session.Clear();
            Session.RemoveAll();
            string returnmsg = string.Empty;
            User   objUser   = new User();
            string uname     = Request.QueryString["username"].ToString();
            string pass      = Request.QueryString["password"].ToString();

            Api.User.User obj       = new Api.User.User();
            string        logindata = obj.Login(uname, pass);
            string        str       = logindata.Replace("\"", string.Empty).Trim();

            if (str != "Not Exist" && !str.Equals("Email Not Exist"))
            {
                objUser = (User)(new JavaScriptSerializer().Deserialize(logindata, typeof(User)));
                FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                try
                {
                    Dictionary <string, string> re = await ac.GetTokenDictionary(username, password);

                    Session["access_token"] = re["access_token"];
                }
                catch (Exception e)
                {
                    objUser = null;

                    // Edited by Antima

                    HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                    myCookie.Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies.Add(myCookie);

                    returnmsg = "Invalid Email or Password";
                    return(Content(returnmsg));
                }
            }
            else if (str.Equals("Email Not Exist"))
            {
                returnmsg = "Sorry, " + ConfigurationManager.AppSettings["domain"] + " doesn't recognize that username.";
                return(Content(returnmsg));
            }
            else
            {
                objUser = null;

                // Edited by Antima

                HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);

                returnmsg = "Invalid Email or Password";
                return(Content(returnmsg));
            }

            #region Unused code
            //JObject profile = JObject.Parse(obj.Login(uname, pass));
            //objUser.Id = Guid.Parse(profile["Id"].ToString());
            //objUser.UserName = profile["UserName"].ToString();
            //objUser.AccountType = profile["AccountType"].ToString();
            //objUser.ProfileUrl = profile["ProfileUrl"].ToString();
            //objUser.EmailId = profile["EmailId"].ToString();
            //objUser.CreateDate = Convert.ToDateTime(profile["CreateDate"].ToString());
            //objUser.ExpiryDate = Convert.ToDateTime(profile["ExpiryDate"].ToString());
            //objUser.UserStatus = Convert.ToInt16(profile["UserStatus"].ToString());
            //objUser.Password = profile["Password"].ToString();
            //objUser.TimeZone = profile["TimeZone"].ToString();
            //objUser.PaymentStatus = profile["PaymentStatus"].ToString();
            //objUser.ActivationStatus = profile["ActivationStatus"].ToString();
            //objUser.CouponCode = profile["CouponCode"].ToString();
            //objUser.ReferenceStatus = profile["ReferenceStatus"].ToString();
            //objUser.RefereeStatus = profile["RefereeStatus"].ToString();
            //objUser.UserType = profile["UserType"].ToString();
            #endregion
            if (objUser.UserType != "SuperAdmin")
            {
                if (objUser != null)
                {
                    if (objUser.ActivationStatus == "1")
                    {
                        int daysremaining = 0;

                        daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                        if (daysremaining > 0)
                        {
                            Session["User"] = objUser;
                            returnmsg       = "user";
                            #region Count Used Accounts
                            try
                            {
                                Session["Paid_User"] = "******";
                                Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                Session["ProfileCount"] = Convert.ToInt16(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                            #endregion
                        }
                        else
                        {
                            Session["User"]      = objUser;
                            Session["Paid_User"] = "******";
                            returnmsg            = "unpaid";
                        }
                    }
                    else if (objUser.ActivationStatus == "2")
                    {
                        returnmsg = "User Not Exist!";
                    }
                    else
                    {
                        returnmsg = "notactivated";
                    }
                }
            }
            else
            {
                returnmsg       = "SuperAdmin";
                Session["User"] = objUser;
            }
            return(Content(returnmsg));
        }
        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");
        }
        //[CustomAuthorize]
        public async Task<ActionResult> Facebook(string code)
        {
            if (Session["fblogin"] != null)
            {

                if ((string)Session["fblogin"] == "fblogin")
                {
                    Session["fblogin"] = null;
                    if (String.IsNullOrEmpty(code))
                    {
                        return RedirectToAction("Index", "Index");
                    }
                    Domain.Socioboard.Domain.User objUser = (Domain.Socioboard.Domain.User)Session["User"];
                    Domain.Socioboard.Domain.User checkuserexist = (Domain.Socioboard.Domain.User)Session["User"];
                    string facebookcode = code;
                    
                    string fbloginreturn = apiobjFacebook.FacebookLogin(code);
                    string[] arrfbloginreturn = Regex.Split(fbloginreturn, "_#_");
                    objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrfbloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                    Session["AccesstokenFblogin"] = arrfbloginreturn[1];
                    Session["fblogin"] = "******";
                    try
                    {
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        FormsAuthentication.SetAuthCookie(checkuserexist.UserName, false);
                    }
                    catch (Exception e)
                    {
                        checkuserexist = null;
                    }
                    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());
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            #endregion
                        }
                        else
                        {
                            Session["Paid_User"] = "******";
                        }
                        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 ((string)Session["fblogin"] == "page")
                {
                    Session["fblogin"] = null;
                    Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();
                    List<Domain.Socioboard.Domain.AddFacebookPage> lstAddFacebookPage = new List<Domain.Socioboard.Domain.AddFacebookPage>();
                    lstAddFacebookPage = (List<Domain.Socioboard.Domain.AddFacebookPage>)(new JavaScriptSerializer().Deserialize(apiobjFacebook.GetFacebookPages(code), typeof(List<Domain.Socioboard.Domain.AddFacebookPage>)));
                    Session["fbpage"] = lstAddFacebookPage;
                    return RedirectToAction("Index", "Home", new { hint = "fbpage" });
                }
                else if ((string)Session["fblogin"] == "fbgroup")
                {
                    Session["fblogin"] = null;

                    Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();
                    List<Domain.Socioboard.Domain.AddFacebookGroup> lstAddFacebookGroup = new List<Domain.Socioboard.Domain.AddFacebookGroup>();
                    lstAddFacebookGroup = (List<Domain.Socioboard.Domain.AddFacebookGroup>)(new JavaScriptSerializer().Deserialize(apiobjFacebook.GetFacebookGroups(code), typeof(List<Domain.Socioboard.Domain.AddFacebookGroup>)));
                    Session["fbgrp"] = lstAddFacebookGroup;
                    return RedirectToAction("Index", "Home", new { hint = "fbgrp" });
                }
                else if ((string)Session["fblogin"] == "fbplugin")
                {
                    Session["fblogin"] = null;
                    if (String.IsNullOrEmpty(code))
                    {
                        return RedirectToAction("Index", "Index", new { hint = "plugin" });
                    }
                    Domain.Socioboard.Domain.User objUser = (Domain.Socioboard.Domain.User)Session["User"];
                    Domain.Socioboard.Domain.User checkuserexist = (Domain.Socioboard.Domain.User)Session["User"];
                    Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();
                    Api.User.User ApiobjUser = new Api.User.User();
                    string fbloginreturn = apiobjFacebook.FacebookLogin(code);
                    string[] arrfbloginreturn = Regex.Split(fbloginreturn, "_#_");

                    objUser = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(arrfbloginreturn[0], typeof(Domain.Socioboard.Domain.User)));
                    Session["AccesstokenFblogin"] = arrfbloginreturn[1];
                    try
                    {
                        checkuserexist = (Domain.Socioboard.Domain.User)(new JavaScriptSerializer().Deserialize(ApiobjUser.getUserInfoByEmail(objUser.EmailId.ToString()), typeof(Domain.Socioboard.Domain.User)));
                        FormsAuthentication.SetAuthCookie(checkuserexist.UserName, false);
                    }
                    catch (Exception e)
                    {
                        checkuserexist = null;
                    }
                    if (checkuserexist != null)
                    {
                        objUser = checkuserexist;
                        Session["User"] = checkuserexist;
                        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");
                    }
                    #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
                    daysremaining = 0;
                    daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                    if (daysremaining > 0)
                    {
                        Session["Paid_User"] = "******";
                    }
                    else
                    {
                        Session["Paid_User"] = "******";
                    }
                    Session["fblogin"] = "******";
                    return RedirectToAction("Index", "Home", new { hint = "plugin" });
                }
            }
            else
            {
                Domain.Socioboard.Domain.User objUser = (Domain.Socioboard.Domain.User)Session["User"];
                string facebookcode = code;
                Api.Facebook.Facebook apiobjFacebook = new Api.Facebook.Facebook();

                apiobjFacebook.Timeout = 120 * 1000;

                //string AddfacebookAccount = apiobjFacebook.AddFacebookAccount(facebookcode, objUser.Id.ToString(), Session["group"].ToString());
                string AddfacebookAccount = "";
                Domain.Socioboard.Domain.FacebookAccount objfacebookAccount = new Domain.Socioboard.Domain.FacebookAccount();
                try
                {
                    var res_addFacebook = apiobjFacebook.AddFacebookAccount(facebookcode, objUser.Id.ToString(), Session["group"].ToString());
                    AddfacebookAccount = res_addFacebook;
                    try
                    {
                        objfacebookAccount = (Domain.Socioboard.Domain.FacebookAccount)new JavaScriptSerializer().Deserialize(res_addFacebook, typeof(Domain.Socioboard.Domain.FacebookAccount));
                        AddfacebookAccount = objfacebookAccount.FbUserId;
                    }
                    catch (Exception)
                    {

                    }

                }
                catch (Exception)
                {
                    AddfacebookAccount = "issue_access_token";
                }

                if (AddfacebookAccount == "issue_access_token")
                {
                    Response.Redirect(Helper.SBUtils.GetFacebookRedirectLink());
                }
                else if (AddfacebookAccount == "Account already Exist !")
                {
                }
                else
                {
                    Session["SocialManagerInfo"] = AddfacebookAccount;

                    //To enable the Facebook Message Pop up
                    TempData["IsFacebookAccountAdded"] = 1;
                    TempData["FacebookAccount"] = objfacebookAccount;
                }
            }
            return RedirectToAction("Index", "Home");

        }
        //[HttpPost]
        public async System.Threading.Tasks.Task <ActionResult> AjaxLogin(string username, string password)
        {
            Session.Clear();
            Session.RemoveAll();
            string returnmsg = string.Empty;
            User   objUser   = new User();
            string uname     = Request.QueryString["username"].ToString();
            string pass      = Request.QueryString["password"].ToString();

            Api.User.User       obj      = new Api.User.User();
            HttpResponseMessage response = await WebApiReq.GetReq("api/ApiUser/Login?EmailId=" + uname + "&PasswordHash=" + SBUtils.MD5Hash(pass), "", "");

            if (response.IsSuccessStatusCode)
            {
                objUser = await response.Content.ReadAsAsync <Domain.Socioboard.Domain.User>();

                if (objUser != null)
                {
                    Response.Cookies.Add(FormsAuthentication.GetAuthCookie(objUser.UserName, true));
                    // FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                    Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                    try
                    {
                        Dictionary <string, string> re = await ac.GetTokenDictionary(username, SBUtils.MD5Hash(pass));

                        Session["access_token"] = re["access_token"];
                    }
                    catch (Exception e)
                    {
                        objUser = null;

                        // Edited by Antima

                        HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                        myCookie.Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies.Add(myCookie);

                        returnmsg = "Invalid Email or Password";
                        return(Content(returnmsg));
                    }

                    if (objUser != null)
                    {
                        if (objUser.ActivationStatus == "1")
                        {
                            int daysremaining = 0;

                            daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                            if (daysremaining > 0)
                            {
                                Session["User"]  = objUser;
                                Session["group"] = await SBHelper.LoadGroups(objUser.Id);

                                returnmsg = "user";
                                #region Count Used Accounts
                                try
                                {
                                    Session["Paid_User"] = "******";
                                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                                    Session["ProfileCount"] = Convert.ToInt16(apiobjSocialProfile.GetAllSocialProfilesOfUserCount(objUser.Id.ToString()).ToString());
                                    Session["TotalAccount"] = Convert.ToInt16(SBUtils.GetUserPackageProfileCount(objUser.AccountType));
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex.Message);
                                }
                                #endregion
                            }
                            else
                            {
                                Session["User"]      = objUser;
                                Session["Paid_User"] = "******";
                                returnmsg            = "unpaid";
                            }
                        }
                        else if (objUser.ActivationStatus == "2")
                        {
                            returnmsg = "User Not Exist!";
                        }
                        else
                        {
                            returnmsg = "notactivated";
                        }
                    }
                    if (objUser.UserType == "SuperAdmin")
                    {
                        returnmsg       = "SuperAdmin";
                        Session["User"] = objUser;
                    }
                }
            }
            else
            {
                objUser = null;
                HttpCookie myCookie = new HttpCookie("logininfo" + uname.Trim());
                myCookie.Expires = DateTime.Now.AddDays(-1);
                Response.Cookies.Add(myCookie);
                returnmsg = "Invalid Email or Password";
                return(Content(returnmsg));
            }
            return(Content(returnmsg));
        }
        public async System.Threading.Tasks.Task <ActionResult> AjaxPluginLogin()
        {
            Session.Clear();
            Session.RemoveAll();

            string returnmsg = string.Empty;

            string uname   = Request.Form["email"].ToString();
            string pass    = Request.Form["password"].ToString();
            User   objUser = new User();

            Api.User.User ApiUser   = new Api.User.User();
            string        logindata = ApiUser.Login(uname, pass);
            string        str       = logindata.Replace("\"", string.Empty).Trim();

            if (str != "Not Exist" && !str.Equals("Email Not Exist"))
            {
                objUser = (User)(new JavaScriptSerializer().Deserialize(logindata, typeof(User)));
                FormsAuthentication.SetAuthCookie(objUser.UserName, false);
                Socioboard.Helper.apiClientProvider ac = new Socioboard.Helper.apiClientProvider(System.Configuration.ConfigurationManager.AppSettings["ApiDomainName"] + "/token");
                try
                {
                    Dictionary <string, string> re = await ac.GetTokenDictionary(uname, SBUtils.MD5Hash(pass));

                    Session["access_token"] = re["access_token"];
                }
                catch (Exception e)
                {
                    returnmsg = "Invalid Email or Password";
                    return(Content(returnmsg));
                }
            }
            else if (str.Equals("Email Not Exist"))
            {
                returnmsg = "Sorry, " + ConfigurationManager.AppSettings["domain"] + " doesn't recognize that username.";
                return(Content(returnmsg));
            }
            else
            {
                returnmsg = "Invalid Email or Password";
                return(Content(returnmsg));
            }

            if (objUser != null)
            {
                if (objUser.ActivationStatus == "1")
                {
                    int daysremaining = 0;
                    daysremaining = (objUser.ExpiryDate.Date - DateTime.Now.Date).Days;
                    Api.SocialProfile.SocialProfile apiobjSocialProfile = new Api.SocialProfile.SocialProfile();
                    #region Count Used Accounts
                    try
                    {
                        Session["ProfileCount"] = Convert.ToInt16(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["User"]      = objUser;
                        returnmsg            = "user";
                        Session["Paid_User"] = "******";
                    }
                    else
                    {
                        Session["User"]      = objUser;
                        Session["Paid_User"] = "******";
                        returnmsg            = "unpaid";
                    }
                }
                else if (objUser.ActivationStatus == "2")
                {
                    returnmsg = "User Not Exist!";
                }
                else
                {
                    returnmsg = "notactivated";
                }
            }

            return(Content(returnmsg));
        }
Beispiel #12
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"));
        }