aboutsummaryrefslogtreecommitdiff
path: root/ui/src/account/mod.rs
blob: 91202b0f6aa70cb486492a28b7a14369718ec2b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2025 metamuffin <metamuffin.org>
*/
pub mod settings;

use crate::{
    Page,
    locale::{Language, tr, trs},
};
use jellycommon::routes::{u_account_login, u_account_register};

impl Page for AccountLogin<'_> {
    fn title(&self) -> String {
        tr(
            *self.lang,
            if self.logged_in {
                "account.login.switch"
            } else {
                "account.login"
            },
        )
        .to_string()
    }

    fn to_render(&self) -> markup::DynRender<'_> {
        markup::new!(@self)
    }
}
impl Page for AccountRegister<'_> {
    fn title(&self) -> String {
        tr(*self.lang, "account.register").to_string()
    }
    fn to_render(&self) -> markup::DynRender<'_> {
        markup::new!(@self)
    }
}
impl Page for AccountRegisterSuccess<'_> {
    fn title(&self) -> String {
        tr(*self.lang, "account.register").to_string()
    }
    fn to_render(&self) -> markup::DynRender<'_> {
        markup::new!(@self)
    }
}
impl Page for AccountLogout<'_> {
    fn title(&self) -> String {
        tr(*self.lang, "account.logout").to_string()
    }
    fn to_render(&self) -> markup::DynRender<'_> {
        markup::new!(@self)
    }
}

markup::define! {
    AccountRegister<'a>(lang: &'a Language) {
        form.account[method="POST", action=""] {
            h1 { @trs(&lang, "account.register") }

            label[for="inp-invitation"] { @trs(&lang, "account.register.invitation") }
            input[type="text", id="inp-invitation", name="invitation"]; br;

            label[for="inp-username"] { @trs(&lang, "account.username") }
            input[type="text", id="inp-username", name="username"]; br;
            label[for="inp-password"] { @trs(&lang, "account.password") }
            input[type="password", id="inp-password", name="password"]; br;

            input[type="submit", value=&*tr(**lang, "account.register.submit")];

            p { @trs(&lang, "account.register.login") " " a[href=u_account_login()] { @trs(&lang, "account.register.login_here") } }
        }
    }
    AccountRegisterSuccess<'a>(lang: &'a Language, logged_in: bool) {
        h1 { @trs(&lang, if *logged_in {
            "account.register.success.switch"
        } else {
            "account.register.success"
        })}
    }
    AccountLogin<'a>(lang: &'a Language, logged_in: bool) {
        form.account[method="POST", action=""] {
            h1 { @self.title() }

            label[for="inp-username"] { @trs(&lang, "account.username") }
            input[type="text", id="inp-username", name="username"]; br;
            label[for="inp-password"] { @trs(&lang, "account.password") }
            input[type="password", id="inp-password", name="password"]; br;

            input[type="submit", value=&*tr(**lang, if *logged_in { "account.login.submit.switch" } else { "account.login.submit" })];

            @if *logged_in {
                p { @trs(&lang, "account.login.register.switch") " " a[href=u_account_register()] { @trs(&lang, "account.login.register_here") } }
            } else {
                p { @trs(&lang, "account.login.cookie_note") }
                p { @trs(&lang, "account.login.register") " " a[href=u_account_register()] { @trs(&lang, "account.login.register_here") } }
            }
        }
    }
    AccountLogout<'a>(lang: &'a Language) {
        form.account[method="POST", action=""] {
            h1 { @trs(&lang, "account.logout") }
            input[type="submit", value=&*tr(**lang, "account.logout.submit")];
        }
    }
}