FEATURE: require name when accepting invite if 'full name required' setting is enabled

This commit is contained in:
Arpit Jalan 2017-05-29 13:15:01 +05:30
parent 266acbcc6c
commit d2c2139da8
8 changed files with 53 additions and 22 deletions

View File

@ -6,9 +6,10 @@ import { emailValid } from 'discourse/lib/utilities';
import InputValidation from 'discourse/models/input-validation';
import PasswordValidation from "discourse/mixins/password-validation";
import UsernameValidation from "discourse/mixins/username-validation";
import NameValidation from "discourse/mixins/name-validation";
import { userPath } from 'discourse/lib/url';
export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, UsernameValidation, {
export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, UsernameValidation, NameValidation, {
login: Ember.inject.controller(),
complete: false,
@ -85,15 +86,6 @@ export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, U
return I18n.t(Discourse.SiteSettings.full_name_required ? 'user.name.instructions_required' : 'user.name.instructions');
}.property(),
// Validate the name.
nameValidation: function() {
if (Discourse.SiteSettings.full_name_required && Ember.isEmpty(this.get('accountName'))) {
return InputValidation.create({ failed: true });
}
return InputValidation.create({ok: true});
}.property('accountName'),
// Check the email address
emailValidation: function() {
// If blank, fail without a reason

View File

@ -4,9 +4,10 @@ import DiscourseURL from 'discourse/lib/url';
import { ajax } from 'discourse/lib/ajax';
import PasswordValidation from "discourse/mixins/password-validation";
import UsernameValidation from "discourse/mixins/username-validation";
import NameValidation from "discourse/mixins/name-validation";
import { findAll as findLoginMethods } from 'discourse/models/login-method';
export default Ember.Controller.extend(PasswordValidation, UsernameValidation, {
export default Ember.Controller.extend(PasswordValidation, UsernameValidation, NameValidation, {
invitedBy: Ember.computed.alias('model.invited_by'),
email: Ember.computed.alias('model.email'),
accountUsername: Ember.computed.alias('model.username'),
@ -20,6 +21,11 @@ export default Ember.Controller.extend(PasswordValidation, UsernameValidation, {
return I18n.t('invites.welcome_to', {site_name: this.siteSettings.title});
},
@computed
nameLabel() {
return I18n.t(this.siteSettings.full_name_required ? 'invites.name_label' : 'invites.name_label_optional');
},
@computed('email')
yourEmailMessage(email) {
return I18n.t('invites.your_email', {email: email});
@ -30,9 +36,9 @@ export default Ember.Controller.extend(PasswordValidation, UsernameValidation, {
return findLoginMethods(this.siteSettings, this.capabilities, this.site.isMobileDevice).length > 0;
},
@computed('usernameValidation.failed', 'passwordValidation.failed')
submitDisabled(usernameFailed, passwordFailed) {
return usernameFailed || passwordFailed;
@computed('usernameValidation.failed', 'passwordValidation.failed', 'nameValidation.failed')
submitDisabled(usernameFailed, passwordFailed, nameFailed) {
return usernameFailed || passwordFailed || nameFailed;
},
actions: {
@ -42,6 +48,7 @@ export default Ember.Controller.extend(PasswordValidation, UsernameValidation, {
type: 'PUT',
data: {
username: this.get('accountUsername'),
name: this.get('accountName'),
password: this.get('accountPassword')
}
}).then(result => {

View File

@ -0,0 +1,15 @@
import InputValidation from 'discourse/models/input-validation';
import { default as computed } from 'ember-addons/ember-computed-decorators';
export default Ember.Mixin.create({
// Validate the name.
@computed('accountName')
nameValidation() {
if (this.siteSettings.full_name_required && Ember.isEmpty(this.get('accountName'))) {
return InputValidation.create({ failed: true });
}
return InputValidation.create({ok: true});
}
});

View File

@ -40,7 +40,7 @@ export default Ember.Mixin.create({
}
// If too short
if (accountUsername.length < Discourse.SiteSettings.min_username_length) {
if (accountUsername.length < this.siteSettings.min_username_length) {
return InputValidation.create({
failed: true,
reason: I18n.t('user.username.too_short')

View File

@ -24,14 +24,17 @@
<form>
<label>{{i18n 'user.username.title'}}</label>
<div class="input username-input">
{{input value=accountUsername id="new-account-username" name="username" maxlength=maxUsernameLength autocomplete="off"}}
&nbsp;{{input-tip validation=usernameValidation id="username-validation"}}
</div>
<label>{{i18n 'invites.password_label'}}</label>
<label>{{nameLabel}}</label>
<div class="input name-input">
{{input value=accountName id="new-account-name" name="name"}}
</div>
<label>{{i18n 'invites.password_label'}}</label>
<div class="input password-input">
{{password-field value=accountPassword type="password" id="new-account-password" capsLockOn=capsLockOn}}
&nbsp;{{input-tip validation=passwordValidation}}

View File

@ -29,11 +29,13 @@ class InvitesController < ApplicationController
end
def perform_accept_invitation
params.require(:id)
params.permit(:username, :name, :password)
invite = Invite.find_by(invite_key: params[:id])
if invite.present?
begin
user = invite.redeem(username: params[:username], password: params[:password])
user = invite.redeem(username: params[:username], name: params[:name], password: params[:password])
if user.present?
log_on_user(user)
post_process_invite(user)

View File

@ -1099,6 +1099,8 @@ en:
your_email: "Your account email address is <b>%{email}</b>."
accept_invite: "Accept Invitation"
success: "Your account has been created and you're now logged in."
name_label: "Name"
name_label_optional: "Name (optional)"
password_label: "Set Password (optional)"
password_reset:

View File

@ -1,7 +1,11 @@
import { acceptance } from "helpers/qunit-helpers";
import PreloadStore from 'preload-store';
acceptance("Invite Accept");
acceptance("Invite Accept", {
settings: {
full_name_required: true
}
});
test("Invite Acceptance Page", () => {
PreloadStore.store('invite_info', {
@ -14,7 +18,13 @@ test("Invite Acceptance Page", () => {
andThen(() => {
ok(exists("#new-account-username"), "shows the username input");
equal(find("#new-account-username").val(), "invited", "username is prefilled");
ok(exists("#new-account-name"), "shows the name input");
ok(exists("#new-account-password"), "shows the password input");
ok(exists('.invites-show .btn-primary:disabled'), 'submit is disabled because name is not filled');
});
fillIn("#new-account-name", 'John Doe');
andThen(() => {
not(exists('.invites-show .btn-primary:disabled'), 'submit is enabled');
});