Esempio n. 1
0
        public AccountModule()
        {
            this.RequiresAuthentication();
            Get["/account"] = _ =>
            {
                User currentUser = UserManager.get().getUser(this.Context.CurrentUser.UserName);

                if (currentUser.FS_Token == null || currentUser.FS_Token.Trim() == "")
                {
                    return(View["account_basic", new ViewModel(this.Context, currentUser)]);
                }

                CheckinsModel checkins = FoursquareAccess.get().getCheckins(currentUser.FS_Token);
                checkins.user = currentUser;
                //checkins.count++;
                //checkins.items.Add(new CheckinModel
                //{
                //    id = "This is the ID",
                //    createdAt = ConvertToUnixTimestamp(DateTime.Now.AddDays(-4).AddHours(11).AddMinutes(20)),
                //    timeZoneOffset = -600,
                //    venue = "Smiths",
                //    type = "Shopping"
                //});

                return(View["account_adv", new ViewModel(this.Context, checkins)]);
            };
        }
        public CheckinsModel getCheckins(string FS_Token)
        {
            string url = getCheckinsUrl(FS_Token);

            Console.WriteLine("\nGetting checkins using the following URL:\n" + url);

            string checkinJson = makeRequest(url);

            Console.WriteLine("\nRaw response data for the checkings is as follows:\n" + checkinJson);

            JObject jobj = JObject.Parse(checkinJson);

            checkinJson = (jobj["response"]["checkins"]).ToString();

            CheckinsModel checkins = JsonConvert.DeserializeObject <CheckinsModel>(checkinJson);

            Console.WriteLine("\nObjects successfully converted!");

            return(checkins);
        }
Esempio n. 3
0
        public UserModule()
        {
            Get["/user/delete/{username}"] = _ =>
            {
                User toDelete = UserManager.get().getUser((string)_.username);

                // if it's not a valid user, go back home
                if (toDelete == null)
                {
                    return(View["home", new ViewModel(this.Context, null)]);
                }

                // if user is logged in, logout
                if (this.Context.CurrentUser != null &&
                    toDelete.UserName == this.Context.CurrentUser.UserName)
                {
                    this.LogoutWithoutRedirect();
                }

                UserManager.get().deleteUser(_.username);
                return(View["home", new ViewModel(this.Context, null)]);
            };

            Get["/user/{username}"] = _ =>
            {
                User selected = UserManager.get().getUser((string)_.username);

                // if it's not a valid user, go back home
                if (selected == null)
                {
                    return(View["error", new ErrorModel
                                {
                                    Message = (string)_.username + " is not a valid user.",
                                    RedirectPage = "home",
                                    RedirectURL = "/home"
                                }]);
                }

                // if user is logged in, go to the account page
                if (this.Context.CurrentUser != null &&
                    selected.UserName == this.Context.CurrentUser.UserName)
                {
                    return(Response.AsRedirect("/account"));
                }

                // if the user isn't connected to foursquare, display the basic page
                if (selected.FS_Token == null || selected.FS_Token.Trim() == "")
                {
                    return(View["user_basic", new ViewModel(this.Context, selected)]);
                }

                // otherwise display the page with a checkin
                CheckinsModel checkins = FoursquareAccess.get().getCheckins(selected.FS_Token);

                checkins.user = selected;
                //checkins.items.Add(new CheckinModel
                //{
                //    id = "This is the ID",
                //    createdAt = ConvertToUnixTimestamp(DateTime.Now.AddDays(-4).AddHours(11).AddMinutes(20)),
                //    timeZoneOffset = -600,
                //    venue = "Smiths",
                //    type = "Shopping"
                //});

                return(View["user_adv", new ViewModel(this.Context, checkins)]);
            };
        }