예제 #1
0
        //Route to process registration
        public IActionResult Register(PetOwnerRegistration freshRegistration)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <PetOwner> hasher = new PasswordHasher <PetOwner>();
                PetOwner newPetOwner             = new PetOwner { //Transfer of ViewModel to Db Model
                    Name           = freshRegistration.Name,
                    Email          = freshRegistration.Email,
                    Password       = freshRegistration.Password,
                    CountryId      = freshRegistration.CountryId,
                    EnrollmentDate = DateTime.Now,
                    Active         = true
                };
                newPetOwner.Password = hasher.HashPassword(newPetOwner, newPetOwner.Password);
                _context.Add(newPetOwner);
                _context.SaveChanges();
                int userId = _context.petowner.Single(u => u.Email == newPetOwner.Email).Id;
                HttpContext.Session.SetInt32("activeUser", userId);
                return(RedirectToAction("Dashboard"));
            }
            PetOwnerRegistration regForm = new PetOwnerRegistration();//This process to re-render Index page with errors

            regForm.AllCountries = _context.country.ToList();
            ViewBag.RegForm      = regForm;
            ViewBag.RegErrors    = true;//Allows for registration form to appear correctly in this scenario
            return(View("Index"));
        }
예제 #2
0
        //Route to show the Login/Reg page
        public IActionResult Index()
        {
            PetOwnerRegistration regForm = new PetOwnerRegistration();

            regForm.AllCountries = _context.country.ToList(); //List of countries to populate the drop-down menu on the registration page
            ViewBag.RegForm      = regForm;                   //Needed to bring the PetOwnerRegistration model to the registration partial page
            return(View());
        }
예제 #3
0
        //Route to process login attempt
        public IActionResult Login(PetOwnerLogin loginAttempt)
        {
            if (ModelState.IsValid)
            {
                int userId = _context.petowner.Single(u => u.Email == loginAttempt.LoginEmail).Id;
                HttpContext.Session.SetInt32("activeUser", userId);
                return(RedirectToAction("Dashboard"));
            }
            PetOwnerRegistration regForm = new PetOwnerRegistration();//This process to re-render Index page with errors

            regForm.AllCountries = _context.country.ToList();
            ViewBag.RegForm      = regForm;
            return(View("Index"));
        }