Пример #1
0
        public ActionResult Login(Administrator user)
        {
            WebShopDb context = new WebShopDb();

            // check if user has entered the admin account
            if (user.Username == context.Administrators.FirstOrDefault().Username)
            {
                if (user.Password == context.Administrators.FirstOrDefault().Password)
                {
                    FormsAuthentication.SetAuthCookie(user.Username, true);

                    // all good - redirect the user to admin panel
                    return(RedirectToAction("Index", "Admin"));
                }
                else
                {
                    // wrong password
                    ModelState.AddModelError("WrongPW", "Wrong password. Please try again.");
                }
            }
            else
            { // username is wrong
                ModelState.AddModelError("WrongLogin", "There is no account with such details.");
            }
            return(View());
        }
Пример #2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            Database.SetInitializer(new CustInit());

            WebShopDb context = new WebShopDb();

            context.Database.Initialize(true);
        }