Esempio n. 1
0
 public virtual ActionResult Authorize(string code)
 {
     if (string.IsNullOrWhiteSpace(code))
     {
         return Json("Failed to authenticate");
     }
     var api = new SharpSquare(ClientId, ClientSecret);
     string token = api.GetAccessToken(RedirectUrl, code);
     api.SetAccessToken(token);
     var user = api.GetUser();
     // todo store token to user
     using(var context = new FourWarContext())
     {
         /*
         var user = context.Users.Create();
         user.OAuthToken = token;
         user
          * */
     }
     return RedirectToAction(MVC.Home.Index());
 }
        /// <summary>
        /// Gets current authenticated user on Foursquare
        /// </summary>
        /// <param name="accessToken">access token of authenticated user</param>
        /// <returns>current User</returns>
        public FUser GetAuthenticatedUser(string accessToken)
        {
            if (string.IsNullOrEmpty(accessToken))
            {
                throw new InvalidOperationException("No user is logged in.");
            }

            // set access token for SharpSquare service
            sharpSquare.SetAccessToken(accessToken);

            User user = null;

            try
            {
                user = sharpSquare.GetUser("self");
            }
            catch (WebException webEx)
            {
                throw new InvalidOperationException("No user is logged in.", webEx);
            }

            return(TransformerHelpers.TransformToFUser(user));
        }
        public ActionResult PreencherUsuarios()
        {
            SharpSquare sharpSquare = new SharpSquare(clientId, clientSecret);
            BancoContext db = new BancoContext();
            int lastid = 13027;
            Dictionary<string, string> parametros = new Dictionary<string, string>();

            List<Banco.Models.User> lisUser = db.Users.Where(w => w.Sexo == null && w.Id > lastid).ToList();

            foreach (Banco.Models.User usuario in lisUser)
            {
                try
                {
                    FourSquare.SharpSquare.Entities.User us = new FourSquare.SharpSquare.Entities.User();
                    lastid = usuario.Id;
                    us = sharpSquare.GetUser(usuario.SquareId);
                    usuario.Sexo = us.gender;
                    usuario.countAmigos = (int)us.friends.count;
                    usuario.countCheckin = (int)us.checkins.count;
                    usuario.countTip = (int)us.tips.count;
                    usuario.cidadeNatal = us.homeCity;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    if (e.Message == "O servidor remoto retornou um erro: (403) Proibido.")
                    {
                        break;
                    }
                }
            }
            return View();
        }
Esempio n. 4
0
        public User getUserInformation(string userID)
        {
            var user = client.GetUser(userID);

            return(user);
        }