Ejemplo n.º 1
0
        public ActionResult Index(long? facebookId = null, string oAuthToken = "")
        {
            SignedRequest signedRequest;

            if (facebookId.HasValue && !string.IsNullOrEmpty(oAuthToken))
            {
                signedRequest = new SignedRequest()
                {
                    OauthToken = oAuthToken,
                    UserId = facebookId.Value
                };
            }
            else
            {
                signedRequest = this.FacebookInit();
            }

            if (signedRequest == null || signedRequest.UserId == 0)
            {
                signedRequest = new SignedRequest { UserId = 0, OauthToken = "0" };
            }
            else
            {
                MovieDatabase.DataAccess.DataContext.Models.User user = UserService.GetUser(signedRequest.UserId);

                if (user == null)
                {
                    FacebookClient fb = new FacebookClient(signedRequest.OauthToken);
                    string requestForUserInformation = String.Format("{0}?fields=name,picture", signedRequest.UserId);
                    dynamic responseForProfileImage = fb.Get(requestForUserInformation);

                    UserService.AddUser(signedRequest.UserId, responseForProfileImage.picture.data.url, responseForProfileImage.name);
                }
                else
                {
                    UserService.UpdateUserLastVisit(user);
                }
            }

            return RedirectToAction("Index", "Home", new { facebookId = signedRequest.UserId, oAuthToken = signedRequest.OauthToken });
        }
Ejemplo n.º 2
0
 private SignedRequest MockUser()
 {
     SignedRequest signedRequest = new SignedRequest { UserId = DateTime.UtcNow.Ticks, OauthToken = DateTime.UtcNow.Ticks.ToString() };
     return signedRequest;
 }