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