Browse Source

feat: make mastodon login a optional feature

master v1.1.0
hole-thu 3 years ago
parent
commit
7c024bfd6b
  1. 7
      Cargo.toml
  2. 4
      README.md
  3. 14
      src/main.rs

7
Cargo.toml

@ -6,6 +6,9 @@ license = "AGPL-3.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
mastlogin = ["url", "reqwest"]
[dependencies]
rocket = { version = "0.5.0-rc.1", features = ["json"] }
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"
env_logger = "0.9.0"
url = "2.2.2"
reqwest = { version = "0.11.10", features = ["json"] }
url = { version="2.2.2",optional = true }
reqwest = { version = "0.11.10", features = ["json"], optional = true }

4
README.md

@ -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>`
+ 如果你希望也使用闭社提供的授权来维护账号系统,使用 `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

@ -16,6 +16,7 @@ mod api;
mod cache;
mod db_conn;
mod libs;
#[cfg(feature = "mastlogin")]
mod login;
mod models;
mod random_hasher;
@ -49,6 +50,7 @@ async fn main() -> Result<(), rocket::Error> {
models::Post::annealing(establish_connection(), &rconn).await;
}
});
rocket::build()
.mount(
"/_api/v1",
@ -71,7 +73,17 @@ async fn main() -> Result<(), rocket::Error> {
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(
"/_api",
catchers![api::catch_401_error, api::catch_403_error,],

Loading…
Cancel
Save