コード例 #1
0
        public IActionResult CreateWedding(Wedding wedding)
        {
            if (HttpContext.Session.GetInt32("User") == null)
            {
                return(Redirect("/login"));
            }

            wedding.UserId = (int)HttpContext.Session.GetInt32("User");

            if (ModelState.IsValid)
            {
                bool otherWed = dbContext.weddings
                                .Any(w => w.UserId == (int)HttpContext.Session.GetInt32("User"));
                if (otherWed)
                {
                    ModelState.AddModelError("Wedder1", "You already have a wedding, bub");
                    return(View("NewWedding"));
                }

                dbContext.Add(wedding);
                dbContext.SaveChanges();
                return(RedirectToAction("Dashboard"));
            }
            return(View("NewWedding"));
        }
コード例 #2
0
        public IActionResult Register(Register regUser)
        {
            if (ModelState.IsValid)
            {
                User exists = _context.Users.SingleOrDefault(user => user.Email == regUser.Email);
                if (exists != null)
                {
                    ModelState.AddModelError("Email", "An account with this email already exists!");
                    return(View("Register"));
                }
                else
                {
                    PasswordHasher <Register> Hasher = new PasswordHasher <Register>();
                    string hashed  = Hasher.HashPassword(regUser, regUser.Password);
                    User   newUser = new User
                    {
                        FirstName = regUser.FirstName,
                        LastName  = regUser.LastName,
                        Email     = regUser.Email,
                        Password  = hashed
                    };
                    _context.Add(newUser);
                    _context.SaveChanges();
                    User user = _context.Users.Where(u => u.Email == regUser.Email).SingleOrDefault();
                    HttpContext.Session.SetInt32("userId", user.UserId);
                    HttpContext.Session.SetString("name", user.FirstName + " " + user.LastName);

                    return(RedirectToAction("Dashboard", "Home"));
                }
            }
            else
            {
                return(View("Register"));
            }
        }
コード例 #3
0
        public IActionResult register(RegisterViewModel registerVM)
        {
            if (ModelState.IsValid)
            {
                //Check if user already exists
                List <User> ReturnValues = _context.Users.Where(u => u.Email.Equals(registerVM.Email)).ToList();
                foreach (var item in ReturnValues)
                {
                    if (item.Email == registerVM.Email)
                    {
                        TempData["error"] = "Email already registered. Please log-in.";
                        return(RedirectToAction("Index"));
                    }
                }
                User user = new User
                {
                    FirstName = registerVM.FirstName,
                    LastName  = registerVM.LastName,
                    Email     = registerVM.Email,
                    Password  = registerVM.Password,
                };

                //Hashed Password
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);

                //Save to DB
                _context.Add(user);
                _context.SaveChanges();

                //set userid into session
                HttpContext.Session.SetInt32("user_id", user.UserId);
                return(RedirectToAction("Home"));
            }
            return(View("Index"));
        }
コード例 #4
0
        public IActionResult RegProcess(RegisterForm sub)
        {
            if (dbContext.Users.FirstOrDefault(user => user.Email == sub.Email) != null)
            {
                ModelState.AddModelError("Email", "This email is already in use!");
            }
            if (sub.Password != sub.ConfirmPw)
            {
                ModelState.AddModelError("Password", "Passwords must match.");
            }
            if (sub.Password != null)
            {
                Regex regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)");
                Match match = regex.Match(sub.Password);
                if (!match.Success)
                {
                    ModelState.AddModelError("Password", "Password must contain an uppercase, lowercase, numeric, and special character!");
                }
            }

            if (ModelState.IsValid)
            {
                User newUser = new User();
                newUser.Name  = sub.Name;
                newUser.Email = sub.Email;

                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                newUser.PwHash = Hasher.HashPassword(newUser, sub.Password);

                System.Console.WriteLine("Id before db submit " + newUser.Id);
                dbContext.Add(newUser);
                dbContext.SaveChanges();
                HttpContext.Session.SetInt32("userID", newUser.Id);
                System.Console.WriteLine("Id after db submit " + newUser.Id);

                return(RedirectToAction("Wall", controllerName: "Home"));
            }
            else
            {
                return(View("Index"));
            }
        }
コード例 #5
0
        public IActionResult Register(User user)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.users.Any(u => u.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "Email already in use");
                    return(View("Index"));
                }
                PasswordHasher <User> hasher = new PasswordHasher <User>();
                user.Password = hasher.HashPassword(user, user.Password);

                dbContext.Add(user);
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("User", user.UserId);
                return(Redirect("/dashboard"));
            }
            return(View("Index"));
        }
コード例 #6
0
        public IActionResult Register(User user)
        {
            if (ModelState.IsValid)
            {
                var dbuser = context.Users.FirstOrDefault(u => u.Email == user.Email);
                if (context.Users.Any(u => u.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "Email already in use!");
                    return(View("Index"));
                }
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);
                context.Add(user);
                context.SaveChanges();
                HttpContext.Session.SetInt32("UserId", user.UserId);
                //

                return(RedirectToAction("Dashboard", "Activity"));
            }
            return(View("Index"));
        }
