Can update user information

This commit is contained in:
Pierre HUBERT 2022-04-08 16:28:19 +02:00
parent 91817bd2a4
commit 65dac1e923
3 changed files with 35 additions and 2 deletions

View File

@ -139,3 +139,32 @@ pub async fn create_user(user: CurrentUser, clients: web::Data<ClientManager>) -
clients: clients.cloned(),
}.render().unwrap())
}
#[derive(serde::Deserialize)]
pub struct EditUserQuery {
id: UserID,
}
pub async fn edit_user(user: CurrentUser,
clients: web::Data<ClientManager>,
users: web::Data<Addr<UsersActor>>,
query: web::Query<EditUserQuery>,
) -> impl Responder {
let edited_account = users.send(users_actor::GetUserRequest(query.0.id))
.await.unwrap().0;
HttpResponse::Ok().body(EditUserTemplate {
_parent: BaseSettingsPage::get(
"Edit user account",
user.deref(),
match edited_account.is_none() {
true => Some("Could not find requested user!".to_string()),
false => None
},
None,
),
u: edited_account.unwrap_or_default(),
clients: clients.cloned(),
}.render().unwrap())
}

View File

@ -118,6 +118,7 @@ async fn main() -> std::io::Result<()> {
.route("/admin/users", web::get().to(admin_controller::users_route))
.route("/admin/users", web::post().to(admin_controller::users_route))
.route("/admin/create_user", web::get().to(admin_controller::create_user))
.route("/admin/edit_user", web::get().to(admin_controller::edit_user))
// Admin API
.route("/admin/api/find_username", web::post().to(admin_api::find_username))

View File

@ -26,7 +26,10 @@
<td>{{ u.email }}</td>
<td>{% if u.admin %}Admin{% else %}Regular user{% endif %}</td>
<td>{% if u.enabled %}Enabled{% else %}Disabled{% endif %}</td>
<td>Edit Delete</td>
<td>
<a href="/admin/edit_user?id={{ u.uid }}">Edit</a>
Delete
</td>
</tr>
{% endfor %}
</tbody>