public ActionResult Friends()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }

            string          token           = GetCurrentUserToken();
            FoursquareOAuth foursquareOAuth = new FoursquareOAuth(token);
            List <int>      friends         = foursquareOAuth.GetFriends();
            List <String>   names           = new List <string>();

            for (int i = 0; i < friends.Count; ++i)
            {
                if (Membership.GetUser(friends[i].ToString()) == null)
                {
                    friends.RemoveAt(i);
                    i--;
                }
                else
                {
                    NameValueCollection tmp;
                    tmp = GetProfileInfo(friends[i]);
                    names.Add(tmp["firstname"]);
                }
            }

            ViewBag.users = friends;
            ViewBag.names = names;
            return(View("NearbyUsers"));
        }
        public ActionResult RandomChat(int radius, string gender)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }
            String          token           = GetCurrentUserToken();
            FoursquareOAuth foursquareOAuth = new FoursquareOAuth(token);
            List <int>      users           = foursquareOAuth.GetNearByUsers(radius);

            if (Convert.ToBoolean(GetProfileInfo(Convert.ToInt32(User.Identity.Name))["isPremium"]) && gender != null)
            {
                for (int i = 0; i < users.Count; ++i)
                {
                    NameValueCollection nv = GetProfileInfo(users[i]);
                    if (gender != nv["gender"])
                    {
                        users.RemoveAt(i--);
                    }
                }
            }
            if (users.Count == 0)
            {
                ViewBag.error = "Sorry. Nobody to chat";

                return(View("CustomError"));
            }
            Random random = new Random();
            int    pos    = random.Next(0, users.Count);

            return(RedirectToAction("Chat", new { id = users[pos] }));
        }
        public ActionResult NearbyVenues(int maxRadius)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }

            FoursquareUserContext foursquareUserContext = new FoursquareUserContext();
            //TODO maybe change to premium warning notification
            int userId = Convert.ToInt32(User.Identity.Name);
            FoursquareUserModel user =
                foursquareUserContext.FoursquareUsers.
                First(x => x.FoursquareUserId == userId);

            int premiumRadius = Convert.ToInt32(ConfigurationManager.AppSettings["PremiumRadius"]);

            if (!user.IsPremium && premiumRadius < maxRadius)
            {
                maxRadius = premiumRadius;
            }

            string token = GetCurrentUserToken();

            logger.Debug("Got token " + token);
            Logic.FoursquareOAuth FSQOAuth = new FoursquareOAuth(token);



            List <string> res = FSQOAuth.GetNearbyVenues(maxRadius);


            logger.Debug("Got venues " + res.Count);
            List <FoursquareOAuth.Venue> venues = new List <FoursquareOAuth.Venue>();

            if (res.Count == 0)
            {
                ViewBag.venues = null;
                return(View());
            }
            try
            {
                foreach (var re in res)
                {
                    venues.Add(FSQOAuth.GetVenuesInfo(re));
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }
            logger.Debug("Got venues info");
            ViewBag.venues = venues;
            return(View());
        }
        public bool GetApproveFriend(string token, string userId, string targetId)
        {
            int uId = Convert.ToInt32(userId);
            int tId = Convert.ToInt32(targetId);

            if (AuthService.ValidateAuthData(uId, token))
            {
                FoursquareOAuth foursquareOAuth = new FoursquareOAuth(token);
                return(foursquareOAuth.ApproveFriendship(tId));
            }
            return(false);
        }
        public Profile GetMyProfile(string userId, string token)
        {
            int uId = Convert.ToInt32(userId);

            if (AuthService.ValidateAuthData(uId, token))
            {
                FoursquareOAuth fsqOAuth = new FoursquareOAuth(token);
                Profile         res      = fsqOAuth.GetProfileInfo(uId);
                return(res);
            }
            return(null);
        }
        public ActionResult Chat(int id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }
            ViewBag.to = id;
            FoursquareOAuth foursquareOAuth = new FoursquareOAuth(GetCurrentUserToken());
            bool            isFriend        = foursquareOAuth.CheckForFriendship(id);

            ViewBag.isFriend = isFriend;
            ViewBag.token    = GetCurrentUserToken();
            return(View());
        }
        public NameValueCollection GetProfileInfo(int targetId)
        {
            string token = GetCurrentUserToken();

            Logic.FoursquareOAuth FSQOAuth = new FoursquareOAuth(token);
            Profile pf = FSQOAuth.GetProfileInfo(targetId);

            Models.FoursquareUserContext db = new FoursquareUserContext();
            int userID             = FSQOAuth.GetUserId();
            FoursquareUserModel um = db.FoursquareUsers.Find(userID);
            NameValueCollection nv = pf.getInfo(um.IsPremium);

            nv["isPremium"] = um.IsPremium.ToString();
            return(nv);
        }
        public ActionResult NearbyUsers()
        {
            //TODO redirect to Friends
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }
            string token = GetCurrentUserToken();

            Logic.FoursquareOAuth             FSQOAuth        = new FoursquareOAuth(token);
            Models.FoursquareUserContext      db              = new FoursquareUserContext();
            IEnumerable <FoursquareUserModel> foursquareUsers = db.FoursquareUsers;

            foreach (var foursquareUserModel in foursquareUsers)
            {
                Logic.FoursquareOAuth tmp = new FoursquareOAuth(foursquareUserModel.Token);
                foursquareUserModel.LastVenueID = tmp.GetLastVenue();
                UpdateModel(foursquareUserModel);


                logger.Debug("Got last venue " + foursquareUserModel.FoursquareUserId);
            }
            db.SaveChanges();
            logger.Debug("Got all venues");

            List <int> res = FSQOAuth.GetNearByUsers(1000);

            logger.Debug("got nearby users");
            List <string> names = new List <string>();

            for (int i = 0; i < res.Count; ++i)
            {
                NameValueCollection tmp;
                if (res[i] != null)
                {
                    tmp = GetProfileInfo(res[i]);
                    names.Add(tmp["firstname"]);
                }
                else
                {
                    res.Remove(i);
                }
            }
            logger.Debug("got profile info");
            ViewBag.users = res;
            ViewBag.names = names;
            return(View());
        }
        public Profile GetProfile(string userId, string token, string targetId)
        {
            int uId = Convert.ToInt32(userId);
            int tId = Convert.ToInt32(targetId);

            if (AuthService.ValidateAuthData(uId, token))
            {
                FoursquareUserContext dbContext  = new FoursquareUserContext();
                IMessageRepository    repository = new MessageRepository(dbContext);
                FoursquareOAuth       fsqOAuth   = new FoursquareOAuth(token);
                if (fsqOAuth.CheckForFriendship(tId))
                {
                    Profile res = fsqOAuth.GetProfileInfo(tId);
                    return(res);
                }
            }
            return(null);
        }
