Exemple #1
0
        //returns view with recipe posted by the signed in user
        public IActionResult MyRecipes()
        {
            bool SignedIn = true;
            User user     = new User();

            Utilities.UserToView(this, ref SignedIn, ref user);

            if (!SignedIn)
            {
                return(RedirectToAction("Index", "Home"));
            }

            user = AuthenticationHandler.GetDatabaseInstance(user);
            List <Recipe> recipes = context.Recipes.Where(r => r.Username == user.Username).ToList();

            return(View(recipes));
        }
        public IActionResult SignIn(User user)
        {
            bool SignedIn = true;

            Utilities.UserToView(this, ref SignedIn);

            if (SignedIn)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (AuthenticationHandler.UserExists(user))
            {
                if (AuthenticationHandler.PassedSignin(user))
                {
                    if (!AuthenticationHandler.UserSignedIn(user))
                    {
                        User dbInstance = AuthenticationHandler.GetDatabaseInstance(user);
                        AuthenticationHandler.SignIn(HttpContext.Session, dbInstance);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", $"User {user.Username} is signed in on annother device.");
                    }
                }
                else
                {
                    ModelState.AddModelError("Password", $"Password is incorrect");
                }
            }
            else
            {
                ModelState.AddModelError("UserName", $"User {user.Username} does not exist.");
            }
            return(View(user));
        }