Exemplo n.º 1
0
        public void Test_login_form()
        {
            JsonServiceClient authClient = new JsonServiceClient("https://localhost:44320");
            LoginRegisterForm frm        = new LoginRegisterForm(authClient)
            {
                ShowInTaskbar = false //<-- this enable forms to show up for testing! otherwise it doesn't show.
            };
            var authResp = frm.LoginOrRegister();

            Assert.IsNotNull(authResp);
            Assert.IsNotNull(authResp.BearerToken);
        }
Exemplo n.º 2
0
        public IActionResult HandleLogin(LoginRegisterForm model)
        {
            LoginContext context =
                HttpContext.RequestServices.GetService(typeof(LoginContext)) as LoginContext;

            int userId = context.CheckCredentials(model.LoginUserEmail, model.LoginPassword);

            if (userId == 0)
            {
                return(Content("User not found or password is incorrect"));
            }
            SetCookie(userId);
            return(Content(""));
        }
Exemplo n.º 3
0
        public IActionResult HandleRegister(LoginRegisterForm model)
        {
            LoginContext context = HttpContext.RequestServices.GetService(typeof(LoginContext)) as LoginContext;

            if (model.RegisterPassword != model.RegisterPasswordCheck)
            {
                return(Content("Passwords don't match!"));
            }

            if (context.CheckEmail(model.RegisterEmail))
            {
                return(Content("Email already in use"));
            }

            string hashed = Hashing(model.RegisterPassword);
            string result = context.AddUser(model.RegisterEmail, hashed, model.RegisterUsername,
                                            model.RegisterPasswordCheck);

            int userId = context.CheckCredentials(model.RegisterEmail, model.RegisterPassword);

            SetCookie(userId);

            return(Content($"{result}"));
        }