enabled registration
This commit is contained in:
@@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
- Specify the JWT secret with the `CHATAPP_JWT_SECRET` environment variable.
|
- Specify the JWT secret with the `CHATAPP_JWT_SECRET` environment variable.
|
||||||
- Specify the server's port with the `CHATAPP_PORT` environment variable. Defaults to `8080`.
|
- Specify the server's port with the `CHATAPP_PORT` environment variable. Defaults to `8080`.
|
||||||
- To enable user registration, pass in `CHATAPP_ALLOW_REGISTRATION=true`.
|
- To disable user registration, pass in `CHATAPP_PROHIBIT_REGISTRATION=true`.
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ pub fn routes() -> Router {
|
|||||||
|
|
||||||
async fn registration_guard(req: Request, next: Next) -> Result<Response, StatusCode> {
|
async fn registration_guard(req: Request, next: Next) -> Result<Response, StatusCode> {
|
||||||
if req.uri().path() == "/register"
|
if req.uri().path() == "/register"
|
||||||
&& env::var("CHATAPP_ALLOW_REGISTRATION").map_or(true, |v| v.to_lowercase() == "false")
|
&& env::var("CHATAPP_PROHIBIT_REGISTRATION").map_or(false, |v| v.to_lowercase() == "true")
|
||||||
{
|
{
|
||||||
return Err(StatusCode::FORBIDDEN);
|
return Err(StatusCode::FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user