mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-22 15:17:53 -05:00
added join token route; handle route alongside existing student signup uri
This commit is contained in:
parent
7f9ffada5f
commit
75f8c6429a
2 changed files with 38 additions and 11 deletions
|
@ -280,6 +280,13 @@
|
|||
"view": "studentregistration/studentregistration",
|
||||
"title": "Class Registration"
|
||||
},
|
||||
{
|
||||
"name": "student-registration-token-only",
|
||||
"pattern": "^/join/:token",
|
||||
"routeAlias": "/classes/(complete_registration|.+/register/.+)",
|
||||
"view": "studentregistration/studentregistration",
|
||||
"title": "Class Registration"
|
||||
},
|
||||
{
|
||||
"name": "teacher-faq",
|
||||
"pattern": "^/educators/faq/?$",
|
||||
|
|
|
@ -32,11 +32,22 @@ class StudentRegistration extends React.Component {
|
|||
}
|
||||
componentDidMount () {
|
||||
this.setState({waiting: true}); // eslint-disable-line react/no-did-mount-set-state
|
||||
api({
|
||||
uri: `/classrooms/${this.props.classroomId}`,
|
||||
params: {
|
||||
token: this.props.classroomToken
|
||||
|
||||
// set uri and params
|
||||
let uri;
|
||||
let params;
|
||||
if (this.props.classroomId === null || typeof this.props.classroomId === 'undefined') {
|
||||
// configure for token-only endpoint
|
||||
uri = `/classtoken/${this.props.classroomToken}`;
|
||||
} else {
|
||||
// configure for endpoint expecting classroomId and token
|
||||
uri = `/classrooms/${this.props.classroomId}`;
|
||||
params = {token: this.props.classroomToken};
|
||||
}
|
||||
|
||||
api({
|
||||
uri: uri,
|
||||
params: params
|
||||
}, (err, body, res) => {
|
||||
this.setState({waiting: false});
|
||||
if (err) {
|
||||
|
@ -164,14 +175,23 @@ StudentRegistration.defaultProps = {
|
|||
|
||||
const IntlStudentRegistration = injectIntl(StudentRegistration);
|
||||
|
||||
const [classroomId, _, classroomToken] = document.location.pathname.split('/').filter(p => {
|
||||
if (p) {
|
||||
return p;
|
||||
// parse either format of student registration url:
|
||||
// "class register": http://scratch.mit.edu/classes/3/register/c0256654e1be
|
||||
// "join token": http://scratch.mit.edu/join/c025r54ebe
|
||||
let classroomId = null;
|
||||
let classroomToken = null;
|
||||
const classRegisterRegexp = /^\/?classes\/(\d*)\/register\/([a-zA-Z0-9]*)\/?$/;
|
||||
const classRegisterMatch = classRegisterRegexp.exec(document.location.pathname);
|
||||
if (classRegisterMatch) {
|
||||
classroomId = classRegisterMatch[1];
|
||||
classroomToken = classRegisterMatch[2];
|
||||
} else {
|
||||
const joinTokenRegexp = /^\/?join\/([a-zA-Z0-9]*)\/?$/;
|
||||
const joinTokenMatch = joinTokenRegexp.exec(document.location.pathname);
|
||||
if (joinTokenMatch) {
|
||||
classroomToken = joinTokenMatch[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.slice(-3);
|
||||
|
||||
const props = {classroomId, classroomToken};
|
||||
|
||||
render(<IntlStudentRegistration {...props} />, document.getElementById('app'));
|
||||
|
|
Loading…
Reference in a new issue