Пример #1
0
        public IActionResult Index()
        {
            var name     = Logic.Logic.GetValue(Request, "name");
            var username = Logic.Logic.GetValue(Request, "username");
            var password = Logic.Logic.GetValue(Request, "password");
            var email    = Logic.Logic.GetValue(Request, "email");

            if (Logic.Logic.IsValidName(name) && Logic.Logic.IsValidUsername(username) &&
                Logic.Logic.IsValidPassword(password) && Logic.Logic.IsValidEmail(email))
            {
                if (!_userDao.Exists(email, username))
                {
                    _userDao.CreateUser(username, password, email, name);
                    _sessionDao.Login(Logic.Logic.GetSessionId(Request), username);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewData["error"] = "username or email is duplicated";
                }
            }
            else if (Request.Method == "POST")
            {
                ViewData["error"] = "a field is invalid";
            }
            return(View());
        }
        public IActionResult Index()
        {
            ViewData["isLogin"] = _sessionDao.GetUsername(Logic.Logic.GetSessionId(Request)) != null;
            var username = Logic.Logic.GetValue(Request, "username");
            var password = Logic.Logic.GetValue(Request, "password");
            var usr      = (User)_userDao.GetUserByUsernameAndPassword(username, password);

            if (usr != null)
            {
                _sessionDao.Login(Logic.Logic.GetSessionId(Request), username);
                return(RedirectToAction("Index", "Home"));
            }
            else if (Request.Method == "POST")
            {
                ViewData["error"] = "your password or username is incorrect";
            }

            return(View());
        }