示例#1
0
        public IActionResult Register(RegisterUserModel registerUser)
        {
            if (registerUser.username == null)
            {
                ModelState.Remove("username");
                ModelState.Remove("password");
                ModelState.Remove("confirmPassword");

                return(View("Register"));
            }
            else
            {
                //User Db context to register user
                if (UserDatabaseContext.CheckUsername(registerUser.username))
                {
                    UserDatabaseContext.Register(registerUser);
                    User user = new User();
                    user.username = registerUser.username;

                    user.accessToken = UserDatabaseContext.GenerateAccessToken(registerUser.username);

                    HttpContext.Session.SetString("user", JsonConvert.SerializeObject(user));
                }
                else
                {
                    TempData["err"] = "Username already exists";
                    return(View("Register"));
                }
            }

            UserPassModel userPass = new UserPassModel();

            userPass.username = registerUser.username;
            userPass.password = registerUser.password;

            return(RedirectToAction("Login", userPass));
        }