feat: make mastodon login a optional feature
This commit is contained in:
@@ -6,6 +6,9 @@ license = "AGPL-3.0"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[features]
|
||||||
|
mastlogin = ["url", "reqwest"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { version = "0.5.0-rc.1", features = ["json"] }
|
rocket = { version = "0.5.0-rc.1", features = ["json"] }
|
||||||
rocket_sync_db_pools = { version = "0.1.0-cr.1", features = ["diesel_postgres_pool"] }
|
rocket_sync_db_pools = { version = "0.1.0-cr.1", features = ["diesel_postgres_pool"] }
|
||||||
@@ -20,5 +23,5 @@ sha2 = "0.10.2"
|
|||||||
log = "0.4.16"
|
log = "0.4.16"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
|
|
||||||
url = "2.2.2"
|
url = { version="2.2.2",optional = true }
|
||||||
reqwest = { version = "0.11.10", features = ["json"] }
|
reqwest = { version = "0.11.10", features = ["json"], optional = true }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# hole-backend-rust v1.0.0
|
# hole-backend-rust v1.1.0
|
||||||
|
|
||||||
|
|
||||||
## 部署
|
## 部署
|
||||||
@@ -67,4 +67,4 @@ cargo run --release
|
|||||||
|
|
||||||
+ 如果你希望使用自己的登录系统,将 `/_login/` 路径交由另外的后端处理,只需最终将用户名和token写入users表,并跳转到 `/?token=<token>`。
|
+ 如果你希望使用自己的登录系统,将 `/_login/` 路径交由另外的后端处理,只需最终将用户名和token写入users表,并跳转到 `/?token=<token>`。
|
||||||
|
|
||||||
+ 如果你希望也使用闭社提供的授权来维护账号系统,使用 `https://thu.closed.social/api/v1/apps` 接口创建应用,并在.env或环境变量中填入client与secret。此操作不需要闭社账号。详情见[文档](https://docs.joinmastodon.org/client/token/#app)。
|
+ 如果你希望也使用闭社提供的授权来维护账号系统,使用 `https://thu.closed.social/api/v1/apps` 接口创建应用,并在.env或环境变量中填入client与secret。此操作不需要闭社账号。详情见[文档](https://docs.joinmastodon.org/client/token/#app)。编译运行时,增加`--features mastlogin`: `cargo run --release --features mastlogin`
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@@ -16,6 +16,7 @@ mod api;
|
|||||||
mod cache;
|
mod cache;
|
||||||
mod db_conn;
|
mod db_conn;
|
||||||
mod libs;
|
mod libs;
|
||||||
|
#[cfg(feature = "mastlogin")]
|
||||||
mod login;
|
mod login;
|
||||||
mod models;
|
mod models;
|
||||||
mod random_hasher;
|
mod random_hasher;
|
||||||
@@ -49,6 +50,7 @@ async fn main() -> Result<(), rocket::Error> {
|
|||||||
models::Post::annealing(establish_connection(), &rconn).await;
|
models::Post::annealing(establish_connection(), &rconn).await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.mount(
|
.mount(
|
||||||
"/_api/v1",
|
"/_api/v1",
|
||||||
@@ -71,7 +73,17 @@ async fn main() -> Result<(), rocket::Error> {
|
|||||||
api::vote::vote,
|
api::vote::vote,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount("/_login", routes![login::cs_login, login::cs_auth])
|
.mount(
|
||||||
|
"/_login",
|
||||||
|
#[cfg(feature = "mastlogin")]
|
||||||
|
{
|
||||||
|
routes![login::cs_login, login::cs_auth]
|
||||||
|
},
|
||||||
|
#[cfg(not(feature = "mastlogin"))]
|
||||||
|
{
|
||||||
|
[]
|
||||||
|
},
|
||||||
|
)
|
||||||
.register(
|
.register(
|
||||||
"/_api",
|
"/_api",
|
||||||
catchers![api::catch_401_error, api::catch_403_error,],
|
catchers![api::catch_401_error, api::catch_403_error,],
|
||||||
|
|||||||
Reference in New Issue
Block a user