Commit 4d661eb6 authored by buttle's avatar buttle

Added site() to flask.g

Fixed remaining missing session user_id
parent d73a18f8
......@@ -69,7 +69,7 @@ class User(object):
kwargs={"token.token": kwargs['token'], **kwargs}
kwargs.pop('token')
if not ('hostname' in kwargs or g.isRootUser):
kwargs['hostname']=Site().hostname
kwargs['hostname']=g.site.hostname
user = mongo.db.users.find_one(kwargs)
if user:
......@@ -87,13 +87,13 @@ class User(object):
def findAll(cls, *args, **kwargs):
if not g.isRootUser:
kwargs['hostname']=Site().hostname
kwargs['hostname']=g.site.hostname
return mongo.db.users.find(kwargs)
def getNotifyNewFormEmails(cls):
emails=[]
criteria={ 'hostname':Site().hostname,
criteria={ 'hostname':g.site.hostname,
'blocked':False,
'validatedEmail': True,
'admin.isAdmin':True,
......@@ -113,7 +113,7 @@ class User(object):
def getNotifyNewUserEmails(cls):
emails=[]
criteria={ 'hostname':Site().hostname,
criteria={ 'hostname':g.site.hostname,
'blocked':False,
'validatedEmail': True,
'admin.isAdmin':True,
......@@ -312,7 +312,7 @@ class Form(object):
kwargs={"sharedEntries.key": kwargs['key'], **kwargs}
kwargs.pop('key')
if not ('hostname' in kwargs or g.isRootUser):
kwargs['hostname']=Site().hostname
kwargs['hostname']=g.site.hostname
#print(kwargs)
form = mongo.db.forms.find_one(kwargs)
......@@ -463,7 +463,7 @@ class Form(object):
def findAll(cls, *args, **kwargs):
if not g.isRootUser:
kwargs['hostname']=Site().hostname
kwargs['hostname']=g.site.hostname
if 'editor' in kwargs:
kwargs={"editors.%s" % kwargs["editor"] :{"$exists":True}, **kwargs}
kwargs.pop('editor')
......@@ -757,7 +757,7 @@ class Invite(object):
if '_id' in kwargs:
kwargs["_id"] = ObjectId(kwargs['_id'])
if not ('hostname' in kwargs or g.isRootUser):
kwargs['hostname']=Site().hostname
kwargs['hostname']=g.site.hostname
if 'token' in kwargs:
kwargs={"token.token": kwargs['token'], **kwargs}
kwargs.pop('token')
......@@ -805,7 +805,7 @@ class Invite(object):
def findAll(cls, *args, **kwargs):
if not g.isRootUser:
kwargs['hostname']=Site().hostname
kwargs['hostname']=g.site.hostname
return mongo.db.invites.find(kwargs)
def setToken(self, **kwargs):
......
......@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>{{ g.siteName }}</title>
<title>{{ g.site.siteName }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/static/jquery/jquery.min.js"></script>
<script src="/static/jquery/jquery-ui.min.js"></script>
......
......@@ -191,16 +191,16 @@
</tr>
</table>
<div id="editor" style="display:none">
<input id="save-edit" class="btn-success btn" type="button" value="{%trans%}Save{%endtrans%}" />
<input id="cancel-edit" class="btn-primary btn" type="button" value="{%trans%}Cancel{%endtrans%}" />
<p></p>
<form id="editor-form" action="/site/save-personal-data-consent-text" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<textarea id="sm-editor" name="editor">{{ site.personalDataConsent['markdown'] }}</textarea>
</form>
</div>
<div id="editor" style="display:none">
<input id="save-edit" class="btn-success btn" type="button" value="{%trans%}Save{%endtrans%}" />
<input id="cancel-edit" class="btn-primary btn" type="button" value="{%trans%}Cancel{%endtrans%}" />
<p></p>
<form id="editor-form" action="/site/save-personal-data-consent-text" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<textarea id="sm-editor" name="editor">{{ site.personalDataConsent['markdown'] }}</textarea>
</form>
</div>
{% endif %}
{% if g.isRootUser %}
<p></p>
......@@ -270,9 +270,7 @@
</td>
</tr>
</table>
{% endif %}
</div>
<div class="row col-md-3"></div>
</div>
......@@ -372,12 +370,6 @@ document.getElementById('toggle_dataprotection_enabled').addEventListener('click
}
});
});
document.getElementById('test-email-button').addEventListener('click', function(evt){
var email = $("#test-email").val();
if (email){
location.href="/site/test-smtp/"+email
}
});
$(document).ready(function() {
var simplemde = new SimpleMDE({
......@@ -389,9 +381,7 @@ $(document).ready(function() {
});
$("#show-editor").click(function(){
$('#blurb').hide();
$('#editor').show();
$('.flash_message').hide();
simplemde.value($("#sm-editor").val())
return false;
});
......@@ -402,9 +392,18 @@ $(document).ready(function() {
});
$("#cancel-edit").click(function(){
$('#editor').hide();
$('#blurb').show();
});
});
{% if g.isRootUser %}
document.getElementById('test-email-button').addEventListener('click', function(evt){
var email = $("#test-email").val();
if (email){
location.href="/site/test-smtp/"+email
}
});
{% endif %}
</script>
{% endblock %}
......@@ -45,11 +45,10 @@ def before_request():
g.isAdmin=False
if '/static' in request.path:
return
site=Site()
g.siteName=site.siteName
g.site=Site()
if 'user_id' in session:
g.current_user=User(_id=session["user_id"])
if g.current_user and g.current_user.hostname != site.hostname:
if g.current_user and g.current_user.hostname != g.site.hostname:
g.current_user=None
return
if g.current_user and g.current_user.isRootUser():
......@@ -990,7 +989,7 @@ def validate_email(token):
user.data['validatedEmail']=True
user.save()
#login the user
session['username']=user.username
session['user_id']=str(user._id)
flash(gettext("Your email address is valid"), 'success')
return redirect(make_url_for('user_settings', username=user.username))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment