MCPcopy Create free account
hub / github.com/codecombat/codecombat / redirectMiddleware

Method redirectMiddleware

app/views/play/CampaignView.js:334–406  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

332 }
333
334 redirectMiddleware () {
335 const studentRedirect = () => {
336 const courseInstanceId = utils.getQueryVariable('course-instance')
337 if (!courseInstanceId && me.isStudent() && this.terrain !== 'intro') {
338 window.noty({
339 text: $.i18n.t('play.home_campaign_redirect_student'),
340 layout: 'center',
341 timeout: 5000,
342 type: 'error',
343 })
344 application.router.navigate('/students', { trigger: true, replace: true })
345 return true
346 }
347 }
348
349 const hocRedirect = () => {
350 if (this.terrain === 'hoc-2018') {
351 $('body').append($("<img src='https://code.org/api/hour/begin_codecombat_play.png' style='visibility: hidden;'>"))
352 }
353
354 if (utils.getQueryVariable('hour_of_code')) {
355 if (me.isStudent() || me.isTeacher()) {
356 if (this.terrain === 'dungeon') {
357 const newCampaign = 'intro'
358 api.users.getCourseInstances({ userID: me.id, campaignSlug: newCampaign }, { data: { project: '_id' } })
359 .then(courseInstances => {
360 if (courseInstances.length) {
361 const courseInstanceID = courseInstances[0]._id
362 return application.router.navigate(`/play/${newCampaign}?course-instance=${courseInstanceID}`, { trigger: true, replace: true })
363 } else {
364 application.router.navigate((me.isStudent() ? '/students' : '/teachers'), { trigger: true, replace: true })
365 return noty({ text: 'Please create or join a classroom first', layout: 'topCenter', timeout: 8000, type: 'success' })
366 }
367 })
368 return true
369 }
370 }
371 if (this.terrain === 'game-dev-hoc') {
372 window.tracker?.trackEvent('Start HoC Campaign', { label: 'game-dev-hoc' })
373 }
374 me.set('hourOfCode', true)
375 me.patch()
376 const pixelCode = (() => {
377 switch (this.terrain) {
378 case 'game-dev-hoc': return 'code_combat_gamedev'
379 case 'game-dev-hoc-2': return 'code_combat_build_arcade'
380 case 'ai-league-hoc': return 'codecombat_esports'
381 case 'goblins-hoc': return 'codecombat_goblins'
382 default: return 'code_combat'
383 }
384 })()
385 $('body').append($(`<img src='https://code.org/api/hour/begin_${pixelCode}.png' style='visibility: hidden;'>`))
386 } else if (me.isTeacher() && !utils.getQueryVariable('course-instance') &&
387 !application.getHocCampaign() && (this.terrain !== 'hoc-2018')) {
388 // redirect teachers away from home campaigns
389 application.router.navigate('/teachers', { trigger: true, replace: true })
390 return true
391 } else if (location.pathname === '/paypal/subscribe-callback') {

Callers 1

constructorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected