forked from Ruderverein-Donau-Linz/rowt
allow admin to create user
This commit is contained in:
parent
ed28a50d98
commit
f609ee1cb4
@ -7,7 +7,6 @@
|
||||
# TODO
|
||||
- [ ] Allow sign-outs only >2h before event
|
||||
- [ ] Don't allow to be a cox + rower in same trip
|
||||
- [ ] Admin create user
|
||||
|
||||
# Frontend Process
|
||||
´cd frontend´
|
||||
|
@ -89,6 +89,17 @@ impl User {
|
||||
.unwrap(); //TODO: fixme
|
||||
}
|
||||
|
||||
pub async fn create(db: &SqlitePool, name: String, is_guest: bool) -> bool {
|
||||
sqlx::query!(
|
||||
"INSERT INTO USER(name, is_guest) VALUES (?,?)",
|
||||
name,
|
||||
is_guest,
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub async fn find_by_id(db: &SqlitePool, id: i32) -> Result<Self, sqlx::Error> {
|
||||
let user: User = sqlx::query_as!(
|
||||
User,
|
||||
|
@ -57,6 +57,29 @@ async fn update(
|
||||
Flash::success(Redirect::to("/admin/user"), "Successfully updated user")
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![index, resetpw, update]
|
||||
#[derive(FromForm)]
|
||||
struct UserAddForm {
|
||||
name: String,
|
||||
is_guest: bool,
|
||||
}
|
||||
|
||||
#[post("/user/new", data = "<data>")]
|
||||
async fn create(
|
||||
db: &State<SqlitePool>,
|
||||
data: Form<UserAddForm>,
|
||||
_admin: AdminUser,
|
||||
) -> Flash<Redirect> {
|
||||
if User::create(db, data.name.clone(), data.is_guest).await {
|
||||
//TODO: fix clone() above
|
||||
Flash::success(Redirect::to("/admin/user"), "Successfully created user")
|
||||
} else {
|
||||
Flash::error(
|
||||
Redirect::to("/admin/user"),
|
||||
format!("User {} already exists", data.name),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![index, resetpw, update, create]
|
||||
}
|
||||
|
@ -4,6 +4,15 @@
|
||||
|
||||
<h1>Users</h1>
|
||||
|
||||
<form action="/admin/user/new" method="post">
|
||||
Name: <input type="text" name="name" /><br />
|
||||
Guest <input type="checkbox" name="is_guest" checked /><br />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
{% for user in users %}
|
||||
<form action="/admin/user" method="post">
|
||||
<input type="hidden" name="id" value="{{ user.id }}" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user