Exemplo n.º 1
0
 public IActionResult ProcessReg(Users inp)
 {
     if (ModelState.IsValid)
     {
         PasswordHasher <Users> Hasher = new PasswordHasher <Users>();
         inp.password = Hasher.HashPassword(inp, inp.password);
         _context.Add(inp);
         _context.SaveChanges();
         Users       check   = _context.users.SingleOrDefault(x => x.email == inp.email);
         CurrentUser newcurr = new CurrentUser();
         newcurr.id   = check.id;
         newcurr.name = check.first_name + " " + check.last_name;
         List <object> temp = new List <object>();
         temp.Add(newcurr);
         HttpContext.Session.SetObjectAsJson("curr", temp);
         return(RedirectToAction("thewall"));
     }
     else
     {
         return(View("Index"));
     }
 }
Exemplo n.º 2
0
 public IActionResult Register(User newUser)
 {
     if (ModelState.IsValid)
     {
         if (dbContext.Users.Any(u => u.Email == newUser.Email))
         {
             ModelState.AddModelError("Email",
                                      "Email already in use. Please log in.");
             return(View("Index"));
         }
         PasswordHasher <User> Hasher = new PasswordHasher <User> ();
         newUser.Password = Hasher.HashPassword(newUser, newUser.Password);
         dbContext.Users.Add(newUser);
         dbContext.SaveChanges();
         User loggedUser = dbContext.Users.FirstOrDefault((u => u.Email == newUser.Email));
         HttpContext.Session.SetInt32("logged", loggedUser.UserId);
         return(RedirectToAction("Home"));
     }
     else
     {
         return(View("Index"));
     }
 }
Exemplo n.º 3
0
        public IActionResult Users(UserVal user)
        {
            if (ModelState.IsValid)
            {
                User NewUser = new User {
                    first_name = user.first_name,
                    last_name  = user.last_name,
                    email      = user.email,
                    password   = user.password
                };

                // get from db...
                List <User> usr = _context.users.Where(userItem => userItem.email == NewUser.email).ToList();

                // check if user already exists...
                if (usr.Count > 0)
                {
                    // FIXME: need to add an error for this case...
                    // need to render view to support model binded errors...
                    return(View("Login"));
                }

                // insert to DB...
                _context.users.Add(NewUser);
                _context.SaveChanges();

                // set session... by getting the created user id...
                List <User> CurrentUser = _context.users.Where(userItem => userItem.email == NewUser.email).ToList();
                HttpContext.Session.SetString("user_name", (string)CurrentUser[0].first_name);
                HttpContext.Session.SetInt32("user_id", (int)CurrentUser[0].userid);

                return(RedirectToAction("Index"));
            }
            else
            {
                // need to render view to support model binded errors...
                return(View("Login"));
            }
        }
Exemplo n.º 4
0
        public IActionResult createMessage(MessageVal message)
        {
            int?user_id = HttpContext.Session.GetInt32("user_id");

            if (ModelState.IsValid)
            {
                Message NewMessage = new Message {
                    userid  = (int)user_id,
                    content = message.content
                };

                // insert to DB...
                _context.messages.Add(NewMessage);
                _context.SaveChanges();

                return(RedirectToAction("Dashboard", "Users"));
            }
            else
            {
                return(RedirectToAction("Dashboard", "Users"));
            }
        }
Exemplo n.º 5
0
        public IActionResult createComment(CommentVal comment)
        {
            int?user_id = HttpContext.Session.GetInt32("user_id");

            if (ModelState.IsValid)
            {
                Comment NewComment = new Comment {
                    userid    = (int)user_id,
                    messageid = comment.messageid,
                    content   = comment.content
                };
                // insert to DB...
                _context.comments.Add(NewComment);
                _context.SaveChanges();

                return(RedirectToAction("Dashboard", "Users"));
            }
            else
            {
                Console.WriteLine("Failed validation...");
                return(RedirectToAction("Dashboard", "Users"));
            }
        }