✨ user page + passwd
This commit is contained in:
parent
f91b4ed6da
commit
240d6cd5ce
4 changed files with 157 additions and 42 deletions
|
@ -79,7 +79,10 @@ async fn launch() -> _ {
|
|||
pages::user::login_post,
|
||||
pages::user::history_page,
|
||||
pages::index::latest_page,
|
||||
pages::index::latest_api
|
||||
pages::index::latest_api,
|
||||
pages::user::account,
|
||||
pages::user::change_password,
|
||||
pages::user::change_password_post
|
||||
],
|
||||
)
|
||||
.attach(cors)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::library::Video;
|
||||
use based::ui::components::prelude::Avatar;
|
||||
use based::ui::components::prelude::*;
|
||||
use based::ui::components::{AppBar, Card, NavBar, Shell};
|
||||
use based::ui::primitives::flex::Column;
|
||||
use based::ui::components::{NavBar, Shell};
|
||||
use based::ui::primitives::flex::Row;
|
||||
use based::ui::primitives::Optional;
|
||||
use based::ui::wrapper::HoverWrapper;
|
||||
use based::ui::{prelude::*, UIWidget};
|
||||
|
@ -33,12 +33,28 @@ pub async fn render_page(
|
|||
// TODO : profile pictures
|
||||
DropDown(
|
||||
Avatar("", &user.username).use_initials(),
|
||||
DropdownMenu(vec![DropdownMenuEntry(
|
||||
"/history",
|
||||
Padding(Text("Video History").medium())
|
||||
.x(ScreenValue::_4)
|
||||
.y(ScreenValue::_2),
|
||||
)]),
|
||||
DropdownMenu(vec![
|
||||
DropdownMenuEntry(
|
||||
"/account",
|
||||
Row(vec![
|
||||
MaterialIcon("account_circle"),
|
||||
Text("Account").medium().render(),
|
||||
])
|
||||
.gap(ScreenValue::_2)
|
||||
.items_center()
|
||||
.justify(Justify::Start),
|
||||
),
|
||||
DropdownMenuEntry(
|
||||
"/history",
|
||||
Row(vec![
|
||||
MaterialIcon("history"),
|
||||
Text("Video History").medium().render(),
|
||||
])
|
||||
.gap(ScreenValue::_2)
|
||||
.items_center()
|
||||
.justify(Justify::Start),
|
||||
),
|
||||
]),
|
||||
)
|
||||
}))
|
||||
.no_dropdown(),
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
use based::auth::csrf::CSRF;
|
||||
use based::auth::{Sessions, User};
|
||||
use based::page;
|
||||
use based::request::StringResponse;
|
||||
use based::ui::components::{Card, Shell};
|
||||
use based::ui::prelude::*;
|
||||
use based::ui::components::prelude::Avatar;
|
||||
use based::ui::components::{prelude::*, Shell};
|
||||
use based::ui::primitives::flex::Row;
|
||||
use based::ui::{prelude::*, AttrExtendable};
|
||||
use based::{auth::MaybeUser, request::RequestContext};
|
||||
use maud::{html, Render};
|
||||
use maud::{html, PreEscaped, Render};
|
||||
use rocket::http::CookieJar;
|
||||
use rocket::State;
|
||||
use rocket::{form::Form, get, http::Cookie, post, response::Redirect, FromForm};
|
||||
|
@ -82,3 +85,96 @@ pub async fn history_page(ctx: RequestContext, user: User, shell: &State<Shell>)
|
|||
|
||||
render_page(&shell, ctx, content, "History", Some(user)).await
|
||||
}
|
||||
|
||||
#[get("/account")]
|
||||
pub async fn account(ctx: RequestContext, user: User, shell: &State<Shell>) -> StringResponse {
|
||||
let content = Width(
|
||||
ScreenValue::fit,
|
||||
Margin(
|
||||
Div()
|
||||
.push(
|
||||
Row(vec![
|
||||
Avatar("", &user.username).render(),
|
||||
Text(&user.username)._2xl().bold().render(),
|
||||
])
|
||||
.gap(ScreenValue::_2),
|
||||
)
|
||||
.push(Link("/passwd", Button(Text("Change Password")))),
|
||||
)
|
||||
.top(ScreenValue::_8)
|
||||
.x(ScreenValue::auto),
|
||||
)
|
||||
.render();
|
||||
|
||||
render_page(&shell, ctx, content, "Account", Some(user)).await
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
pub struct PasswordChangeForm {
|
||||
password_old: String,
|
||||
password_new: String,
|
||||
password_new_repeat: String,
|
||||
csrf: String,
|
||||
}
|
||||
|
||||
#[post("/passwd", data = "<form>")]
|
||||
pub async fn change_password_post(form: Form<PasswordChangeForm>, user: User) -> Redirect {
|
||||
if form.password_new != form.password_new_repeat {
|
||||
return Redirect::to("/passwd");
|
||||
}
|
||||
|
||||
if !user.verify_csrf(&form.csrf).await {
|
||||
return Redirect::to("/passwd");
|
||||
}
|
||||
|
||||
user.passwd(&form.password_old, &form.password_new)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Redirect::to("/account")
|
||||
}
|
||||
|
||||
#[get("/passwd")]
|
||||
pub async fn change_password(
|
||||
ctx: RequestContext,
|
||||
user: User,
|
||||
shell: &State<Shell>,
|
||||
) -> StringResponse {
|
||||
let csrf = user.get_csrf().await.to_string();
|
||||
let form = based::ui::primitives::input::Form::new("/passwd")
|
||||
.method(FormMethod::POST)
|
||||
.add_input(
|
||||
Margin(
|
||||
Text("Change Password")
|
||||
._2xl()
|
||||
.bold()
|
||||
.align(TextAlignment::Center),
|
||||
)
|
||||
.bottom(ScreenValue::_6),
|
||||
)
|
||||
.add_input(
|
||||
TextInput("password_old")
|
||||
.password()
|
||||
.placeholder("Old Password")
|
||||
.required(),
|
||||
)
|
||||
.add_input(
|
||||
TextInput("password_new")
|
||||
.password()
|
||||
.placeholder("New Password")
|
||||
.required(),
|
||||
)
|
||||
.add_input(
|
||||
TextInput("password_new_repeat")
|
||||
.password()
|
||||
.placeholder("Repeat new password")
|
||||
.required(),
|
||||
)
|
||||
.add_input(FormSubmitButton("Change"))
|
||||
.add_input(HiddenInput("csrf", &csrf).add_attr("class", "csrf"))
|
||||
.render();
|
||||
|
||||
let content = Div().vanish().push(form).render();
|
||||
|
||||
render_page(&shell, ctx, content, "Change Password", Some(user)).await
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue