Skip to content

Commit

Permalink
Changes third party structure, store choice in database as well (hedy…
Browse files Browse the repository at this point in the history
…org#3245)


Co-authored-by: Felienne <[email protected]>
  • Loading branch information
TiBiBa and Felienne authored Sep 1, 2022
1 parent 4a8968c commit 1a0df29
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
11 changes: 0 additions & 11 deletions static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,17 +1602,6 @@ export function toggle_blur_code() {
}
}

export function load_profile(username: string, mail: string, birth_year: number, gender: string, country: string) {
$('#profile-change-body').toggle();
if ($('#profile').is(":visible")) {
$('#username').html(username);
$('#email').val(mail);
$('#birth_year').val(birth_year);
$('#gender').val(gender);
$('#country').val(country);
}
}

export function change_language(lang: string) {
$.ajax({
type: 'POST',
Expand Down
10 changes: 5 additions & 5 deletions static/js/appbundle.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions templates/admin/admin-users.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ <h4 class="text-center">Total amount of shown users: {{ users|length }}</h4>
<td id="experience_header" class="hidden">Experience</td>
<td id="tags_header" class="text-center">Tags</td>
<td id="teacher_header" class="text-center">Teacher</td>
<td id="third_party_header" class="text-center">Third Party?</td>
<td id="verified_header" class="hidden">Verified</td>
</tr>
</thead>
Expand All @@ -163,6 +164,7 @@ <h4 class="text-center">Total amount of shown users: {{ users|length }}</h4>
{% else %}
<td class="teacher_cell text-center"><input type="checkbox" {% if user.is_teacher %}checked="checked"{% endif %} onclick="hedyApp.markAsTeacher (this, '{{user.username}}', {% if user.is_teacher %}false{% else %}true{% endif %})"></td>
{% endif %}<td class="verified_cell hidden">{{user.email_verified}}</td>
<td class="third_party_cell text-center"><input type="checkbox" {% if user.third_party %}checked="checked"{% endif %} ></td>
</tr>
{% endfor %}
</tbody>
Expand Down
24 changes: 14 additions & 10 deletions templates/profile.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "auth.html" %}

{% block body %}
{% block main %}
{% if user_data['teacher_request'] %}
<div class="flex items-center justify-center w-full h-10 bg-yellow-500 text-white font-bold">
<div>
Expand Down Expand Up @@ -88,19 +88,19 @@ <h2 class="profile-section-body-header">{{_('my_classes')}}</h2>
</div>
</div>
{% endif %}
<h1 class="section-header" onclick="hedyApp.load_profile ('{{user_data['username']}}', '{{user_data['email']}}', '{{user_data['birth_year']}}', '{{user_data['gender']}}', '{{user_data['country']}}')">{{_('settings')}}</h1>
<h1 class="section-header" onclick="$('#profile-change-body').toggle();">{{_('settings')}}</h1>
<div class="profile-section-body" id="profile-change-body">
<form id="profile">
<h2 class="profile-section-body-header">{{_('settings')}}</h2>
<div class="flex flex-row items-center mb-2">
<label for="username" class="inline-block w-72">{{_('username')}}</label><strong id="username" class="inline-block w-1/2 px-2"></strong>
<label for="username" class="inline-block w-72">{{_('username')}}</label><strong id="username" class="inline-block w-1/2 px-2">{{user_data['username']}}</strong>
</div>
<div class="flex flex-row items-center mb-2">
<label for="email" class="inline-block w-72">{{_('email')}}</label><input id="email" name="email" type="email" class="personal-input" {% if user_data['email'] %}required{% endif %}>
<label for="email" class="inline-block w-72">{{_('email')}}</label><input id="email" name="email" type="email" class="personal-input" value="{{user_data['email']}}" {% if user_data['email'] %}required{% endif %}>
</div>
<div class="flex flex-row items-center mb-2">
<label for="birth_year" class="inline-block w-72">{{_('birth_year')}}</label>
<input id="birth_year" name="birth_year" class="personal-input" type="number">
<input id="birth_year" name="birth_year" class="personal-input" type="number" value="{{user_data['birth_year']}}">
</div>
<div class="flex flex-row items-center mb-2">
<label for="language" class="inline-block w-72">{{_('preferred_language')}}</label>
Expand Down Expand Up @@ -129,21 +129,25 @@ <h2 class="profile-section-body-header">{{_('settings')}}</h2>
<div class="flex flex-row items-center mb-2">
<label for="gender" class="inline-block w-72">{{_('gender')}}</label>
<select id="gender" name="gender" class="personal-input">
<option value="">{{_('select')}}</option>
<option value="f">{{_('female')}}</option>
<option value="m">{{_('male')}}</option>
<option value="o">{{_('other')}}</option>
<option value=""}>{{_('select')}}</option>
<option value="f" {% if user_data['gender'] == "f" %}selected{% endif %}>{{_('female')}}</option>
<option value="m" {% if user_data['gender'] == "m" %}selected{% endif %}>{{_('male')}}</option>
<option value="o" {% if user_data['gender'] == "o" %}selected{% endif %}>{{_('other')}}</option>
</select>
</div>
<div class="flex flex-row items-center mb-2">
<label for="country" class="inline-block w-72">{{_('country')}}</label>
<select id="country" name="country" class="personal-input">
<option value="">{{_('select')}}</option>
{% for alpha, name in all_countries().items() %}
<option value="{{ alpha }}">{{ name }}</option>
<option value="{{ alpha }}" {% if alpha == user_data['country'] %}selected{% endif %}>{{ name }}</option>
{% endfor %}
</select>
</div>
<div class="flex flex-row items-center mt-4 gap-4">
<input type="checkbox" id="agree_third_party" name="agree_third_party" {% if user_data['third_party'] %}checked{% endif %}>
<label class="text-center" for="agree_third_party">{{_('agree_third_party')}}</label>
</div>
<div class="mb-4">
<button type="submit" class="green-btn mt-4">{{_('update_profile')}}</button>
</div>
Expand Down
3 changes: 2 additions & 1 deletion website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ def get_admin_users_page(user):
'username', 'email', 'birth_year', 'country',
'gender', 'created', 'last_login', 'verification_pending',
'is_teacher', 'program_count', 'prog_experience', 'teacher_request',
'experience_languages', 'language', 'keyword_language'
'experience_languages', 'language', 'keyword_language', 'third_party'
]

