Exemplo n.º 1
0
        public ActionResult MainPage()
        {
            var viewModel = new MainPageViewModel(); //creates new mainpageviewmodel

            using (var db = new FurryEntities())
            //creating a new furryentities called db....allows access to the db
            {
                List <Profile> profiles = db.Profiles.ToList(); //grabbing all the profiles from the db

                foreach (var profile in profiles)               //goes through each profile
                {
                    var viewModelProfile = new ViewProfile
                    {
                        ProfileId     = profile.ProfileId,
                        DisplayName   = profile.DisplayName,
                        Gender        = profile.Gender,
                        GenderSeeking = profile.GenderSeeking,
                        Avatar        = profile.Avatar,
                        City          = profile.City
                    }; //creates the parameters of the view model



                    viewModel.Profiles.Add(viewModelProfile); //adds this profile to the viewmodel's list
                }
            }

            return(View(viewModel)); //returns view, passing viewmodel to it
        }
Exemplo n.º 2
0
        public ActionResult SpeedDatesList()
        {
            List <SpeedDate> speedDates;

            using (var db = new FurryEntities())
            {
                speedDates = db.SpeedDates.ToList();
            }
            return(View(speedDates));
        }
Exemplo n.º 3
0
        public ActionResult InteractiveProfile(Guid profileId)
        {
            var viewModel = new InteractiveProfileViewModel();

            using (var db = new FurryEntities())
            {
                var profile    = db.Profiles.FirstOrDefault(x => x.ProfileId == profileId);
                var shareables = db.Shareables.ToList();

                viewModel.Profile    = profile;
                viewModel.Shareables = shareables;
            }

            return(View(viewModel));
        }
Exemplo n.º 4
0
        [ValidateAntiForgeryToken]//security feature
        public ActionResult Index(AppUser input, string returnUrl = "")
        //This action is taking a post from the User... App user input
        {
            if (ModelState.IsValid)
            {
                using (var db = new FurryEntities()) //creating a new furryentities called db....allows access to the db
                {
                    var user = db.Users.FirstOrDefault(x => x.UserName == input.UserName && x.Password == input.Password);
                    //var user above is a linq statement, checking the Users table in the db and grabbingfirst or default user
                    //that matches the username and password passed in. In this case 'x' = table of database
                    if (user != null) //if it does result in a user, it's authenticated and gives a cookie.
                    {
                        var persistentCookie = input.RememberMe;

                        var ticket = new FormsAuthenticationTicket(
                            1,
                            input.UserName,
                            DateTime.Now,
                            DateTime.Now.AddMinutes(30),
                            persistentCookie,
                            user.UserId.ToString()
                            );
                        var cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                                    FormsAuthentication.Encrypt(ticket))
                        {
                            Path = FormsAuthentication.FormsCookiePath
                        };
                        if (persistentCookie)
                        {
                            cookie.Expires = ticket.Expiration;
                        }
                        Response.Cookies.Add(cookie);
                        //FormsAuthentication.SetAuthCookie(user.UserName, input.RememberMe);  removed this due to fixing auth

                        return(RedirectToAction("Index", "Home"));//routes authenticated user over to 'home index' which route to the MainPage
                    }
                }
            }
            ModelState.Remove("Password"); //removes password when not authenticated
            return(View(input));
            //if model state isinvalid, then goes back to login view passing existing input minus password
        }
Exemplo n.º 5
0
        //security check.... prevents cross-site request forgeries....stack overflow... description
        public ActionResult CreateSpeedDate(SpeedDates input)
        {
            if (ModelState.IsValid)
            {
                using (var db = new FurryEntities())
                {
                    var speedDates    = db.SpeedDates.FirstOrDefault(x => x.SpeedDateId == input.SpeedDateId);
                    var newSpeedDates = new SpeedDate();
                    if (speedDates == null)
                    {
                        newSpeedDates.SpeedDateId = Guid.NewGuid();
                        newSpeedDates.PostTime    = DateTime.Now;
                        if (input != null)
                        {
                            var cookievalue =
                                FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                            newSpeedDates.UserId      = new Guid(cookievalue.UserData);
                            newSpeedDates.Title       = input.Title;
                            newSpeedDates.Description = input.Description;
                            newSpeedDates.City        = input.City;
                            newSpeedDates.State       = input.State;
                            if (input.JsonAttributes != null)
                            {
                                newSpeedDates.JsonAttributes = input.JsonAttributes;
                            }
                        }
                        //nullable properties that may or may not have a value
                        db.SpeedDates.Add(newSpeedDates);             //adds complete 'newSpeedDate' to the table
                        db.SaveChanges();                             //saves information in db
                        return(RedirectToAction("MainPage", "Home")); //sends them straight to 'home index'
                    }
                } //closing using statement destroys db connection

                //if model state is invalid, returns to register and passes existing 'input' back
            }
            return(View(input));
        }
