aboutsummaryrefslogtreecommitdiffstats
path: root/etherpad/src/etherpad/control/pro/pro_main_control.js
blob: b4e3bc41fe15406f0bc0c2ac90724fad634219a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
 * Copyright 2009 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import("stringutils");
import("dispatch.{Dispatcher,DirMatcher,forward}");
import("funhtml.*");
import("cache_utils.syncedWithCache");

import("etherpad.helpers");
import("etherpad.utils.*");
import("etherpad.sessions.getSession");
import("etherpad.licensing");
import("etherpad.pne.pne_utils");
import("etherpad.pro.pro_pad_db");
import("etherpad.pro.domains");
import("etherpad.pro.pro_accounts");
import("etherpad.pro.pro_accounts.getSessionProAccount");
import("etherpad.pro.pro_padlist");

import("etherpad.control.pro.account_control");
import("etherpad.control.pro.pro_padlist_control");
import("etherpad.control.pro.admin.pro_admin_control");
import("etherpad.control.pro.admin.account_manager_control");

import("etherpad.pad.activepads");
import("etherpad.pad.model");


function onRequest() {
  var disp = new Dispatcher();
  disp.addLocations([
    [DirMatcher('/ep/account/'), forward(account_control)],
    [DirMatcher('/ep/admin/'), forward(pro_admin_control)],
    [DirMatcher('/ep/padlist/'), forward(pro_padlist_control)],
  ]);
  return disp.dispatch();
}

function render_main() {
  if (request.path == '/ep/') {
    response.redirect('/');
  }

  // recent pad list
  var livePads = pro_pad_db.listLiveDomainPads();
  var recentPads = pro_pad_db.listAllDomainPads();

  var renderLivePads = function() {
    return pro_padlist.renderPadList(livePads, ['title', 'connectedUsers'], 10);
  }

  var renderRecentPads = function() {
    return pro_padlist.renderPadList(recentPads, ['title'], 10);
  };

  var r = domains.getRequestDomainRecord();

  renderFramed('pro/pro_home.ejs', {
    isEvaluation: licensing.isEvaluation(),
    account: getSessionProAccount(),
    isPNE: pne_utils.isPNE(),
    pneVersion: pne_utils.getVersionString(),
    livePads: livePads,
    recentPads: recentPads,
    renderRecentPads: renderRecentPads,
    renderLivePads: renderLivePads,
    orgName: r.orgName
  });
  return true;
}

function render_finish_activation_get() {
  if (!isActivationAllowed()) {
    response.redirect('/');
  }

  var accountList = pro_accounts.listAllDomainAccounts();
  if (accountList.length > 1) {
    response.redirect('/');
  }
  if (accountList.length == 0) {
    throw Error("accountList.length should never be 0.");
  }

  var acct = accountList[0];
  var tempPass = stringutils.randomString(10);
  pro_accounts.setTempPassword(acct, tempPass);
  account_manager_control.sendWelcomeEmail(acct, tempPass);

  var domainId = domains.getRequestDomainId();

  syncedWithCache('pro-activations', function(c) {
    delete c[domainId];
  });

  renderNoticeString(
    DIV({style: "font-size: 16pt; border: 1px solid green; background: #eeffee; margin: 2em 4em; padding: 1em;"},
      P("Success!  You will receive an email shortly with instructions."),
      DIV({style: "display: none;", id: "reference"}, acct.id, ":", tempPass)));
}

function isActivationAllowed() {
  if (request.path != '/ep/finish-activation') {
    return false;
  }
  var allowed = false;
  var domainId = domains.getRequestDomainId();
  return syncedWithCache('pro-activations', function(c) {
    if (c[domainId]) {
      return true;
    }
    return false;
  });
}

function render_payment_required_get() {
  // Users get to this page when there is a problem with billing:
  // possibilities:
  //   * they try to create a new account but they have not entered
  //   payment information
  //
  //   * their credit card lapses and any pro request fails.
  //
  //   * others?

  var message = getSession().billingProblem || "A payment is required to proceed.";
  var adminList = pro_accounts.listAllDomainAdmins();

  renderFramed("pro/pro-payment-required.ejs", {
    message: message,
    isAdmin: pro_accounts.isAdminSignedIn(),
    adminList: adminList
  });
}