示例#10
0
 public ActionResult Login()
 {
     if (!User.Identity.IsAuthenticated)
     {
         return(RedirectToAction("Authenticate"));
     }
     Models.FoursquareUserContext fsqDBContext = new FoursquareUserContext();
     Models.FoursquareUserModel   fsqUser      = fsqDBContext.FoursquareUsers.Find(Convert.ToInt32(User.Identity.Name));
     Logic.FoursquareOAuth        FSQOAuth     = new FoursquareOAuth(fsqUser.Token);
     try
     {
         FSQOAuth.GetUserId();
         return(RedirectToAction("Index", "Foursquare"));
     }
     catch (WebException)
     {
         return(RedirectToAction("Authenticate"));
     }
 }
示例#11
0
        public ActionResult Index()
        {
            if (Request["targetID"] == null)
            {
                return(HttpNotFound());
            }
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }
            int             targetId        = Convert.ToInt32(Request["targetID"]);
            FoursquareOAuth foursquareOAuth = new FoursquareOAuth(GetCurrentUserToken());

            if (targetId == Convert.ToInt32(User.Identity.Name) || foursquareOAuth.CheckForFriendship(targetId))
            {
                ViewBag.profile = GetProfileInfo(targetId);
                ViewBag.token   = GetCurrentUserToken();
                return(View());
            }
            return(RedirectToAction("Index", "Foursquare"));
        }
示例#12
0
        public ActionResult MakeFriends(int id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "FoursquareLogin"));
            }

            FoursquareOAuth foursquareOAuth = new FoursquareOAuth(GetCurrentUserToken());

            foursquareOAuth.MakeFriendship(id);
            MessageModel messageModel = new MessageModel()
            {
                From    = Convert.ToInt32(User.Identity.Name),
                Message = "Accept",
                time    = DateTime.Now,
                To      = id,
                type    = "Invite"
            };
            IMessageRepository repository = new MessageRepository(new FoursquareUserContext());

            repository.InsertMessage(messageModel);
            repository.Save();
            return(RedirectToAction("Chat", "Foursquare", new { id = id }));
        }
示例#13
0
        public bool GetMakeFriends(string token, string userId, string targetId)
        {
            int uId = Convert.ToInt32(userId);
            int tId = Convert.ToInt32(targetId);

            if (AuthService.ValidateAuthData(uId, token))
            {
                FoursquareOAuth foursquareOAuth = new FoursquareOAuth(token);

                MessageModel messageModel = new MessageModel()
                {
                    From    = uId,
                    Message = "Accept",
                    time    = DateTime.Now,
                    To      = tId,
                    type    = "Invite"
                };
                IMessageRepository repository = new MessageRepository(new FoursquareUserContext());
                repository.InsertMessage(messageModel);
                repository.Save();
                return(foursquareOAuth.MakeFriendship(tId));
            }
            return(false);
        }
示例#14
0
 private void InitializeOauth(string token)
 {
     foursquareOAuth = new FoursquareOAuth(token);
 }