This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
181 lines (137 loc) · 6.13 KB
/
main.py
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# modelr web app
# Agile Geoscience
# 2012-2014
#
from google.appengine.ext import webapp as webapp2
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import users
# For image serving
import cloudstorage as gcs
import urllib
import urllib2
import os
import hashlib
import logging
import stripe
import re
from page_handlers import *
from web_api import *
from lib_auth import AuthExcept, get_cookie_string, signup, signin, \
verify, authenticate, verify_signup, initialize_user,\
reset_password, \
forgot_password, send_message, make_user, cancel_subscription
from lib_db import Rock, Scenario, User, ModelrParent, Group, \
GroupRequest, ActivityLog, VerifyUser, ModelServedCount,\
ImageModel, Forward2DModel, Issue, EarthModel, Server
from constants import admin_id, env, LOCAL, stripe_api_key
# Retry can help overcome transient urlfetch or GCS issues,
# such as timeouts.
my_default_retry_params = gcs.RetryParams(initial_delay=0.2,
max_delay=5.0,
backoff_factor=2,
max_retry_period=15)
# All requests to GCS using the GCS client within current GAE request
# and current thread will use this retry params as default. If a
# default is not set via this mechanism, the library's built-in
# default will be used. Any GCS client function can also be given a
# more specific retry params that overrides the default.
# Note: the built-in default is good enough for most cases. We
# override retry_params here only for demo purposes.
gcs.set_default_retry_params(my_default_retry_params)
# Ancestor dB for all of modelr. Allows for strongly consistent
# database queries. (all entities update together, so every page is
# is sync)
ModelrRoot = ModelrParent.all().get()
if ModelrRoot is None:
ModelrRoot = ModelrParent()
ModelrRoot.put()
# For the plot server
server = Server.all().ancestor(ModelrRoot).get()
if server is None:
server = Server(parent=ModelrRoot)
if LOCAL is True:
server.host = "http://127.0.0.1:8081"
logging.debug("[*] Debug info activated")
stripe.verify_ssl_certs = False
else:
server.host = "https://www.modelr.org"
server.put()
stripe.api_key = stripe_api_key
#=====================================================================
# Define Global Variables
#=====================================================================
# Initialize the model served counter
models_served = ModelServedCount.all().ancestor(ModelrRoot).get()
if models_served is None:
models_served = ModelServedCount(count=0, parent=ModelrRoot)
models_served.put()
# Put in the default rock database under the admin account.
# The admin account is set up so every user can view our default
# scenarios and rocks
admin_user = User.all().ancestor(ModelrRoot).filter("user_id =",
admin_id).get()
# Create the admin account
if admin_user is None:
password = "Mod3lrAdm1n"
email="admin@modelr.io"
admin_user = make_user(user_id=admin_id, email=email,
password=password,
parent=ModelrRoot)
# Create the public group. All users are automatically entitled
# to part of this group.
public = Group.all().ancestor(ModelrRoot).filter("name =", 'public')
public = public.fetch(1)
if not public:
public = Group(name='public', admin=admin_user.user_id,
parent=ModelrRoot)
public.put()
# Populate the default rock database.
#====================================================================
# Global Variables
#====================================================================
# Secret API key from Stripe dashboard
app = webapp2.WSGIApplication([('/', MainHandler),
('/dashboard', DashboardHandler),
('/rock', RockHandler),
('/fluid', FluidHandler),
('/scenario', ScenarioPageHandler),
('/scenario_db',ScenarioHandler),
('/pricing', PricingHandler),
('/profile', ProfileHandler),
('/settings', SettingsHandler),
('/about', AboutHandler),
('/features', FeaturesHandler),
('/feedback', FeedbackHandler),
('/help/?([-\w]+)?', HelpHandler),
('/terms', TermsHandler),
('/privacy', PrivacyHandler),
('/signup', SignUp),
('/verify_email', EmailAuthentication),
('/signin', SignIn),
('/manage_group', ManageGroup),
('/upload', Upload),
('/model_builder', ModelBuilder),
('/model', ModelHandler),
('/image_model', ImageModelHandler),
('/earth_model', EarthModelHandler),
('/forgot', ForgotHandler),
('/reset', ResetHandler),
('/delete', DeleteHandler),
('/signout', SignOut),
('/stripe', StripeHandler),
('/manage_group', ManageGroup),
('/model_served', ModelServed),
('/admin_site', AdminHandler),
('/1D_model', Model1DHandler),
('/1D_model_data', ModelData1DHandler),
('/server_error', ServerError),
('/.*', NotFoundPageHandler)
],
debug=False)
def main():
logging.getLogger().setLevel(logging.DEBUG)
run_wsgi_app(app)
if __name__ == "__main__":
main()