Skip to content

Commit ac95ec3

Browse files
committed
feat: new option forceUsernameViaEmail
1 parent d662fc0 commit ac95ec3

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/controllers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Controllers.editStrategy = async (req, res) => {
7373

7474
payload.enabled = !!req.body.enabled;
7575

76-
const checkboxes = ['usernameViaEmail', 'trustEmailVerified', 'syncFullname', 'syncPicture'];
76+
const checkboxes = ['forceUsernameViaEmail', 'usernameViaEmail', 'trustEmailVerified', 'syncFullname', 'syncPicture'];
7777
checkboxes.forEach((prop) => {
7878
payload[prop] = payload.hasOwnProperty(prop) && payload[prop] === 'on' ? 1 : 0;
7979
});

library.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ OAuth.parseUserReturn = async (provider, profile) => {
166166
given_name, middle_name, family_name,
167167
picture, roles, email, email_verified,
168168
} = profile;
169-
const { usernameViaEmail, idKey } = await OAuth.getStrategy(provider);
169+
const { usernameViaEmail, forceUsernameViaEmail, idKey } = await OAuth.getStrategy(provider);
170170

171171
const displayName = nickname || preferred_username || name;
172172

@@ -184,7 +184,7 @@ OAuth.parseUserReturn = async (provider, profile) => {
184184
email_verified,
185185
};
186186

187-
if (!normalized.displayName && email && usernameViaEmail === 'on') {
187+
if (forceUsernameViaEmail || (!normalized.displayName && email && usernameViaEmail === 'on')) {
188188
normalized.displayName = email.split('@')[0];
189189
}
190190

static/templates/partials/edit-oauth2-strategy.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
<label for="usernameViaEmail" class="form-check-label">Fall back to email as username if no username available (e.g. <code><strong>username</strong>@example.org</code>).</label>
112112
</div>
113113

114+
<div class="form-check form-switch mb-3">
115+
<input type="checkbox" class="form-check-input" id="forceUsernameViaEmail" name="forceUsernameViaEmail" {{{ if (./forceUsernameViaEmail == "1") }}}checked{{{ end }}}>
116+
<label for="forceUsernameViaEmail" class="form-check-label">Use email as username <span class="form-text text-danger">(supercedes previous option).</span></label>
117+
</div>
118+
114119
<div class="form-check form-switch mb-3">
115120
<input type="checkbox" class="form-check-input" id="trustEmailVerified" name="trustEmailVerified" {{{ if (./trustEmailVerified == "1") }}}checked{{{ end }}}>
116121
<label for="trustEmailVerified" class="form-check-label">Automatically confirm emails when <code>email_verified</code> is true.</code></label>

0 commit comments

Comments
 (0)