Skip to content

Commit fd6e6c0

Browse files
authored
Revert "undo and merge into correct branch (#27)"
This reverts commit 2144da0.
1 parent 2144da0 commit fd6e6c0

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

backend/src/handlers/user.rs

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ pub fn init_routes(cfg: &mut web::ServiceConfig) {
2626
.route(web::post().to(login)))
2727
.service(web::resource("/ban/{user}")
2828
.route(web::delete().to(ban_user)))
29-
.service(web::resource("/token/verify")
30-
.route(web::post().to(verify_token)))
31-
.service(web::resource("/token/renew")
32-
.route(web::post().to(renew_token)))
33-
.service(web::resource("/email/verify/{token}")
34-
.route(web::get().to(verify_email)))
29+
.service(web::resource("/verify/{token}")
30+
.route(web::get().to(verify_user)))
3531
);
3632
}
3733

@@ -49,11 +45,6 @@ pub struct Login {
4945
pub password: String,
5046
}
5147

52-
#[derive(Clone, Debug, Deserialize, Serialize)]
53-
pub struct Token {
54-
pub token: String,
55-
}
56-
5748
pub async fn register(req: HttpRequest, mut payload: web::Json<Register>, app_data: WebAppData) -> ServiceResult<impl Responder> {
5849
let settings = app_data.cfg.settings.read().await;
5950

@@ -187,39 +178,8 @@ pub async fn login(payload: web::Json<Login>, app_data: WebAppData) -> ServiceRe
187178
None => Err(ServiceError::WrongPasswordOrUsername)
188179
}
189180
}
190-
pub async fn verify_token(payload: web::Json<Token>, app_data: WebAppData) -> ServiceResult<impl Responder> {
191-
// verify if token is valid
192-
let _claims = app_data.auth.verify_jwt(&payload.token).await?;
193-
194-
Ok(HttpResponse::Ok().json(OkResponse {
195-
data: format!("Token is valid.")
196-
}))
197-
}
198-
199-
pub async fn renew_token(payload: web::Json<Token>, app_data: WebAppData) -> ServiceResult<impl Responder> {
200-
// verify if token is valid
201-
let claims = app_data.auth.verify_jwt(&payload.token).await?;
202-
203-
let user_compact = app_data.database.get_user_compact_from_id(claims.user.user_id).await?;
204-
205-
const ONE_WEEK_IN_SECONDS: u64 = 604_800;
206-
207-
// renew token if it is valid for less than one week
208-
let token = match claims.exp - current_time() {
209-
x if x < ONE_WEEK_IN_SECONDS => app_data.auth.sign_jwt(user_compact.clone()).await,
210-
_ => payload.token.clone()
211-
};
212-
213-
Ok(HttpResponse::Ok().json(OkResponse {
214-
data: TokenResponse {
215-
token,
216-
username: user_compact.username,
217-
admin: user_compact.administrator
218-
}
219-
}))
220-
}
221181

222-
pub async fn verify_email(req: HttpRequest, app_data: WebAppData) -> String {
182+
pub async fn verify_user(req: HttpRequest, app_data: WebAppData) -> String {
223183
let settings = app_data.cfg.settings.read().await;
224184
let token = req.match_info().get("token").unwrap();
225185

backend/src/mailer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ If this account wasn't made by you, you can ignore this email.
137137
base_url = cfg_base_url;
138138
}
139139

140-
format!("{}/user/email/verify/{}", base_url, token)
140+
format!("{}/user/verify/{}", base_url, token)
141141
}
142142
}
143143

0 commit comments

Comments
 (0)