Exemplo n.º 1
0
        public void CreateAndRemoveUser()
        {
            LoginCredentialsModel u = new LoginCredentialsModel
            {
                Username = $"Test User {Rand.Next(int.MaxValue)}",
                Password = "******"
            };
            var user = ProcrastinatorCore.CreateUser(u);

            Assert.IsNotNull(ProcrastinatorCore.ValidateUser(u));
            ProcrastinatorCore.RemoveUser(user.Id);
        }
Exemplo n.º 2
0
        public AuthModule() : base("/auth")
        {
            Post["/login"] = args =>
            {
                var login = this.Bind <LoginCredentialsModel>();
                var auth  = ProcrastinatorCore.ValidateUser(login);
                Console.WriteLine(auth);
                if (string.IsNullOrEmpty(auth))
                {
                    return new Response {
                               StatusCode = HttpStatusCode.Unauthorized
                    }
                }
                ;
                else
                {
                    return(new Response().WithCookie("Auth", auth, DateTime.Now.AddDays(5)));
                }
            };

            Get["/logout"] = _ =>
            {
                return(Response.AsRedirect("/").WithCookie("Auth", null, DateTime.Now));
            };

            Post["/register"] = _ =>
            {
                var user = this.Bind <LoginCredentialsModel>();
                ProcrastinatorCore.CreateUser(user);
                var auth = ProcrastinatorCore.ValidateUser(user);
                return(new Response().WithCookie("Auth", auth, DateTime.Now.AddDays(5)));
            };

            Post["/checkuser"] = args =>
            {
                return((ProcrastinatorCore.CheckUserExists(Request.Body.AsString())) ? new Response {
                    StatusCode = HttpStatusCode.NotAcceptable
                } : new Response {
                    StatusCode = HttpStatusCode.OK
                });
            };
        }