server/modules/auth.js
/**
 * Middleware that finds the student from the session 'cas_user' and
 * creates the student if it does not exist yet.
 *
 * @param {Koa context} ctx
 */
Middleware that finds the student from the session 'cas_user' and
creates the student if it does not exist yet.

@param {Koa context} ctx
Middleware that finds the student from the session ' cas_user ' and creates the student if it does not exist yet . @param { Koa context } ctx
async function loginStudent (ctx) {
  if (!ctx.session.cas_user) await cas.bounce();
  let student = await Student.findOne().byUsername(
    ctx.session.cas_user.toLowerCase()
  );
  if (student) {
    if (student.accountLocked) {
      logger.info(`${student.rcs_id} tried to login to locked account`);
      ctx.session = null;
      return ctx.redirect('/?waitlisted=1');
    }
    logger.info(`Logging in ${student.rcs_id}`);
  } else {
    student = Student({
      rcs_id: ctx.session.cas_user,
      accountLocked: true, 
      joined_date: new Date()
    });
    await student.save();
    logger.info(`Creating and adding new user to waitlist with rcs_id: ${student.rcs_id}`);
    sendNewUserEmail(student.rcs_id);
    ctx.session = null;
    return ctx.redirect('/?waitlisted=1');
  }
  student.last_login = new Date();
  await student.save();
  ctx.redirect(ctx.query.redirectTo || '/');
}
async function loginStudent ( ctx ) { if ( ! ctx . session . cas_user ) await cas . bounce ( ) ; let student = await Student . findOne ( ) . byUsername ( ctx . session . cas_user . toLowerCase ( ) ) ; if ( student ) { if ( student . accountLocked ) { logger . info ( ` ${ student . rcs_id } ` ) ; ctx . session = null ; return ctx . redirect ( '/?waitlisted=1' ) ; } logger . info ( ` ${ student . rcs_id } ` ) ; } else { student = Student ( { rcs_id : ctx . session . cas_user , accountLocked : true , joined_date : new Date ( ) } ) ; await student . save ( ) ; logger . info ( ` ${ student . rcs_id } ` ) ; sendNewUserEmail ( student . rcs_id ) ; ctx . session = null ; return ctx . redirect ( '/?waitlisted=1' ) ; } student . last_login = new Date ( ) ; await student . save ( ) ; ctx . redirect ( ctx . query . redirectTo || '/' ) ; }
Middleware that finds the student from the session 'cas_user' and
 creates the student if it does not exist yet.
Middleware that finds the student from the session ' cas_user ' and creates the student if it does not exist yet .
// TODO: CMS api to get personal info here // WAIT LIST /*
    logger.info(
      `Creating and logging in new student with rcs_id: ${student.rcs_id}`
    );
    */