Skip to content

Commit a8cf19f

Browse files
committed
pointercrate-user-pages: implement frontend for oauth registration
It works by first having you go through google's authorization flow, and then having the website prompt you for a username. Signed-off-by: stadust <43299462+stadust@users.noreply.github.com>
1 parent eaf7af1 commit a8cf19f

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

pointercrate-user-pages/src/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ fn login_page_body() -> Markup {
7171
}
7272
}
7373
}
74-
}
74+
}

pointercrate-user-pages/src/register.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use maud::{html, Markup};
22
use pointercrate_core_pages::head::HeadLike;
33
use pointercrate_core_pages::PageFragment;
4+
use pointercrate_user::config;
45

56
pub fn registration_page() -> PageFragment {
67
let mut frag = PageFragment::new("Pointercrate - Registration", "Register for a new pointercrate account!")
@@ -25,11 +26,23 @@ fn register_page_body() -> Markup {
2526
h1.underlined.pad {
2627
"Sign Up"
2728
}
28-
@if cfg!(feature = "legacy_accounts") {
29-
p {
30-
"Create a new account. Please note that the username cannot be changed after account creation, so choose wisely!"
31-
}
29+
p {
30+
"Create a new account. Please note that the username cannot be changed after account creation, so choose wisely!"
31+
}
32+
@if cfg!(feature = "oauth2") {
33+
div #g_id_onload
34+
data-ux_mode="popup"
35+
data-auto_select="true"
36+
data-itp_support="true"
37+
data-client_id=(config::google_client_id())
38+
data-callback="googleOauthRegisterCallback" {}
3239

40+
div .g_id_signin data-text="signup_with" style="margin: 10px 0px" {}
41+
@if cfg!(feature = "legacy_accounts") {
42+
p.or style="text-size: small; margin: 0px" {"or"}
43+
}
44+
}
45+
@if cfg!(feature = "legacy_accounts") {
3346
form.flex.col #register-form novalidate = "" {
3447
p.info-red.output {}
3548
span.form-input #register-username {
@@ -56,5 +69,31 @@ fn register_page_body() -> Markup {
5669
}
5770
}
5871
}
72+
@if cfg!(feature = "oauth2") {
73+
(oauth_registration_dialog())
74+
}
5975
}
6076
}
77+
78+
79+
fn oauth_registration_dialog() -> Markup {
80+
html! {
81+
div.overlay.closable {
82+
div.dialog #oauth-registration-pick-username style="width: 400px" {
83+
span.plus.cross.hover {}
84+
h2.underlined.pad {
85+
"Pick your username:"
86+
}
87+
form.flex.col novalidate = "" {
88+
p.info-red.output {}
89+
span.form-input #oauth-username {
90+
label for = "username" {"Username:"}
91+
input type = "text" name = "username";
92+
p.error {}
93+
}
94+
input.button.blue.hover type = "submit" style = "margin: 15px auto 0px;" value="Sign Up!";
95+
}
96+
}
97+
}
98+
}
99+
}

pointercrate-user-pages/static/js/register.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Form, post, tooShort, valueMissing} from "/static/core/js/modules/form";
1+
import {displayError, Form, FormDialog, post, tooShort, valueMissing} from "/static/core/js/modules/form.js";
22

33

44
function intializeRegisterForm() {
@@ -46,7 +46,21 @@ function intializeRegisterForm() {
4646
});
4747
}
4848

49-
$(document).ready(function () {
49+
function googleOauthRegisterCallback(response) {
50+
let dialog = new FormDialog("oauth-registration-pick-username");
51+
dialog.form.addErrorOverride(40902, "oauth-username");
52+
dialog.form.onSubmit(() => {
53+
let formData = dialog.form.serialize();
54+
formData['credential'] = response['credential'];
55+
post("/api/v1/auth/oauth/google/register", {}, formData)
56+
.then(() => window.location = "/account/")
57+
.catch(displayError(dialog.form))
58+
})
59+
dialog.open();
60+
}
5061

62+
window.googleOauthRegisterCallback = googleOauthRegisterCallback;
63+
64+
$(document).ready(function () {
5165
intializeRegisterForm();
5266
})

0 commit comments

Comments
 (0)