Example #1
0
        public JsonResult Login(String username, String password)
        {
            // checking login

            LoginUser loginUser = new LoginUser();

            loginUser.userName = username;
            loginUser.password = password;

            var dbGodtSkodd = new DBGodtSkodd();
            var userId      = dbGodtSkodd.GetUserIdInDB(loginUser);

            //if (dbGodtSkodd.UserInDb(loginUser))
            if (userId != -1)
            {
                // yes username and password is OK
                Session["LoggedIn"] = true;
                ViewBag.LoggedIn    = true;

                Session["UserId"] = userId;

                JsonResult jsonOutput = Json(loginUser, JsonRequestBehavior.AllowGet);
                return(jsonOutput);
            }
            else
            {
                // no
                Session["LoggedIn"] = false;
                ViewBag.LoggedIn    = false;
                return(null);
            }
        }
Example #2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                var  dbGodtSkodd = new DBGodtSkodd();
                bool insertOK    = dbGodtSkodd.CreateUser(user);

                if (insertOK)
                {
                    Session["LoggedIn"] = true;
                    ViewBag.LoggedIn    = true;

                    LoginUser loginUser = new LoginUser();
                    loginUser.userName = user.userName;
                    loginUser.password = user.password;

                    Session["UserId"] = dbGodtSkodd.GetUserIdInDB(loginUser);

                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View());
        }