Exemplo n.º 1
0
        public async Task <IActionResult> Register(ParkMember pm)
        {
            if (ModelState.IsValid)
            {
                ParkMember user = new ParkMember
                {
                    FirstName  = pm.FirstName,
                    LastName   = pm.LastName,
                    Email      = pm.Email,
                    DogName    = pm.DogName,
                    DogBreed   = pm.DogBreed,
                    UserName   = pm.UserName,
                    ForumAlias = pm.ForumAlias
                };
                IdentityResult result = await userManager.CreateAsync(user, pm.Password);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Forum", "Forum"));
                }
                else
                {
                    foreach (IdentityError error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }
            return(View(pm));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Login(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                ParkMember user = await userManager.FindByNameAsync(loginModel.UserName);

                if (user != null)
                {
                    //signs out anyone that is currently logged in
                    await signInManager.SignOutAsync();

                    Microsoft.AspNetCore.Identity.SignInResult result =
                        await signInManager.PasswordSignInAsync(
                            user, loginModel.Password, false, false);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                ModelState.AddModelError(nameof(LoginModel.UserName),
                                         "Invalid user or password");
            }
            return(View(loginModel));
        }
Exemplo n.º 3
0
        //[Authorize]
        public ViewResult AddPost(ForumMessage newPost)
        {
            string ai = newPost.User.ForumAlias;

            if (string.IsNullOrEmpty(ai))
            {
                string error = "User.ForumAlias";
                ModelState.AddModelError(error, "Please enter your forum name.");
            }

            if (ModelState.IsValid)
            {
                ParkMember from = memRepo.GetMemberByName(ai);
                newPost.User = from;
                forumRepo.Update(newPost);
                //TempData["message"] = $"{from} has posted a new message";
                return(View("Forum", forumRepo.GetAllForumMessages().ToList()));
            }

            else
            {
                return(View());
            }
        }
Exemplo n.º 4
0
 //not sure what this is supposed to do
 public List <ForumMessage> GetPostsbyMember(ParkMember user)
 {
     return((from p in context.ForumMessages
             where p.User.Equals(user)
             select p).ToList());
 }
Exemplo n.º 5
0
        public static async Task EnsurePopulated(IApplicationBuilder app)
        {
            AppIdentityDbContext ident = app.ApplicationServices
                                         .GetRequiredService <AppIdentityDbContext>();
            ApplicationDbContext context = app.ApplicationServices
                                           .GetRequiredService <ApplicationDbContext>();

            //testing hard coded user
            string firstName = "Ash Cole";
            string lastName  = "Plute";
            string dogName   = "DOG";
            string dogBreed  = "Mal";
            string forumAl   = "Rhasedi";
            string userName  = "******";
            string email     = "*****@*****.**";
            string password  = "******";

            //using park member becuase it now uses the Identity class, usermanager basiclly stores the user in session
            UserManager <ParkMember> userManager = app.ApplicationServices
                                                   .GetRequiredService <UserManager <ParkMember> >();

            if (!context.ForumMessages.Any())
            {
                ParkMember user = await userManager.FindByNameAsync(userName);

                if (user == null)
                {
                    user = new ParkMember
                    {
                        FirstName  = firstName,
                        LastName   = lastName,
                        DogName    = dogName,
                        DogBreed   = dogBreed,
                        ForumAlias = forumAl,
                        UserName   = userName,
                        Email      = email
                    };

                    IdentityResult result = await userManager.CreateAsync(user, password);
                }


                ParkMember pm = new ParkMember {
                    FirstName = "Aaron", LastName = "Plute", Email = "*****@*****.**", DogName = "Ash Cole PLute", DogBreed = "Malinous Mix", ForumAlias = "Rha"
                };
                context.ParkMembers.Add(pm);
                ForumMessage post = new ForumMessage {
                    Subject = "Thief", Body = "Dont let your dog steal balls for extended periods!", Date = new DateTime(2017, 1, 12)
                };
                post.User = pm;
                context.ForumMessages.Add(post);


                post = new ForumMessage {
                    Subject = "Birthday", Body = "Ash is having a birthday party", Date = new DateTime(2017, 7, 25)
                };
                post.User = pm;
                context.ForumMessages.Add(post);
                post = new ForumMessage {
                    Subject = "Walkers", Body = " Need a good dog walker! ", Date = new DateTime(2017, 1, 15)
                };
                post.User = pm;
                context.ForumMessages.Add(post);

                pm = new ParkMember {
                    FirstName = "Jene", LastName = "Hubbard", Email = "*****@*****.**", DogName = "Webster", DogBreed = "Hound", ForumAlias = "Ka"
                };
                context.ParkMembers.Add(pm);
                post = new ForumMessage {
                    Subject = "Birthday", Body = "Webster is having a birthday party", Date = new DateTime(2017, 1, 4)
                };
                post.User = pm;
                context.ForumMessages.Add(post);

                pm = new ParkMember {
                    FirstName = "Dustin", LastName = "Smith", Email = "*****@*****.**", DogName = "Odin", DogBreed = "Shepard Mix", ForumAlias = "Nut"
                };
                context.ParkMembers.Add(pm);
                post = new ForumMessage {
                    Subject = "Walkers", Body = "Does anyone have a good dog walker for dominant dogs?", Date = new DateTime(2016, 12, 3)
                };
                post.User = pm;
                context.ForumMessages.Add(post);
                post = new ForumMessage {
                    Subject = "Thief", Body = "Ok the theiving has gotten bad", Date = new DateTime(2017, 1, 12)
                };
                post.User = pm;
                context.ForumMessages.Add(post);


                context.SaveChanges();
            }
        }