mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
server (/auth/register): create directory for user files
This commit is contained in:
parent
cdc185c4d8
commit
1df16a3169
4 changed files with 16 additions and 6 deletions
|
@ -18,8 +18,8 @@ pub async fn handle(
|
|||
let user = User::new(&request.username, &request.password);
|
||||
|
||||
let response = match db.find_user(&user.username, &user.password).await {
|
||||
Ok(res) => {
|
||||
let token = create_token(res, config.jwt.secret.as_bytes(), config.jwt.expires)?;
|
||||
Ok(user) => {
|
||||
let token = create_token(&user, config.jwt.secret.as_bytes(), config.jwt.expires)?;
|
||||
|
||||
Response::LoggedIn {
|
||||
access_token: token,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::fs;
|
||||
|
||||
use axum::{extract::rejection::JsonRejection, Extension, Json};
|
||||
use homedisk_database::{Database, User};
|
||||
use homedisk_types::{
|
||||
|
@ -34,7 +36,7 @@ pub async fn handle(
|
|||
|
||||
let response = match db.create_user(&user).await {
|
||||
Ok(_) => {
|
||||
let token = create_token(user, config.jwt.secret.as_bytes(), config.jwt.expires)?;
|
||||
let token = create_token(&user, config.jwt.secret.as_bytes(), config.jwt.expires)?;
|
||||
|
||||
Response::LoggedIn {
|
||||
access_token: token,
|
||||
|
@ -52,5 +54,13 @@ pub async fn handle(
|
|||
}
|
||||
};
|
||||
|
||||
// create directory for user files
|
||||
let user_dir = format!(
|
||||
"{storage}/{username}",
|
||||
storage = config.storage.path,
|
||||
username = user.username,
|
||||
);
|
||||
fs::create_dir_all(&user_dir).unwrap();
|
||||
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub async fn handle(
|
|||
}
|
||||
|
||||
// write file
|
||||
fs::write(&path, content)
|
||||
fs::write(&path, &content)
|
||||
.map_err(|err| ServerError::FsError(FsError::WriteFile(err.to_string())))?;
|
||||
|
||||
Response { uploaded: true }
|
||||
|
|
|
@ -2,8 +2,8 @@ use homedisk_database::User;
|
|||
use homedisk_types::errors::{AuthError, ServerError};
|
||||
use rust_utilities::crypto::jsonwebtoken::{Claims, Token};
|
||||
|
||||
pub fn create_token(user: User, secret: &[u8], expires: i64) -> Result<String, ServerError> {
|
||||
let token = Token::new(secret, Claims::new(user.id, expires));
|
||||
pub fn create_token(user: &User, secret: &[u8], expires: i64) -> Result<String, ServerError> {
|
||||
let token = Token::new(secret, Claims::new(user.id.clone(), expires));
|
||||
|
||||
match token {
|
||||
Ok(token) => Ok(token.encoded),
|
||||
|
|
Loading…
Reference in a new issue