Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
46515897
Commit
46515897
authored
Sep 26, 2018
by
Luko van der Maas
Browse files
added api key and signature to google maps static map api requests
parent
3da5d0b0
Changes
4
Hide whitespace changes
Inline
Side-by-side
website/events/services.py
View file @
46515897
import
hmac
from
hashlib
import
sha1
from
base64
import
urlsafe_b64decode
,
urlsafe_b64encode
from
collections
import
OrderedDict
from
django.template.defaultfilters
import
urlencode
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
get_language
from
events
import
emails
from
events.exceptions
import
RegistrationError
from
events.models
import
Registration
,
RegistrationInformationField
from
thaliawebsite.settings
import
settings
def
is_user_registered
(
member
,
event
):
...
...
@@ -232,3 +237,22 @@ def registration_fields(member, event):
else
:
raise
RegistrationError
(
_
(
"You are not allowed to update this registration."
))
def
create_google_maps_url
(
event
):
maps_url
=
(
f
"/maps/api/staticmap?"
f
"center=
{
urlencode
(
event
.
map_location
)
}
&"
f
"zoom=13&size=450x250&"
f
"markers=
{
urlencode
(
event
.
map_location
)
}
&"
f
"key=
{
settings
.
GOOGLE_MAPS_API_KEY
}
"
)
decoded_key
=
urlsafe_b64decode
(
settings
.
GOOGLE_MAPS_API_SECRET
)
print
(
type
(
decoded_key
))
signature
=
hmac
.
new
(
decoded_key
,
maps_url
.
encode
(),
sha1
)
encoded_signature
=
urlsafe_b64encode
(
signature
.
digest
())
maps_url
+=
f
"&signature=
{
encoded_signature
.
decode
(
'utf-8'
)
}
"
return
"https://maps.googleapis.com"
+
maps_url
website/events/templates/events/event.html
View file @
46515897
...
...
@@ -200,7 +200,7 @@
<div
class=
"span6"
>
<div
class=
"location-map"
>
<img
src=
"
https://maps.googleapis.com/maps/api/staticmap?center={{ event.map_location|urlencode }}&zoom=13&size=450x250&markers={{ event.map_location|urlencode
}}"
/>
<img
src=
"
{{ maps_url
}}"
/>
</div>
</div>
</div>
...
...
website/events/views.py
View file @
46515897
"""Views provided by the events package"""
from
hashlib
import
sha1
import
hmac
from
base64
import
decodebytes
,
encodebytes
,
urlsafe_b64decode
,
\
urlsafe_b64encode
from
urllib.parse
import
quote
from
django.contrib
import
messages
from
django.contrib.auth.decorators
import
login_required
from
django.shortcuts
import
get_object_or_404
,
redirect
...
...
@@ -12,6 +18,7 @@ from events import services
from
events.exceptions
import
RegistrationError
from
.forms
import
FieldsForm
from
.models
import
Event
,
Registration
from
thaliawebsite
import
settings
class
EventIndex
(
TemplateView
):
...
...
@@ -63,6 +70,8 @@ class EventDetail(DetailView):
context
[
'date_now'
]
=
timezone
.
now
()
context
[
'maps_url'
]
=
services
.
create_google_maps_url
(
event
)
return
context
...
...
website/thaliawebsite/settings/settings.py
View file @
46515897
...
...
@@ -282,6 +282,10 @@ MAILINGLIST_API_SECRET = ''
# Members Sentry API key
MEMBERS_SENTRY_API_SECRET
=
''
# Google maps API key and secrets
GOOGLE_MAPS_API_KEY
=
''
GOOGLE_MAPS_API_SECRET
=
''
# Photos settings
PHOTO_UPLOAD_SIZE
=
1920
,
1080
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment