Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signup teams #210

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
43 changes: 37 additions & 6 deletions routes/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const actionHandler = require('./handlers/action-handler.js');
const signinRequiredRoute = require('./handlers/signin-required-route');
const languages = require('../locales/languages');
const search = require('../search');
const slugs = require('./helpers/slugs.js');

const formDefs = {
'register': [{
Expand Down Expand Up @@ -267,6 +268,7 @@ if (!config.requireInviteLinks) {
if (error) {
debug.error({ req, error });
}
setSignupLanguage(req, res);
returnToPath(req, res);
});
})
Expand Down Expand Up @@ -317,6 +319,7 @@ router.post('/register/:code', function(req, res, next) {
if (error) {
debug.error({ req, error });
}
setSignupLanguage(req, res);
returnToPath(req, res);
});
})
Expand All @@ -341,23 +344,51 @@ router.post('/register/:code', function(req, res, next) {

});

function sendRegistrationForm(req, res, formInfo) {
async function sendRegistrationForm(req, res, formInfo) {
let pageErrors = req.flash('pageErrors');

const { code } = req.params;

render.template(req, res, 'register', {
const signupTeams = req.query.signupTeams;
// checks if signupTeams exist, valid teams are passed to render
if (signupTeams) {
let signupTeamsArray = signupTeams.split(' ');
let validSignupTeams = [];
let promise_array = [];
for (let i = 0; i < signupTeamsArray.length; i++) {
let team = slugs.resolveAndLoadTeam(req, res, signupTeamsArray[i])
.then(result => {
validSignupTeams.push({ 'team': result.canonicalSlugName });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just push the team objects themselves into a plain array. That way, you can access slug, label and ID later.

In the template, you can loop through a plain array via {{#each}} and access each team's properties via this.

})
// swallow DocumentNotFoundErrors
.catch(err => console.log(err.message));
promise_array[i] = team;
}
await Promise.all(promise_array);
render.template(req, res, 'register', {
titleKey: 'register',
pageErrors,
formValues: formInfo ? formInfo.formValues : undefined,
questionCaptcha: forms.getQuestionCaptcha('register'),
illegalUsernameCharactersReadable: User.options.illegalCharsReadable,
scripts: ['register.js'],
inviteCode: code,
signupLanguage: req.query.signupLanguage || req.body.signupLanguage,
signupTeamsTransfer: validSignupTeams,
illegalUsernameCharacters: User.options.illegalChars.source
});
} else {
render.template(req, res, 'register', {
titleKey: 'register',
pageErrors,
formValues: formInfo ? formInfo.formValues : undefined,
questionCaptcha: forms.getQuestionCaptcha('register'),
illegalUsernameCharactersReadable: User.options.illegalCharsReadable,
scripts: ['register.js'],
inviteCode: code,
signupLanguage: req.query.signupLanguage || req.body.signupLanguage
}, {
signupLanguage: req.query.signupLanguage || req.body.signupLanguage,
illegalUsernameCharacters: User.options.illegalChars.source
});
});
}
}

// Check for external redirect in returnTo. If present, redirect to /, otherwise
Expand Down
12 changes: 12 additions & 0 deletions views/register.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
<input id="email" name="email" type="text" data-auto-trim placeholder="{{{__ "enter email"}}}" value="{{formValues.email}}" size="30" class="pure-input-1 login-form-input">
</div>

{{#if signupTeamsTransfer}}
<div class="pure-control-group">
<h4>Teams suggested by invite link, check box to join</h4>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May need to add explanation or link to explanation of what teams are.

Via Eloquence: text will need to be internationalized before merge

Copy link
Owner

@eloquence eloquence Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass the full team objects along, you can access the internationalized team names via {{{mlString this.name}}} inside the {{#each}} loop.

{{#each signupTeamsTransfer}}
<label for="checkbox-option-{{team}}" class="pure-checkbox">
<input id="checkbox-option-{{team}}" type="checkbox" value="">
Copy link
Owner

@eloquence eloquence Jun 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest setting the boxes to checked state. Also be sure to set the name for the input, not just the ID, so the field is submitted under that name.

{{team}}
</label>
{{/each}}
</div>
{{/if}}

{{#if questionCaptcha}}
<div class="pure-control-group">
<p>{{{__ "captcha intro"}}}</p>
Expand Down