fix donate form and token issue
This commit is contained in:
parent
dd28cbe373
commit
d7a156cf0a
|
@ -28,6 +28,15 @@ database = {
|
|||
'db': "maidstone_hackspace",
|
||||
'port': 3306}
|
||||
|
||||
email_server = {
|
||||
'username': '',
|
||||
'password': '',
|
||||
'host': 'mail_server',
|
||||
'port': 1025,
|
||||
'use_tls': False,
|
||||
'from': 'support@maidstone-hackspace.org.uk',
|
||||
'to': 'support@maidstone-hackspace.org.uk'}
|
||||
|
||||
# secret so not included in default settings
|
||||
oauth_live = False
|
||||
oauth_redirect_uri = app_domain + '/oauth'
|
||||
|
|
|
@ -16,7 +16,7 @@ web.template.append('<link rel="icon" type="image/png" href="/static/images/icon
|
|||
#paths
|
||||
web.document_root = os.path.abspath('./')
|
||||
web.template.domain = 'https://maidstone-hackspace.org.uk/'
|
||||
web.template.theme_full_path = os.path.abspath('./static') + os.sep
|
||||
# web.template.theme_full_path = os.path.abspath('./static') + os.sep
|
||||
#~ domain = 'http://192.168.21.41:5000/'
|
||||
#~ image_path = domain + os.sep + 'images' + os.sep
|
||||
|
||||
|
|
|
@ -80,16 +80,21 @@ def load_user(userid):
|
|||
|
||||
|
||||
@login_manager.token_loader
|
||||
def load_token(request):
|
||||
def load_token(token):
|
||||
print('request')
|
||||
print(request)
|
||||
token = request.headers.get('Authorization')
|
||||
if token is None:
|
||||
token = request.args.get('token')
|
||||
|
||||
if token is not None:
|
||||
username, password = token.split(":") # naive token
|
||||
user_entry = User.get(username)
|
||||
if (user_entry is not None):
|
||||
user = User(user_entry[0], user_entry[1])
|
||||
|
||||
if token is None:
|
||||
return None
|
||||
username, password = token.split(":") # naive token
|
||||
user_entry = User.get(username)
|
||||
if (user_entry is None):
|
||||
return None
|
||||
|
||||
user = User(user_entry[0], user_entry[1])
|
||||
|
||||
if (user.password == password):
|
||||
return user
|
||||
|
|
|
@ -33,12 +33,13 @@ def index():
|
|||
#~ web.page.section(web.paragraph.render())
|
||||
|
||||
|
||||
web.form.create('Donate to Maidstone Hackspace', '/donate/submit')
|
||||
web.form.append(name='provider', label='GoCardless', placeholder='gocardless', value='gocardless', input_type='radio')
|
||||
web.form.append(name='provider', label='PayPal', placeholder='', value='paypal', input_type='radio')
|
||||
web.form.append(name='reference', label='Reference', placeholder='#lair', value='#lair', input_type='select')
|
||||
web.form.append(name='amount', label='Donation Amount', placeholder='50.00', value='50.00')
|
||||
web.page.append(web.form.render())
|
||||
web.form_simple.create('Donate to Maidstone Hackspace', '/donate/submit')
|
||||
web.form_simple.append(input_name='provider', input_id="choose_gocardless",label='GoCardless', placeholder='gocardless', values='gocardless', input_type='radio')
|
||||
web.form_simple.append(input_name='provider', input_id="choose_paypal",label='PayPal', placeholder='', values='paypal', input_type='radio')
|
||||
web.form_simple.append(input_name='provider', input_id="choose_braintree",label='Braintree', placeholder='', values='braintree', input_type='radio')
|
||||
web.form_simple.append(input_name='reference', label='Reference', placeholder='#lair', values=['#lair','#t-shirt'], input_type='select')
|
||||
web.form_simple.append(input_name='amount', label='Donation Amount', placeholder='50.00', values='50.00', input_type='text')
|
||||
web.page.append(web.form_simple.render())
|
||||
|
||||
web.template.body.append(web.page.set_classes('page col s10 offset-s1').render())
|
||||
return web.render()
|
||||
|
|
|
@ -5,12 +5,17 @@ class control(base_widget):
|
|||
method = 'post'
|
||||
action = '/'
|
||||
inputs = []
|
||||
template = '''
|
||||
<div class="row">
|
||||
<div class="input-field col s12">
|
||||
%s
|
||||
</div>
|
||||
</div>'''
|
||||
template = {
|
||||
'text':'''
|
||||
<div class="row">
|
||||
<div class="input-field col s12">
|
||||
%s
|
||||
</div>
|
||||
</div>''',
|
||||
'radio': '''
|
||||
<p>
|
||||
%s
|
||||
</p>'''}
|
||||
|
||||
def create(self, action, method='post'):
|
||||
self.action = action
|
||||
|
@ -22,38 +27,50 @@ class control(base_widget):
|
|||
if template:
|
||||
control.template = template
|
||||
|
||||
def append(self, input_type, input_name, label, values="", classes='validate', disabled='')
|
||||
def append(self, input_type, input_name, label, values="", input_id=None, classes='validate', placeholder='', disabled=''):
|
||||
if input_type == 'select' and values:
|
||||
if type(values) is not list or tuple:
|
||||
self.inputs.append("""<select name="%s" id="%s">%s</select>""" % (input_name, input_name))
|
||||
form_control = """<select name="%s" id="%s">%s</select>""" % (
|
||||
input_name,
|
||||
input_name,
|
||||
"\n".join(["""<option value="%s">%s</option>""" % (value, value) for value in values]))
|
||||
|
||||
self.apply_template(input_type, form_control)
|
||||
return self
|
||||
if len(values[0]) == 2:
|
||||
self.inputs.append("""
|
||||
form_control = """
|
||||
<select name="%s" id="%s">%s</select>""" % (
|
||||
input_name,
|
||||
input_name,
|
||||
"\n".join(["""<option value="%s">%s</option>""" % (value, item) for value, item in values]))
|
||||
else:
|
||||
self.inputs.append("""
|
||||
form_control = """
|
||||
<select name="%s" id="%s">%s</select>""" % (
|
||||
input_name,
|
||||
input_name,
|
||||
"\n".join(["""<option value="%s">%s</option>""" % (item, item) for item in values]))
|
||||
|
||||
self.apply_template(input_type, form_control)
|
||||
return self
|
||||
|
||||
self.inputs.append("""
|
||||
form_control = """
|
||||
<input type="%s" name="%s" id="%s" placeholder="%s" %s classes="%s" value="%s" />
|
||||
<label for="%s">%s</label>""" % (
|
||||
input_type,
|
||||
input_name,
|
||||
input_name,
|
||||
input_id if input_id else '',
|
||||
label,
|
||||
'disabled="disabled" ' if disabled else '',
|
||||
classes,
|
||||
value,
|
||||
input_name,
|
||||
values,
|
||||
input_id if input_id else '',
|
||||
label)
|
||||
)
|
||||
self.apply_template(input_type, form_control)
|
||||
return self
|
||||
|
||||
def apply_template(self, input_type, form_control):
|
||||
return self.inputs.append(
|
||||
control.template.get(input_type, "<p>%s</p>") % form_control)
|
||||
|
||||
def render(self):
|
||||
super(control, self).render()
|
||||
|
@ -65,5 +82,5 @@ class control(base_widget):
|
|||
</div>""" % (
|
||||
self.method,
|
||||
self.action,
|
||||
"\n".join([control.template % input_item for input_item in inputs])
|
||||
"\n".join([input_item for input_item in self.inputs])
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue