예제 #1
0
 public IActionResult Logged(ThisWrapper logged)
 {
     if (ModelState.IsValid)
     {
         var userInDb = dbContext.Users.FirstOrDefault(u => u.Email == logged.ThisLoginUser.Email);
         if (userInDb == null)
         {
             ModelState.AddModelError("ThisLoginUser.Email", "Invalid Email/Password");
             return(View("Signin"));
         }
         var hasher = new PasswordHasher <LoginUser>();
         var result = hasher.VerifyHashedPassword(logged.ThisLoginUser, userInDb.Password, logged.ThisLoginUser.Password);
         if (result == 0)
         {
             ModelState.AddModelError("ThisLoginUser.Email", "Invalid Email/Password");
             return(View("Signin"));
         }
         HttpContext.Session.SetInt32("UserId", userInDb.UserId);
         return(RedirectToAction("Dashboard"));
     }
     else
     {
         return(View("Signin"));
     }
 }
예제 #2
0
        public IActionResult New(ThisWrapper newUser)
        {
            Regex regex = new Regex(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$");

            if (regex.IsMatch(newUser.ThisUser.Password))
            {
                if (ModelState.IsValid)
                {
                    if (dbContext.Users.Any(u => u.Email == newUser.ThisUser.Email))
                    {
                        ModelState.AddModelError("ThisUser.Email", "Email already in use!");
                        return(View("Signin"));
                    }
                    PasswordHasher <User> Hasher = new PasswordHasher <User>();
                    newUser.ThisUser.Password = Hasher.HashPassword(newUser.ThisUser, newUser.ThisUser.Password);
                    dbContext.Add(newUser.ThisUser);
                    dbContext.SaveChanges();
                    HttpContext.Session.SetInt32("UserId", newUser.ThisUser.UserId);
                    return(RedirectToAction("Dashboard"));
                }
                else
                {
                    return(View("Signin"));
                }
            }
            else
            {
                ModelState.AddModelError("ThisUser.Password", "Password requires One Number, One Uppercase Letter and One Special Character");
                return(View("Signin"));
            }
        }
예제 #3
0
 public IActionResult Join(int sportid, ThisWrapper ThisUser)
 {
     ThisUser.Association.SportId = sportid;
     dbContext.Add(ThisUser.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("Dashboard"));
 }
예제 #4
0
 public IActionResult Joina(int sportid, ThisWrapper ThisUser)
 {
     ThisUser.Association.SportId = sportid;
     dbContext.Add(ThisUser.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("OneSport", new{ sportid = sportid }));
 }
예제 #5
0
 public IActionResult RSVP(int wedid, ThisWrapper ThisUser)
 {
     ThisUser.Association.WeddingId = wedid;
     dbContext.Add(ThisUser.Association);
     dbContext.SaveChanges();
     return(RedirectToAction("OneWedding", new { wedid = wedid }));
 }
예제 #6
0
        public IActionResult OneWedding(int wedid)
        {
            ThisWrapper vMod = new ThisWrapper();

            vMod.ThisWedding = dbContext.Weddings
                               .Include(b => b.UsersfromWedding)
                               .ThenInclude(v => v.User)
                               .FirstOrDefault(b => b.WeddingId == wedid);
            return(View(vMod));
        }
예제 #7
0
        public IActionResult OneSport(int sportid)
        {
            int?        userid = HttpContext.Session.GetInt32("UserId");
            ThisWrapper vMod   = new ThisWrapper();

            vMod.ThisSport = dbContext.Sports
                             .Include(b => b.UsersfromSport)
                             .ThenInclude(v => v.User)
                             .Include(d => d.Creator)
                             .FirstOrDefault(b => b.SportId == sportid);
            vMod.AllSports = dbContext.Sports
                             .Include(b => b.UsersfromSport)
                             .ThenInclude(v => v.User)
                             .ToList();
            vMod.ThisUser = dbContext.Users
                            .FirstOrDefault(u => u.UserId == (int)userid);
            return(View(vMod));
        }
예제 #8
0
        public IActionResult Dashboard()
        {
            int?userid = HttpContext.Session.GetInt32("UserId");

            if (userid == null)
            {
                return(View("Index"));
            }
            else
            {
                ThisWrapper vMod = new ThisWrapper();
                vMod.AllWeddings = dbContext.Weddings
                                   .Include(b => b.UsersfromWedding)
                                   .ThenInclude(v => v.User)
                                   .ToList();
                vMod.ThisUser = dbContext.Users
                                .FirstOrDefault(u => u.UserId == (int)userid);
                return(View(vMod));
            }
        }
예제 #9
0
        public IActionResult Dashboard()
        {
            int?userid = HttpContext.Session.GetInt32("UserId");

            if (userid == null)
            {
                return(View("Signin"));
            }
            else
            {
                ThisWrapper vMod = new ThisWrapper();
                vMod.AllSports = dbContext.Sports
                                 .Include(b => b.UsersfromSport)
                                 .ThenInclude(v => v.User)
                                 .Include(c => c.Creator)
                                 .ToList();
                vMod.ThisUser = dbContext.Users
                                .FirstOrDefault(u => u.UserId == (int)userid);
                return(View(vMod));
            }
        }
예제 #10
0
 public IActionResult New(ThisWrapper newUser)
 {
     if (ModelState.IsValid)
     {
         if (dbContext.Users.Any(u => u.Email == newUser.ThisUser.Email))
         {
             ModelState.AddModelError("ThisUser.Email", "Email already in use!");
             return(View("Index"));
         }
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         newUser.ThisUser.Password = Hasher.HashPassword(newUser.ThisUser, newUser.ThisUser.Password);
         dbContext.Add(newUser.ThisUser);
         dbContext.SaveChanges();
         HttpContext.Session.SetInt32("UserId", newUser.ThisUser.UserId);
         return(RedirectToAction("Dashboard"));
     }
     else
     {
         return(View("Index"));
     }
 }