コード例 #7
0
        public IActionResult Create(ValidPlayer Player1)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <ValidPlayer> Hasher = new PasswordHasher <ValidPlayer>();
                Player1.Password = Hasher.HashPassword(Player1, Player1.Password);
                Mage    newMage    = new Mage();
                Hunter  newHunter  = new Hunter();
                Priest  newPriest  = new Priest();
                Ninja   newNinja   = new Ninja();
                Samurai newSamurai = new Samurai();
                if (Player1.Class == "mage")
                {
                    newMage.Username = Player1.Username;
                    newMage.Password = Player1.Password;
                    newMage.Class    = Player1.Class;
                    _context.Add(newMage);
                    _context.SaveChanges();
                    HttpContext.Session.SetInt32("PlayerId", newMage.PlayerId);
                }
                if (Player1.Class == "priest")
                {
                    newPriest.Username = Player1.Username;
                    newPriest.Password = Player1.Password;
                    newPriest.Class    = Player1.Class;
                    _context.Add(newPriest);
                    _context.SaveChanges();
                    HttpContext.Session.SetInt32("PlayerId", newPriest.PlayerId);
                }

                if (Player1.Class == "hunter")
                {
                    newHunter.Username = Player1.Username;
                    newHunter.Password = Player1.Password;
                    newHunter.Class    = Player1.Class;
                    _context.Add(newHunter);
                    _context.SaveChanges();
                    HttpContext.Session.SetInt32("PlayerId", newHunter.PlayerId);
                }

                if (Player1.Class == "ninja")
                {
                    newNinja.Username = Player1.Username;
                    newNinja.Password = Player1.Password;
                    newNinja.Class    = Player1.Class;
                    _context.Add(newNinja);
                    _context.SaveChanges();
                    HttpContext.Session.SetInt32("PlayerId", newNinja.PlayerId);
                }

                if (Player1.Class == "samurai")
                {
                    newSamurai.Username = Player1.Username;
                    newSamurai.Password = Player1.Password;
                    newSamurai.Class    = Player1.Class;
                    _context.Add(newSamurai);
                    _context.SaveChanges();
                    HttpContext.Session.SetInt32("PlayerId", newSamurai.PlayerId);
                }
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View("Registration"));
        }
コード例 #8
0
        public IActionResult SubmitActivity(Activ sub)
        {
            User     loggedIn = dbContext.Users.Include(user => user.plans).ThenInclude(plan => plan.Activity).Where(user => user.Id == HttpContext.Session.GetInt32("userID")).FirstOrDefault();
            DateTime startOrig;
            DateTime endOrig;

            DateTime startNew;
            DateTime endNew;

            if (sub.TimeUnit == "hours")
            {
                sub.Duration = sub.Duration / 24;
            }
            else if (sub.TimeUnit == "minutes")
            {
                sub.Duration = sub.Duration / (60 * 24);
            }
            foreach (var plan in loggedIn.plans)
            {
                startOrig = plan.Activity.Date;
                endOrig   = plan.Activity.Date + plan.Activity.Duration;

                startNew = sub.Date.Date + sub.Time;
                endNew   = sub.Date.Date + sub.Time + sub.Duration;
                System.Console.WriteLine($"**** Is new ending {endNew} before the old start {startOrig} or is the new start {startNew} after the old end {endOrig}???");
                System.Console.WriteLine("endNew.CompareTo(startOrig) < 0 " + endNew.CompareTo(startOrig));
                System.Console.WriteLine("startNew.CompareTo(endOrig) > 0 " + startNew.CompareTo(endOrig));
                if ((endNew.CompareTo(startOrig) < 0) || (startNew.CompareTo(endOrig) > 0))
                {
                    System.Console.WriteLine("pass");
                }
                else
                {
                    ModelState.AddModelError("Date", "Schedule conflict with your events!");
                }
            }
            if (sub.Date + sub.Time <= DateTime.Now)
            {
                ModelState.AddModelError("Date", "Date must be in the future!");
            }

            if (ModelState.IsValid)
            {
                dbContext.Add(sub);
                dbContext.SaveChanges();

                Plan newPlan = new Plan();
                newPlan.User             = loggedIn;
                newPlan.Activity         = sub;
                newPlan.Activity.Date    = newPlan.Activity.Date.Date + sub.Time;
                newPlan.Activity.Creator = loggedIn;
                newPlan.Activity.Guests  = new List <Plan>();
                System.Console.WriteLine(newPlan.Activity.Guests);

                dbContext.Add(newPlan);
                newPlan.Activity.Guests.Add(newPlan);
                dbContext.SaveChanges();

                return(RedirectToAction("Wall"));
            }

            return(View("New"));
        }