This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Replace username picker with a template #9275
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8243ab2
Factor build_jinja_env out to a separate module
richvdh 6a5f353
Improve error handling in SubmitResource
richvdh 18e9b67
Replace username picker with a template
richvdh c3fb344
Document the new template
richvdh 038dab3
changelog
richvdh 2194106
template formatting
richvdh 22caec9
remove html comments
richvdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve the user experience of setting up an account via single-sign on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Synapse Login</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no"> | ||
<style type="text/css"> | ||
{% include "sso.css" without context %} | ||
|
||
.username_input { | ||
display: flex; | ||
border: 2px solid #418DED; | ||
border-radius: 8px; | ||
padding: 12px; | ||
position: relative; | ||
margin: 16px 0; | ||
align-items: center; | ||
font-size: 12px; | ||
} | ||
|
||
.username_input label { | ||
position: absolute; | ||
top: -8px; | ||
left: 14px; | ||
font-size: 80%; | ||
background: white; | ||
padding: 2px; | ||
} | ||
|
||
.username_input input { | ||
flex: 1; | ||
display: block; | ||
min-width: 0; | ||
border: none; | ||
} | ||
|
||
.username_input div { | ||
color: #8D99A5; | ||
} | ||
|
||
.idp-pick-details { | ||
border: 1px solid #E9ECF1; | ||
border-radius: 8px; | ||
margin: 24px 0; | ||
} | ||
|
||
.idp-pick-details h2 { | ||
margin: 0; | ||
padding: 8px 12px; | ||
} | ||
|
||
.idp-pick-details .idp-detail { | ||
border-top: 1px solid #E9ECF1; | ||
padding: 12px; | ||
} | ||
|
||
.idp-pick-details .use, .idp-pick-details .idp-value { | ||
color: #737D8C; | ||
} | ||
|
||
.idp-pick-details .idp-value { | ||
margin: 0; | ||
margin-top: 8px; | ||
} | ||
|
||
.idp-pick-details .avatar { | ||
width: 53px; | ||
height: 53px; | ||
border-radius: 100%; | ||
display: block; | ||
margin-top: 8px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Your account is nearly ready</h1> | ||
<p>Check your details before creating an account on {{ server_name }}</p> | ||
</header> | ||
<main> | ||
<form method="post" class="form__input" id="form"> | ||
<div class="username_input"> | ||
<label for="field-username">Username</label> | ||
<div class="prefix">@</div> | ||
<input type="text" name="username" id="field-username" autofocus required pattern="[a-z0-9\-=_\/\.]+"> | ||
<div class="postfix">:{{ server_name }}</div> | ||
</div> | ||
<input type="submit" value="Continue" class="primary-button"> | ||
{% if user_attributes %} | ||
<section class="idp-pick-details"> | ||
<h2><img src="{{ idp.idp_icon | mxc_to_http(24, 24) }}"/>Information from {{ idp.idp_name }}</h2> | ||
{% if user_attributes.avatar_url %} | ||
<div class="idp-detail idp-avatar"> | ||
<img src="{{ user_attributes.avatar_url }}" class="avatar" /> | ||
</div> | ||
{% endif %} | ||
{% if user_attributes.display_name %} | ||
<div class="idp-detail"> | ||
<p class="idp-value">{{ user_attributes.display_name }}</p> | ||
</div> | ||
{% endif %} | ||
{% for email in user_attributes.emails %} | ||
<div class="idp-detail"> | ||
<p class="idp-value">{{ email }}</p> | ||
</div> | ||
{% endfor %} | ||
</section> | ||
{% endif %} | ||
</form> | ||
</main> | ||
<script type="text/javascript"> | ||
{% include "sso_auth_account_details.js" without context %} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const usernameField = document.getElementById("field-username"); | ||
|
||
function throttle(fn, wait) { | ||
let timeout; | ||
return function() { | ||
const args = Array.from(arguments); | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
timeout = setTimeout(fn.bind.apply(fn, [null].concat(args)), wait); | ||
} | ||
} | ||
|
||
function checkUsernameAvailable(username) { | ||
let check_uri = 'check?username=' + encodeURIComponent(username); | ||
return fetch(check_uri, { | ||
// include the cookie | ||
"credentials": "same-origin", | ||
}).then((response) => { | ||
if(!response.ok) { | ||
// for non-200 responses, raise the body of the response as an exception | ||
return response.text().then((text) => { throw new Error(text); }); | ||
} else { | ||
return response.json(); | ||
} | ||
}).then((json) => { | ||
if(json.error) { | ||
return {message: json.error}; | ||
} else if(json.available) { | ||
return {available: true}; | ||
} else { | ||
return {message: username + " is not available, please choose another."}; | ||
} | ||
}); | ||
} | ||
|
||
function validateUsername(username) { | ||
usernameField.setCustomValidity(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL this is a thing. 👍 |
||
if (usernameField.validity.valueMissing) { | ||
usernameField.setCustomValidity("Please provide a username"); | ||
return; | ||
} | ||
if (usernameField.validity.patternMismatch) { | ||
usernameField.setCustomValidity("Invalid username, please only use " + allowedCharactersString); | ||
return; | ||
} | ||
usernameField.setCustomValidity("Checking if username is available …"); | ||
throttledCheckUsernameAvailable(username); | ||
} | ||
|
||
const throttledCheckUsernameAvailable = throttle(function(username) { | ||
const handleError = function(err) { | ||
// don't prevent form submission on error | ||
usernameField.setCustomValidity(""); | ||
console.log(err.message); | ||
}; | ||
try { | ||
checkUsernameAvailable(username).then(function(result) { | ||
if (!result.available) { | ||
usernameField.setCustomValidity(result.message); | ||
usernameField.reportValidity(); | ||
} else { | ||
usernameField.setCustomValidity(""); | ||
} | ||
}, handleError); | ||
} catch (err) { | ||
handleError(err); | ||
} | ||
}, 500); | ||
|
||
usernameField.addEventListener("input", function(evt) { | ||
validateUsername(usernameField.value); | ||
}); | ||
usernameField.addEventListener("change", function(evt) { | ||
validateUsername(usernameField.value); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template seems to also handle
avatar_url
, although none of our SSO code gets that right now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed it does. It's "future-proof".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright! Does it make sense to document it now or "in the future"? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should document it here until it's supported.