コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            oAuthToken objToken = new oAuthToken();
            GplusHelper objGpHelper = new GplusHelper();
            string objRefresh= objToken.GetRefreshToken(Request.QueryString["code"]);

            if (!objRefresh.StartsWith("["))
                objRefresh = "[" + objRefresh + "]";
            JArray objArray= JArray.Parse(objRefresh);
            User user=(User)Session["LoggedUser"];
            foreach (var item in objArray)
            {
               //string objAccess = objToken.GetAccessToken(item["refresh_token"].ToString());
                //if (!objAccess.StartsWith("["))
                //    objAccess = "[" + objAccess + "]";
                //JArray objArrayAccess = JArray.Parse(objAccess);
             //   objGpHelper.GetUerProfile(item["access_token"].ToString(), item["refresh_token"].ToString(), user.Id);

            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            oAuthToken objToken = new oAuthToken();
            GplusHelper objGpHelper = new GplusHelper();
            UserRepository objUserRepo = new UserRepository();
            PeopleController obj = new PeopleController();
            GooglePlusAccount objgpAcc = new GooglePlusAccount();
            User user = new User();
            try
            {
                string objRefresh = objToken.GetRefreshToken(Request.QueryString["code"]);
                if (!objRefresh.StartsWith("["))
                    objRefresh = "[" + objRefresh + "]";
                JArray objArray = JArray.Parse(objRefresh);
                if (Session["login"] != null)
                {
                    if (Session["login"].ToString() == "googleplus")
                    {
                        user = new User();
                        user.CreateDate = DateTime.Now;
                        user.ExpiryDate = DateTime.Now.AddMonths(1);
                        user.Id = Guid.NewGuid();
                        user.PaymentStatus = "unpaid";
                    }

                }
                else
                {
                    /*User class in SocioBoard.Domain to check authenticated user*/
                    user = (User)Session["LoggedUser"];
                }
                foreach (var item in objArray)
                {
                    try
                    {
                        JArray objEmail = objToken.GetUserInfo("me", item["access_token"].ToString());
                        JArray objProfile = obj.GetPeopleProfile("me", item["access_token"].ToString());
                        // user = (User)HttpContext.Current.Session["LoggedUser"];
                        foreach (var itemEmail in objEmail)
                        {
                            objgpAcc.EmailId = itemEmail["email"].ToString();

                        }
                        foreach (var itemProfile in objProfile)
                        {
                            objgpAcc.GpUserId = itemProfile["id"].ToString();
                            objgpAcc.AccessToken = item["access_token"].ToString();
                            objgpAcc.EntryDate = DateTime.Now;
                            objgpAcc.GpProfileImage = itemProfile["image"]["url"].ToString();
                            objgpAcc.GpUserName = itemProfile["displayName"].ToString();
                            objgpAcc.Id =Guid.NewGuid();
                            objgpAcc.IsActive = 1;
                            objgpAcc.RefreshToken = item["refresh_token"].ToString();
                            objgpAcc.UserId = user.Id;

                        }

                        if (Session["login"] != null)
                        {
                            if (string.IsNullOrEmpty(user.Password))
                            {
                                if (Session["login"].ToString() == "googleplus")
                                {
                                    if (objUserRepo.IsUserExist(user.EmailId))
                                    {
                                        // user = null;
                                        user = objUserRepo.getUserInfoByEmail(user.EmailId);
                                    }
                                    else
                                    {
                                        user.EmailId = objgpAcc.EmailId;
                                        user.UserName = objgpAcc.GpUserName;
                                        user.ProfileUrl = objgpAcc.GpProfileImage;
                                        UserRepository.Add(user);
                                    }
                                    Session["LoggedUser"] = user;
                                    objgpAcc.UserId = user.Id;
                                }
                            }
                        }
                        objGpHelper.GetUerProfile(objgpAcc, item["access_token"].ToString(), item["refresh_token"].ToString(), user.Id);

                        if (Session["login"] != null)
                        {
                            if (string.IsNullOrEmpty(user.Password))
                            {
                                if (Session["login"].ToString() == "googleplus")
                                {
                                    Response.Redirect("Plans.aspx");
                                }
                            }
                            else
                            {
                                Response.Redirect("Home.aspx");
                            }
                        }
                        else
                        {
                            Response.Redirect("Home.aspx");
                        }

                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                        Response.Redirect("Home.aspx");
                    }
                }

            }
            catch (Exception Err)
            {
                Console.Write(Err.Message.ToString());
                logger.Error(Err.StackTrace);
                Response.Redirect("Home.aspx");
            }
        }