Skip to content

Commit af4e466

Browse files
committed
[SDK-160]: Fix Flash example and add minor tweaks
1 parent 6807aa4 commit af4e466

File tree

9 files changed

+69
-25
lines changed

9 files changed

+69
-25
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,8 @@ ENV/
9494
*.un~
9595
.history/
9696
.vscode
97+
98+
# examples files
9799
examples/yoti_example_django/yoti_example/static/YotiSelfie.jpg
98100
examples/yoti_example_django/db.sqlite3
101+
examples/yoti_example_flask/static/YotiSelfie.jpg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ nationality = user_profile.get('nationality')
139139

140140
Both example applications utilise the env variables described in [Configuration](#configuration), make sure they are accessible.
141141

142-
* Installing dependencies: `pip install -e .[examples]`
142+
* Installing dependencies: `pip install -e .[examples]` (If you're using `zsh` you need to escape the square brackets: `pip install -e .\[examples\]`)
143143

144144
### Flask:
145145

examples/yoti_example_django/yoti_example/templates/profile.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>PROFILE</title>
5+
<title>Yoti Profile</title>
66
</head>
77
<body>
88
<h3><a href="/">Home</a></h3>
99
<table>
1010
{% if user_id %}
1111
<tr>
12-
<td>USER ID:</td>
12+
<td>User ID:</td>
1313
<td>{{user_id}}</td>
1414
</tr>
1515
{% endif %}
1616

1717
{% if selfie %}
1818
<tr>
19-
<td>SELFIE in base64 format:</td>
19+
<td>Selfie in base64 format:</td>
2020
<td><img width="200" alt="base64photo" src="{{selfie}}" /></td>
2121
</tr>
2222
<tr>
23-
<td>SELFIE from saved image:</td>
23+
<td>Selfie from saved image:</td>
2424
<td><img width="200" alt="saved image" src="/static/YotiSelfie.jpg" /></td>
2525
</tr>
2626
{% endif %}
@@ -48,7 +48,7 @@ <h3><a href="/">Home</a></h3>
4848

4949
{% if date_of_birth %}
5050
<tr>
51-
<td>DATE OF BIRTH:</td>
51+
<td>Date of Birth:</td>
5252
<td>{{date_of_birth}}</td>
5353
</tr>
5454
{% endif %}

examples/yoti_example_django/yoti_example/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get(self, request, *args, **kwargs):
2626
client = Client(YOTI_CLIENT_SDK_ID, YOTI_FULL_KEY_FILE_PATH)
2727
activity_details = client.get_activity_details(request.GET['token'])
2828
context = activity_details.user_profile
29-
self.save_image(activity_details.user_profile.get('selfie'))
29+
self.save_image(context.get('selfie'))
3030
return self.render_to_response(context)
3131

3232
@staticmethod
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
YOTI_APPLICATION_ID=
2+
YOTI_CLIENT_SDK_ID=
3+
YOTI_KEY_FILE_PATH=

examples/yoti_example_flask/app.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import os
2+
from os.path import join, dirname
3+
from binascii import a2b_base64
4+
from dotenv import load_dotenv
15
from flask import Flask, render_template, request
2-
36
from yoti_python_sdk import Client
47

8+
dotenv_path = join(dirname(__file__), '.env')
9+
load_dotenv(dotenv_path)
10+
511
from settings import (
612
YOTI_APPLICATION_ID,
713
YOTI_CLIENT_SDK_ID,
@@ -10,6 +16,13 @@
1016

1117
app = Flask(__name__)
1218

19+
def save_image(base64_uri):
20+
base64_data_stripped = base64_uri[base64_uri.find(",")+1:]
21+
binary_data = a2b_base64(base64_data_stripped)
22+
upload_path = os.path.join(app.root_path, 'static', 'YotiSelfie.jpg')
23+
fd = open(upload_path, 'wb')
24+
fd.write(binary_data)
25+
fd.close()
1326

1427
@app.route('/')
1528
def index():
@@ -21,9 +34,9 @@ def auth():
2134
client = Client(YOTI_CLIENT_SDK_ID, YOTI_FULL_KEY_FILE_PATH)
2235
activity_details = client.get_activity_details(request.args['token'])
2336
user_profile = activity_details.user_profile
37+
save_image(user_profile.get('selfie'))
2438
return render_template('profile.html',
2539
**user_profile)
2640

27-
2841
if __name__ == '__main__':
2942
app.run(debug=True)

examples/yoti_example_flask/static/.keep

Whitespace-only changes.

examples/yoti_example_flask/templates/profile.html

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,81 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>PROFILE</title>
5+
<title>Yoti Profile</title>
66
</head>
77
<body>
88
<h3><a href="/">Home</a></h3>
99
<table>
1010
{% if user_id %}
1111
<tr>
12-
<td>USER ID:</td>
12+
<td>User ID:</td>
1313
<td>{{user_id}}</td>
1414
</tr>
1515
{% endif %}
1616

1717
{% if selfie %}
1818
<tr>
19-
<td>SELFIE:</td>
20-
<td><img width="200" alt="photo" src="{{selfie}}" /></td>
19+
<td>Selfie in base64 format:</td>
20+
<td><img width="200" alt="base64photo" src="{{selfie}}" /></td>
21+
</tr>
22+
<tr>
23+
<td>Selfie from saved image:</td>
24+
<td><img width="200" alt="saved image" src="/static/YotiSelfie.jpg" /></td>
25+
</tr>
26+
{% endif %}
27+
28+
{% if given_names %}
29+
<tr>
30+
<td>Given Names:</td>
31+
<td>{{given_names}}</td>
32+
</tr>
33+
{% endif %}
34+
35+
{% if family_name %}
36+
<tr>
37+
<td>Family Name:</td>
38+
<td>{{family_name}}</td>
39+
</tr>
40+
{% endif %}
41+
42+
{% if phone_number %}
43+
<tr>
44+
<td>Phone Number:</td>
45+
<td>{{phone_number}}</td>
2146
</tr>
2247
{% endif %}
2348

24-
{% if phone %}
49+
{% if date_of_birth %}
2550
<tr>
26-
<td>PHONE:</td>
27-
<td>{{phone}}</td>
51+
<td>Date of Birth:</td>
52+
<td>{{date_of_birth}}</td>
2853
</tr>
2954
{% endif %}
3055

31-
{% if names %}
56+
{% if postal_address %}
3257
<tr>
33-
<td>NAMES:</td>
34-
<td>{{names}}</td>
58+
<td>Postal Address:</td>
59+
<td>{{postal_address}}</td>
3560
</tr>
3661
{% endif %}
3762

38-
{% if birthdate %}
63+
{% if email_address %}
3964
<tr>
40-
<td>DATE OF BIRTH</td>
41-
<td>{{birthdate}}</td>
65+
<td>Email Address:</td>
66+
<td>{{email_address}}</td>
4267
</tr>
4368
{% endif %}
4469

4570
{% if nationality %}
4671
<tr>
47-
<td>NATIONALITY</td>
72+
<td>NATIONALITY:</td>
4873
<td>{{nationality}}</td>
4974
</tr>
5075
{% endif %}
5176

5277
{% if gender %}
5378
<tr>
54-
<td>GENDER</td>
79+
<td>GENDER:</td>
5580
<td>{{gender}}</td>
5681
</tr>
5782
{% endif %}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
install_requires=['cryptography>=1.4', 'protobuf>=3.0.0',
2121
'requests>=2.0.0', 'future>=0.11.0'],
2222
extras_require={
23-
'examples': ['Django>=1.9', 'Flask>=0.10'],
23+
'examples': ['Django>=1.9', 'Flask>=0.10', 'python-dotenv>=0.7.1'],
2424
},
2525
classifiers=[
2626
'Development Status :: 5 - Production/Stable',

0 commit comments

Comments
 (0)