Create user folder on registering
This commit is contained in:
@@ -123,6 +123,7 @@ bool read_users_file(char *file_path, Users *users) {
|
|||||||
|
|
||||||
if (line.count == 0) {
|
if (line.count == 0) {
|
||||||
noh_log(NOH_ERROR, "%s %zu: Line not in username:hash format.", file_path, i);
|
noh_log(NOH_ERROR, "%s %zu: Line not in username:hash format.", file_path, i);
|
||||||
|
noh_string_free(&users_file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +146,9 @@ bool write_users_file(char *file_path, Users *users, User *user_to_skip) {
|
|||||||
noh_string_append_cstr(&users_file, "\n");
|
noh_string_append_cstr(&users_file, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return noh_string_write_file(&users_file, file_path);
|
bool result = noh_string_write_file(&users_file, file_path);
|
||||||
|
noh_string_free(&users_file);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,6 +196,11 @@ bool register_user(Noh_String_View library_path, Noh_String_View username, Noh_S
|
|||||||
user->hash = noh_sv_from_string(hashed);
|
user->hash = noh_sv_from_string(hashed);
|
||||||
if (!write_users_file(users_file_path.elems, &users, NULL)) noh_return_defer(false);
|
if (!write_users_file(users_file_path.elems, &users, NULL)) noh_return_defer(false);
|
||||||
|
|
||||||
|
// Create user folder if needed.
|
||||||
|
Noh_String user_folder_path = build_path(false, &library_path, &username);
|
||||||
|
noh_string_append_null(&user_folder_path);
|
||||||
|
if (!noh_mkdir_if_needed(user_folder_path.elems)) noh_return_defer(false);
|
||||||
|
|
||||||
noh_return_defer(true);
|
noh_return_defer(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +209,11 @@ bool register_user(Noh_String_View library_path, Noh_String_View username, Noh_S
|
|||||||
noh_da_append(&users, ((User){ .username = username, .hash = noh_sv_from_string(hashed) }));
|
noh_da_append(&users, ((User){ .username = username, .hash = noh_sv_from_string(hashed) }));
|
||||||
if (!write_users_file(users_file_path.elems, &users, NULL)) noh_return_defer(false);
|
if (!write_users_file(users_file_path.elems, &users, NULL)) noh_return_defer(false);
|
||||||
|
|
||||||
|
// Create user folder if needed.
|
||||||
|
Noh_String user_folder_path = build_path(false, &library_path, &username);
|
||||||
|
noh_string_append_null(&user_folder_path);
|
||||||
|
if (!noh_mkdir_if_needed(user_folder_path.elems)) noh_return_defer(false);
|
||||||
|
|
||||||
defer:
|
defer:
|
||||||
noh_da_free(&users);
|
noh_da_free(&users);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user