Exemplo n.º 6
0
        public ActionResult AppUserProfile()
        {
            var         cookievalue = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
            ViewProfile viewModel;

            using (var db = new FurryEntities())
            {
                var profile = db.Profiles.FirstOrDefault(x => x.ProfileId == new Guid(cookievalue.UserData));
                viewModel = new ViewProfile
                {
                    ProfileId      = profile.ProfileId,
                    AboutMe        = profile.AboutMe,
                    Avatar         = profile.Avatar,
                    Birthdate      = profile.Birthdate,
                    City           = profile.City,
                    Country        = profile.Country,
                    DisplayName    = profile.DisplayName,
                    Gender         = profile.Gender,
                    GenderSeeking  = profile.GenderSeeking,
                    JsonAttributes = profile.JsonAttributes,
                };
            }
            return(View(viewModel));
        }
Exemplo n.º 7
0
        public ActionResult Register(RegisterViewModel input) //'input' below is information gathered and entered in to the 'RegisterViewModel' once submitted
        {
            if (ModelState.IsValid)
            {
                using (var db = new FurryEntities())
                {
                    var user = db.Users.FirstOrDefault(x => x.UserName == input.UserName);
                    if (user == null && input.Password == input.RepeatPassword)//put password check in javascript..
                    //if user already exists, sends then this codes does not run.
                    {
                        var newUser    = new User();    //creating a new user that goes in to the db
                        var newProfile = new Profile(); //creating a profile from the info below that goes in to the db

                        newUser.UserId    = Guid.NewGuid();
                        newUser.UserName  = input.UserName;
                        newUser.Password  = input.Password;
                        newUser.EmailId   = input.UserName;//EmailId is the UserName
                        newUser.FirstName = input.FirstName;
                        //above is an entity model of 'User'


                        newProfile.AboutMe       = input.AboutMe;
                        newProfile.Birthdate     = new DateTime(input.Year, input.Month, input.Day);
                        newProfile.City          = input.City;
                        newProfile.Country       = input.Country;
                        newProfile.DisplayName   = input.DisplayName;
                        newProfile.Gender        = input.Gender.ToString();
                        newProfile.GenderSeeking = input.GenderSeeking.ToString();
                        newProfile.ProfileId     = newUser.UserId;
                        //above is an entity model of 'Profile'

                        if (input.JsonAttributes != null)
                        {
                            newProfile.JsonAttributes = input.JsonAttributes;
                        }
                        if (input.Avatar != null)
                        {
                            newProfile.Avatar = input.Avatar;
                        }
                        if (input.LastName != null)
                        {
                            newUser.LastName = input.LastName;
                        }
                        //nullable properties that may or may not have a value

                        db.Users.Add(newUser);       //adds complete 'newUser' to the Users table
                        db.Profiles.Add(newProfile); //does the same for Profiles table
                        db.SaveChanges();            //saves information in db
                        var persistentCookie = input.RememberMe;
                        var ticket           = new FormsAuthenticationTicket(
                            1,
                            input.UserName,
                            DateTime.Now,
                            DateTime.Now.AddMinutes(30),
                            persistentCookie,
                            newProfile.ProfileId.ToString()
                            );
                        var cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
                                                    FormsAuthentication.Encrypt(ticket))
                        {
                            Path = FormsAuthentication.FormsCookiePath
                        };
                        if (persistentCookie)
                        {
                            cookie.Expires = ticket.Expiration;
                        }
                        Response.Cookies.Add(cookie);



                        //FormsAuthentication.SetAuthCookie(input.UserName, input.RememberMe);//adds authentication cookie
                        return(RedirectToAction("Index", "Home"));//sends them straight to 'home index'
                    }
                }//closing using statement destroys db connection
            }
            return(View(input));//if model state is invalid, returns to register and passes existing 'input' back
        }