overleaf/services/web/app/coffee/Features/BetaProgram/BetaProgramController.coffee

41 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2016-06-07 06:15:56 -04:00
BetaProgramHandler = require './BetaProgramHandler'
UserLocator = require "../User/UserLocator"
Settings = require "settings-sharelatex"
logger = require 'logger-sharelatex'
2016-09-22 09:30:34 -04:00
AuthenticationController = require '../Authentication/AuthenticationController'
2016-06-07 06:15:56 -04:00
module.exports = BetaProgramController =
optIn: (req, res, next) ->
2016-09-22 09:30:34 -04:00
user_id = AuthenticationController.getLoggedInUserId(req)
2016-06-07 06:15:56 -04:00
logger.log {user_id}, "user opting in to beta program"
2016-09-22 09:30:34 -04:00
if !user_id?
2016-06-07 06:15:56 -04:00
return next(new Error("no user id in session"))
BetaProgramHandler.optIn user_id, (err) ->
if err
return next(err)
2016-06-08 10:11:39 -04:00
return res.redirect "/beta/participate"
optOut: (req, res, next) ->
2016-09-22 09:30:34 -04:00
user_id = AuthenticationController.getLoggedInUserId(req)
2016-06-08 10:11:39 -04:00
logger.log {user_id}, "user opting out of beta program"
2016-09-22 09:30:34 -04:00
if !user_id?
2016-06-08 10:11:39 -04:00
return next(new Error("no user id in session"))
BetaProgramHandler.optOut user_id, (err) ->
if err
return next(err)
return res.redirect "/beta/participate"
2016-06-07 06:15:56 -04:00
optInPage: (req, res, next)->
2016-09-22 09:30:34 -04:00
user_id = AuthenticationController.getLoggedInUserId(req)
2016-06-08 10:11:39 -04:00
logger.log {user_id}, "showing beta participation page for user"
2016-06-07 06:15:56 -04:00
UserLocator.findById user_id, (err, user)->
if err
logger.err {err, user_id}, "error fetching user"
return next(err)
res.render 'beta_program/opt_in',
2016-06-07 08:42:06 -04:00
title:'sharelatex_beta_program'
2016-06-07 06:15:56 -04:00
user: user,
languages: Settings.languages,