public RegistrationModule() : base("register") { base.Get("/{token}", (Func <dynamic, object>)(p => { var referer = AobaCore.ValidateRegistrationToken(((string)p.token).Replace(' ', '+')); if (referer == null || referer == UserModel.Overlord) { return new Response { StatusCode = HttpStatusCode.Unauthorized } } ; else { return(View["register", new { referer = referer.Username }]); } })); Post("/{token}", p => { var userInfo = this.Bind <LoginCredentialsModel>(); var token = (string)p.token; if (!string.IsNullOrWhiteSpace(token) && AobaCore.RegisterUser(userInfo, token.Replace(' ', '+'))) { return(new Response { StatusCode = HttpStatusCode.OK }); } else { return new Response { StatusCode = HttpStatusCode.Unauthorized } }; }); }
public AuthModule() : base("/auth") { Post("/login", p => { LoginCredentialsModel user = this.Bind <LoginCredentialsModel>(); if (user == null) { return new Response { StatusCode = HttpStatusCode.Unauthorized } } ; string apiKey = AobaCore.ValidateUser(user); if (apiKey == null) { return new Response { StatusCode = HttpStatusCode.Unauthorized } } ; if (user.AuthMode == AuthMode.API) { return(Response.AsJson(new { jwt = AobaCore.GetJWT(apiKey, 365) })); } else { var token = AobaCore.GetJWT(apiKey); return(new Response().WithHeader("Authorization", $"Bearer {token}").WithCookie("token", token)); } }); Get("/logout", _ => { return(new Response().WithCookie("token", "")); }); Post("/register/{token}", p => { LoginCredentialsModel user = this.Bind <LoginCredentialsModel>(); var token = (string)p.token; if (!string.IsNullOrWhiteSpace(token) && AobaCore.RegisterUser(user, token.Replace(' ', '+'))) { return(new Response { StatusCode = HttpStatusCode.OK }); } else { return new Response { StatusCode = HttpStatusCode.Unauthorized } }; }); Post("/checkuser", p => { return((AobaCore.UserExists(Request.Body.AsString())) ? new Response { StatusCode = HttpStatusCode.NotAcceptable } : new Response { StatusCode = HttpStatusCode.OK }); }); }