overleaf/services/web/app/coffee/Features/BetaProgram/BetaProgramController.coffee
Tim Alby 5fbe5c5537 remove UserLocator
Use UserGetter instead
2018-05-28 14:11:13 +02:00

40 lines
1.3 KiB
CoffeeScript

BetaProgramHandler = require './BetaProgramHandler'
UserGetter = require "../User/UserGetter"
Settings = require "settings-sharelatex"
logger = require 'logger-sharelatex'
AuthenticationController = require '../Authentication/AuthenticationController'
module.exports = BetaProgramController =
optIn: (req, res, next) ->
user_id = AuthenticationController.getLoggedInUserId(req)
logger.log {user_id}, "user opting in to beta program"
if !user_id?
return next(new Error("no user id in session"))
BetaProgramHandler.optIn user_id, (err) ->
if err
return next(err)
return res.redirect "/beta/participate"
optOut: (req, res, next) ->
user_id = AuthenticationController.getLoggedInUserId(req)
logger.log {user_id}, "user opting out of beta program"
if !user_id?
return next(new Error("no user id in session"))
BetaProgramHandler.optOut user_id, (err) ->
if err
return next(err)
return res.redirect "/beta/participate"
optInPage: (req, res, next)->
user_id = AuthenticationController.getLoggedInUserId(req)
logger.log {user_id}, "showing beta participation page for user"
UserGetter.getUser user_id, (err, user)->
if err
logger.err {err, user_id}, "error fetching user"
return next(err)
res.render 'beta_program/opt_in',
title:'sharelatex_beta_program'
user: user,
languages: Settings.languages,