Example #1
0
        public FoursquareModule()
        {
            this.RequiresAuthentication();
            this.RequiresHttps();

            Get["/foursquare"]         = _ => View["foursquare", new ViewModel(this.Context, null)];
            Get["/foursquare/connect"] = _ =>
            {
                string url = FoursquareAccess.get().getAuthenticateUrl();

                Console.WriteLine("\nFirst connection to Foursquare using this URL:\n" + url);

                return(this.Response.AsRedirect(url));
            };

            Get["/foursquare/code"] = _ =>
            {
                string code = (string)this.Request.Query["code"];

                string token = FoursquareAccess.get().getAccessToken(code);

                // add it to the user
                string currentUsername = this.Context.CurrentUser.UserName;
                UserManager.get().assignToken(currentUsername, token);

                return(this.Response.AsRedirect("/account"));
            };
        }
Example #2
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)]);
            };
        }
Example #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)]);
            };
        }