1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Fix the upstream oauth registration form

This commit is contained in:
Quentin Gliech
2023-06-30 11:24:26 +02:00
parent dc629d195e
commit e1a5471262
3 changed files with 17 additions and 5 deletions

View File

@@ -75,6 +75,9 @@ pub(crate) enum RouteError {
#[error("Invalid form action")]
InvalidFormAction,
#[error("Missing username")]
MissingUsername,
#[error(transparent)]
Internal(Box<dyn std::error::Error>),
}
@@ -147,7 +150,8 @@ fn import_claim(
#[serde(rename_all = "lowercase", tag = "action")]
pub(crate) enum FormData {
Register {
username: String,
#[serde(default)]
username: Option<String>,
#[serde(default)]
import_email: Option<String>,
#[serde(default)]
@@ -456,11 +460,13 @@ pub(crate) async fn post(
|value, force| {
// If the username is forced, override whatever was in the form
if force {
username = value;
username = Some(value);
}
},
)?;
let username = username.ok_or(RouteError::MissingUsername)?;
// Now we can create the user
let user = repo.user().add(&mut rng, &clock, username).await?;

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
#}
{% macro input(label, name, type="text", form_state=false, autocomplete=false, class="", inputmode="text", autocorrect=false, autocapitalize=false, disabled=false, value="") %}
{% macro input(label, name, type="text", form_state=false, autocomplete=false, class="", inputmode="text", autocorrect=false, autocapitalize=false, disabled=false) %}
{% if not form_state %}
{% set form_state = dict(errors=[], fields=dict()) %}
{% endif %}
@@ -35,7 +35,6 @@ limitations under the License.
class="z-0 px-3 py-2 bg-white dark:bg-black-900 rounded-lg {{ border_color }} border-2 focus:border-accent focus:ring-0 focus:outline-0"
type="{{ type }}"
inputmode="{{ inputmode }}"
value="{{ state.value | default(value=value) }}"
{% if disabled %} disabled {% endif %}
{% if autocomplete %} autocomplete="{{ autocomplete }}" {% endif %}
{% if autocorrect %} autocorrect="{{ autocorrect }}" {% endif %}

View File

@@ -30,7 +30,14 @@ limitations under the License.
<input type="hidden" name="csrf" value="{{ csrf_token }}" />
<input type="hidden" name="action" value="register" />
{{ field::input(label="Username", name="username", autocomplete="username", autocorrect="off", autocapitalize="none", disabled=force_localpart, value=suggested_localpart) }}
{% if force_localpart %}
<div class="rounded-lg bg-grey-25 dark:bg-grey-450 p-4">
<div class="font-medium">Will use the following username</div>
<div class="font-mono">{{ suggested_localpart }}</div>
</div>
{% else %}
{{ field::input(label="Username", name="username", autocomplete="username", autocorrect="off", autocapitalize="none") }}
{% endif %}
{% if suggested_email %}
<div class="rounded-lg bg-grey-25 dark:bg-grey-450 p-4">