mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-23 00:23:55 +00:00
v1 basic invite works, not pretty or tested
This commit is contained in:
parent
cc9c8fdc94
commit
cad8d8a23b
10 changed files with 145 additions and 2 deletions
|
@ -88,6 +88,28 @@ templates.projectSharedWithYou =
|
|||
<p> <a href="<%= siteUrl %>">#{settings.appName}</a></p>
|
||||
"""
|
||||
|
||||
|
||||
templates.completeJoinGroupAccount =
|
||||
subject: _.template "Verify Email to join <%= group_name %> group"
|
||||
layout: NotificationEmailLayout
|
||||
type:"notification"
|
||||
compiledTemplate: _.template """
|
||||
<p>Hi, please verify your email to join the <%= group_name %> and get your free premium account</p>
|
||||
<center>
|
||||
<div style="width:200px;background-color:#a93629;border:1px solid #e24b3b;border-radius:3px;padding:15px; margin:24px;">
|
||||
<div style="padding-right:10px;padding-left:10px">
|
||||
<a href="<%= completeJoinUrl %>" style="text-decoration:none" target="_blank">
|
||||
<span style= "font-size:16px;font-family:Helvetica,Arial;font-weight:400;color:#fff;white-space:nowrap;display:block; text-align:center">
|
||||
Verify now
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</center>
|
||||
<p> Thank you</p>
|
||||
<p> <a href="<%= siteUrl %>">#{settings.appName}</a></p>
|
||||
"""
|
||||
|
||||
module.exports =
|
||||
templates: templates
|
||||
|
||||
|
|
|
@ -6,8 +6,36 @@ _s = require("underscore.string")
|
|||
|
||||
module.exports = SubscriptionDomainAllocator =
|
||||
|
||||
|
||||
getLicenceUserCanJoin: (user, callback)->
|
||||
licence = SubscriptionDomainAllocator._findDomainLicence(user.email)
|
||||
if licence?
|
||||
callback null, licence
|
||||
else
|
||||
callback()
|
||||
|
||||
attemptToJoinGroup: (user, callback)->
|
||||
licence = SubscriptionDomainAllocator._findDomainLicence(user.email)
|
||||
if licence? and user.emailVerified
|
||||
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback
|
||||
else
|
||||
callback "user not verified"
|
||||
|
||||
rejectInvitationToGroup: (user, subscription, callback)->
|
||||
removeUserFromGroup(subscription.admin_id, user._id, callback)
|
||||
|
||||
|
||||
getDomainLicencePage: (user)->
|
||||
licence = SubscriptionDomainAllocator._findDomainLicence(user.email)
|
||||
if licence?.verifyEmail
|
||||
return "/user/subscription/#{licence.subscription_id}/group/invited"
|
||||
else
|
||||
return undefined
|
||||
|
||||
|
||||
autoAllocate: (user, callback = ->)->
|
||||
licence = SubscriptionDomainAllocator._findDomainLicence(user.email)
|
||||
#
|
||||
if licence?
|
||||
SubscriptionGroupHandler.addUserToGroup licence.adminUser_id, user.email, callback
|
||||
else
|
||||
|
@ -21,4 +49,8 @@ module.exports = SubscriptionDomainAllocator =
|
|||
|
||||
return licence
|
||||
|
||||
findDomainLicenceBySubscriptionId: (subscription_id)->
|
||||
licence = _.find settings.domainLicences, (licence)->
|
||||
licence?.subscription_id == subscription_id
|
||||
return licence
|
||||
|
||||
|
|
|
@ -2,6 +2,11 @@ SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
|
|||
logger = require("logger-sharelatex")
|
||||
SubscriptionLocator = require("./SubscriptionLocator")
|
||||
|
||||
settings = require("settings-sharelatex")
|
||||
PasswordResetTokenHandler = require("../PasswordReset/PasswordResetTokenHandler")
|
||||
EmailHandler = require("../Email/EmailHandler")
|
||||
SubscriptionDomainAllocator = require("./SubscriptionDomainAllocator")
|
||||
|
||||
module.exports =
|
||||
|
||||
addUserToGroup: (req, res)->
|
||||
|
@ -32,3 +37,38 @@ module.exports =
|
|||
title: 'group_admin'
|
||||
users: users
|
||||
subscription: subscription
|
||||
|
||||
renderGroupInvitePage: (req, res)->
|
||||
subscription_id = req.params.subscription_id
|
||||
licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id)
|
||||
|
||||
res.render "subscriptions/group/invite",
|
||||
title: "Group Invitation"
|
||||
subscription_id:subscription_id
|
||||
licenceName:licence.name
|
||||
|
||||
beginJoinGroup: (req, res)->
|
||||
subscription_id = req.params.subscription_id
|
||||
user_id = req.session.user._id
|
||||
licence = SubscriptionDomainAllocator.findDomainLicenceBySubscriptionId(subscription_id)
|
||||
if !licence?
|
||||
res.send 500
|
||||
PasswordResetTokenHandler.getNewToken subscription_id, (err, token)->
|
||||
opts =
|
||||
to : req.session.user.email
|
||||
group_name: licence.name
|
||||
completeJoinUrl: "#{settings.siteUrl}/user/subscription/#{subscription_id}/group/complete_join?token=#{token}"
|
||||
EmailHandler.sendEmail "completeJoinGroupAccount", opts, ->
|
||||
res.send 200
|
||||
|
||||
completeJoin: (req, res)->
|
||||
subscription_id = req.params.subscription_id
|
||||
PasswordResetTokenHandler.getUserIdFromTokenAndExpire req.query.token, (err, token_subscription_id)->
|
||||
console.log token_subscription_id
|
||||
if subscription_id != token_subscription_id
|
||||
return res.send 403
|
||||
SubscriptionLocator.getSubscription subscription_id, (err, subscription)->
|
||||
SubscriptionGroupHandler.addUserToGroup subscription.admin_id, req.user.email, (err, user)->
|
||||
res.send "joined"
|
||||
|
||||
|
||||
|
|
|
@ -14,4 +14,7 @@ module.exports =
|
|||
|
||||
getMemberSubscriptions: (user_id, callback) ->
|
||||
logger.log user_id: user_id, "getting users group subscriptions"
|
||||
Subscription.find(member_ids: user_id).populate("admin_id").exec callback
|
||||
Subscription.find(member_ids: user_id).populate("admin_id").exec callback
|
||||
|
||||
getSubscription: (subscription_id, callback)->
|
||||
Subscription.findOne _id:subscription_id, callback
|
||||
|
|
|
@ -24,6 +24,9 @@ module.exports =
|
|||
app.post '/subscription/group/user', AuthenticationController.requireLogin(), SubscriptionGroupController.addUserToGroup
|
||||
app.del '/subscription/group/user/:user_id', AuthenticationController.requireLogin(), SubscriptionGroupController.removeUserFromGroup
|
||||
|
||||
app.get '/user/subscription/:subscription_id/group/invited', AuthenticationController.requireLogin(), SubscriptionGroupController.renderGroupInvitePage
|
||||
app.post '/user/subscription/:subscription_id/group/begin_join', AuthenticationController.requireLogin(), SubscriptionGroupController.beginJoinGroup
|
||||
app.get '/user/subscription/:subscription_id/group/complete_join', AuthenticationController.requireLogin(), SubscriptionGroupController.completeJoin
|
||||
|
||||
#recurly callback
|
||||
app.post '/user/subscription/callback', SubscriptionController.recurlyNotificationParser, SubscriptionController.recurlyCallback
|
||||
|
|
|
@ -53,7 +53,6 @@ UserSchema = new Schema
|
|||
# has this set to true, despite never having had a free trial
|
||||
hadFreeTrial: {type: Boolean, default: false}
|
||||
|
||||
|
||||
UserSchema.statics.getAllIds = (callback)->
|
||||
this.find {}, ["first_name"], callback
|
||||
|
||||
|
|
25
services/web/app/views/subscriptions/group/invite.jade
Normal file
25
services/web/app/views/subscriptions/group/invite.jade
Normal file
|
@ -0,0 +1,25 @@
|
|||
extends ../../layout
|
||||
|
||||
block scripts
|
||||
script(type='text/javascript').
|
||||
window.subscription_id = '#{subscription_id}'
|
||||
|
||||
block content
|
||||
.content.content-alt
|
||||
.container
|
||||
.row
|
||||
.col-md-8.col-md-offset-2(ng-cloak)
|
||||
.card(ng-controller="GroupSubscriptionInviteController")
|
||||
.page-header
|
||||
h1 You are invited to Join #{licenceName}
|
||||
span(ng-show="!requestSent")
|
||||
div You can claim a free premium account provided by #{licenceName} by verifying your email
|
||||
|
||||
a.btn.btn-default(href="/project") Skip
|
||||
|
||||
a.btn.btn.btn-primary(ng-click="joinGroup()") Verify email and join Group
|
||||
|
||||
span(ng-show="requestSent")
|
||||
div Check your email to complete joinging the group
|
||||
|
||||
a.btn(href="/project") Continue to projects
|
|
@ -349,6 +349,10 @@ module.exports =
|
|||
|
||||
reloadModuleViewsOnEachRequest: true
|
||||
|
||||
domainLicences: [
|
||||
{"domains":["gmail.com"], "adminUser_id":"555208e6ce4812e7d2319daa", "subscription_id":"555c6d1eb844bfb3964e0629", "name":"HENRYS AMAZING LICENCE"}
|
||||
]
|
||||
|
||||
# ShareLaTeX Server Pro options (https://www.sharelatex.com/university/onsite.html)
|
||||
# ----------
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ define [
|
|||
"main/new-subscription"
|
||||
"main/annual-upgrade"
|
||||
"main/register-users"
|
||||
"main/subscription/group-subscription-invite-controller"
|
||||
"analytics/AbTestingManager"
|
||||
"directives/asyncForm"
|
||||
"directives/stopPropagation"
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
define [
|
||||
"base"
|
||||
], (App) ->
|
||||
App.controller "GroupSubscriptionInviteController", ($scope, $http) ->
|
||||
|
||||
$scope.requestSent = false
|
||||
|
||||
$scope.joinGroup = ->
|
||||
console.log "joingin group"
|
||||
request = $http.post "/user/subscription/#{subscription_id}/group/begin_join", {_csrf:window.csrfToken}
|
||||
request.success (data, status)->
|
||||
$scope.requestSent = true
|
||||
request.error (data, status)->
|
||||
console.log "the request failed"
|
Loading…
Reference in a new issue