for user in users:
data = pick(user, *fields)
data['email_verified'] = not bool(data['verification_pending'])
data['is_teacher'] = bool(data['is_teacher'])
data['teacher_request'] = True if data['teacher_request'] else None
data['third_party'] = True if data['third_party'] else None
data['created'] = utils.timestamp_to_date(data['created'])
data['last_login'] = utils.timestamp_to_date(data['last_login']) if data.get('last_login') else None
if category == "language":
Expand Down
20 changes: 12 additions & 8 deletions website/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def store_new_account(account, email):
'keyword_language': account['keyword_language'],
'created': timems(),
'teacher_request': True if account.get('is_teacher') else None,
'third_party': True if account.get('agree_third_party') else None,
'verification_pending': hashed_token,
'last_login': timems()
}
Expand Down Expand Up @@ -421,12 +422,6 @@ def signup():
send_email(config['email']['sender'], 'Subscription to Hedy newsletter on signup', user['email'],
'<p>' + user['email'] + '</p>')


# If someone agrees to the third party contacts -> sent a mail to manually write down
if not is_testing_request(request) and 'agree_third_party' in body and body['agree_third_party'] is True:
send_email(config['email']['sender'], 'Agreement to Third party offers on signup', user['email'],
'<p>' + user['email'] + '</p>')

# We automatically login the user
cookie = make_salt()
DATABASE.store_token({'id': cookie, 'username': user['username'], 'ttl': times() + session_length})
Expand Down Expand Up @@ -627,6 +622,11 @@ def update_profile(user):
updates[field] = body[field]
else:
updates[field] = None
if body.get('agree_third_party'):
updates['third_party'] = True
else:
updates['third_party'] = None

if updates:
DATABASE.update_user(username, updates)

Expand All @@ -651,8 +651,12 @@ def get_profile(user):
# The user object we got from 'requires_login' is not fully hydrated yet. Look up the database user.
user = DATABASE.user_by_username(user['username'])

output = {'username': user['username'], 'email': user['email'], 'language': user.get('language', 'en')}
for field in ['birth_year', 'country', 'gender', 'prog_experience', 'experience_languages']:
output = {
'username': user['username'],
'email': user['email'],
'language': user.get('language', 'en')
}
for field in ['birth_year', 'country', 'gender', 'prog_experience', 'experience_languages', 'third_party']:
if field in user:
output[field] = user[field]
if 'verification_pending' in user:
Expand Down

0 comments on commit 1a0df29

Please sign in to comment.