email settings

This commit is contained in:
vabene1111 2021-05-30 15:53:16 +02:00
parent 505b60cb14
commit 3c778927e2
5 changed files with 248 additions and 80 deletions

View File

@ -77,7 +77,6 @@ class UserNameForm(forms.ModelForm):
help_texts = {
'first_name': _('Both fields are optional. If none are given the username will be displayed instead')
# noqa: E501
}

View File

@ -0,0 +1,82 @@
{% extends "base.html" %}
{% load crispy_forms_filters %}
{% load i18n %}
{% block title %}{% trans "E-mail Addresses" %}{% endblock %}
{% block content %}
<h3>{% trans "E-mail Addresses" %}</h3>
{% if user.emailaddress_set.all %}
<p>{% trans 'The following e-mail addresses are associated with your account:' %}</p>
<form action="{% url 'account_email' %}" class="email_list" method="post">
{% csrf_token %}
<fieldset class="blockLabels">
{% for emailaddress in user.emailaddress_set.all %}
<div class="ctrlHolder">
<label for="email_radio_{{ forloop.counter }}"
class="{% if emailaddress.primary %}primary_email{% endif %}">
<input id="email_radio_{{ forloop.counter }}" type="radio" name="email"
{% if emailaddress.primary or user.emailaddress_set.count == 1 %}checked="checked"{% endif %}
value="{{ emailaddress.email }}"/>
{{ emailaddress.email }}
{% if emailaddress.verified %}
<span class="badge badge-pill badge-success">{% trans "Verified" %}</span>
{% else %}
<span class="badge badge-pill badge-warning">{% trans "Unverified" %}</span>
{% endif %}
{% if emailaddress.primary %}<span class="badge badge-pill badge-info">{% trans "Primary" %}</span>{% endif %}
</label>
</div>
{% endfor %}
<div class="buttonHolder">
<button class="btn btn-success" type="submit"
name="action_primary">{% trans 'Make Primary' %}</button>
<button class="btn btn-info" type="submit"
name="action_send">{% trans 'Re-send Verification' %}</button>
<button class="btn btn-warning" type="submit" name="action_remove">{% trans 'Remove' %}</button>
</div>
</fieldset>
</form>
{% else %}
<p>
<strong>{% trans 'Warning:' %}</strong> {% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}
</p>
{% endif %}
{% if can_add_email %}
<h3>{% trans "Add E-mail Address" %}</h3>
<form method="post" action="{% url 'account_email' %}" class="add_email">
{% csrf_token %}
{{ form | crispy }}
<button name="action_add" class="btn btn-success" type="submit">{% trans "Add E-mail" %}</button>
</form>
{% endif %}
{% endblock %}
{% block extra_body %}
<script type="text/javascript">
(function () {
var message = "{% trans 'Do you really want to remove the selected e-mail address?' %}";
var actions = document.getElementsByName('action_remove');
if (actions.length) {
actions[0].addEventListener("click", function (e) {
if (!confirm(message)) {
e.preventDefault();
}
});
}
})();
</script>
{% endblock %}

View File

@ -0,0 +1,34 @@
{% extends "base.html" %}
{% load i18n %}
{% load account %}
{% block title %}{% trans "Confirm E-mail Address" %}{% endblock %}
{% block content %}
<h3>{% trans "Confirm E-mail Address" %}</h3>
{% if confirmation %}
{% user_display confirmation.email_address.user as user_display %}
<p>{% blocktrans with confirmation.email_address.email as email %}Please confirm that
<a href="mailto:{{ email }}">{{ email }}</a> is an e-mail address for user {{ user_display }}
.{% endblocktrans %}</p>
<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">
{% csrf_token %}
<button class="btn btn-primary" type="submit">{% trans 'Confirm' %}</button>
</form>
{% else %}
{% url 'account_email' as email_url %}
<p>{% blocktrans %}This e-mail confirmation link expired or is invalid. Please
<a href="{{ email_url }}">issue a new e-mail confirmation request</a>.{% endblocktrans %}</p>
{% endif %}
{% endblock %}

View File

@ -16,88 +16,141 @@
{% trans 'Settings' %}
</h3>
<br/>
<br/>
<!-- Nav tabs -->
<ul class="nav nav-tabs" id="myTab" role="tablist" style="margin-bottom: 2vh">
<li class="nav-item" role="presentation">
<a class="nav-link active" id="account-tab" data-toggle="tab" href="#account" role="tab"
aria-controls="account" aria-selected="true">{% trans 'Account' %}</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="preferences-tab" data-toggle="tab" href="#preferences" role="tab"
aria-controls="preferences" aria-selected="false">{% trans 'Preferences' %}</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="api-tab" data-toggle="tab" href="#api" role="tab" aria-controls="api"
aria-selected="false">{% trans 'API-Settings' %}</a>
</li>
<h4><i class="fas fa-user-edit fa-fw"></i> {% trans 'Account' %}</h4>
</ul>
<form action="." method="post">
{% csrf_token %}
{{ user_name_form|crispy }}
<button class="btn btn-success" type="submit" name="user_name_form"><i
class="fas fa-save"></i> {% trans 'Save' %}</button>
</form>
<form action="." method="post">
{% csrf_token %}
{{ password_form|crispy }}
<button class="btn btn-success" type="submit" name="password_form"><i
class="fas fa-save"></i> {% trans 'Save' %}</button>
</form>
<a href="{% url 'socialaccount_connections' %}">{% trans 'Link social account' %}</a>
<br/>
<br/>
<h4><i class="fas fa-language fa-fw"></i> {% trans 'Language' %}</h4>
<div class="row">
<div class="col-md-12">
<form action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input class="form-control" name="next" type="hidden" value="{{ redirect_to }}">
<select name="language" class="form-control">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<br/>
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Save' %}</button>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="account" role="tabpanel" aria-labelledby="account-tab">
<h4>{% trans 'Name Settings' %}</h4>
<form action="." method="post">
{% csrf_token %}
{{ user_name_form|crispy }}
<button class="btn btn-success" type="submit" name="user_name_form"><i
class="fas fa-save"></i> {% trans 'Save' %}</button>
</form>
<h4>{% trans 'Password Settings' %}</h4>
<form action="." method="post">
{% csrf_token %}
{{ password_form|crispy }}
<button class="btn btn-success" type="submit" name="password_form"><i
class="fas fa-save"></i> {% trans 'Save' %}</button>
</form>
<h4>{% trans 'Email Settings' %}</h4>
<a href="{% url 'account_email'%}" class="btn btn-primary">{% trans 'Manage Email Settings' %}</a>
<br/><br/>
<h4>{% trans 'Social' %}</h4>
<a href="{% url 'socialaccount_connections' %}" class="btn btn-primary">{% trans 'Manage Social Accounts' %}</a>
<br/>
<br/>
<br/>
<br/>
</div>
</div>
<br/>
<br/>
<h4><i class="fas fa-palette fa-fw"></i> {% trans 'Style' %}</h4>
<form action="." method="post">
{% csrf_token %}
{{ preference_form|crispy }}
<button class="btn btn-success" type="submit" name="preference_form"><i
class="fas fa-save"></i> {% trans 'Save' %}</button>
</form>
<br/>
<br/>
<h4><i class="fas fa-terminal fa-fw"></i> {% trans 'API Token' %}</h4>
{% trans 'You can use both basic authentication and token based authentication to access the REST API.' %} <br/>
<br/>
<div class="tab-pane" id="preferences" role="tabpanel" aria-labelledby="preferences-tab">
<div class="row">
<div class="col col-md-12">
<h4><i class="fas fa-language fa-fw"></i> {% trans 'Language' %}</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input class="form-control" name="next" type="hidden" value="{{ redirect_to }}">
<select name="language" class="form-control">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %}
selected{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<br/>
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Save' %}
</button>
</form>
</div>
</div>
<div class="row">
<div class="col col-md-12">
<h4><i class="fas fa-palette fa-fw"></i> {% trans 'Style' %}</h4>
</div>
</div>
<div class="row">
<div class="col col-md-12">
<form action="." method="post">
{% csrf_token %}
{{ preference_form|crispy }}
<button class="btn btn-success" type="submit" name="preference_form"><i
class="fas fa-save"></i> {% trans 'Save' %}</button>
</form>
</div>
</div>
</div>
<div class="tab-pane" id="api" role="tabpanel" aria-labelledby="api-tab">
<div class="row">
<div class="col col-md-12">
<h4><i class="fas fa-terminal fa-fw"></i> {% trans 'API Token' %}</h4>
{% trans 'You can use both basic authentication and token based authentication to access the REST API.' %}
<br/>
<br/>
</div>
</div>
<div class="row">
<div class="col col-md-12">
<div class="input-group mb-3">
<input class="form-control" value="{{ api_token }}" id="id_token">
<div class="input-group-append">
<button class="input-group-btn btn btn-primary" onclick="copyToken()"><i
class="far fa-copy"></i></button>
</div>
</div>
<br/>
{% trans 'Use the token as an Authorization header prefixed by the word token as shown in the following examples:' %}
<br/>
<code>Authorization: Token {{ api_token }}</code> {% trans 'or' %}<br/>
<code>curl -X GET http://your.domain.com/api/recipes/ -H 'Authorization:
Token {{ api_token }}'</code>
</div>
</div>
<div class="input-group mb-3">
<input class="form-control" value="{{ api_token }}" id="id_token">
<div class="input-group-append">
<button class="input-group-btn btn btn-primary" onclick="copyToken()"><i
class="far fa-copy"></i></button>
</div>
</div>
<br/>
{% trans 'Use the token as an Authorization header prefixed by the word token as shown in the following examples:' %}
<br/>
<code>Authorization: Token {{ api_token }}</code> {% trans 'or' %}<br/>
<code>curl -X GET http://your.domain.com/api/recipes/ -H 'Authorization: Token {{ api_token }}'</code>
<br/>
<br/>
<br/>
<br/>
<script type="application/javascript">
function copyToken() {

View File

@ -309,16 +309,16 @@ def user_settings(request):
up.sticky_navbar = form.cleaned_data['sticky_navbar']
up.shopping_auto_sync = form.cleaned_data['shopping_auto_sync']
if up.shopping_auto_sync < settings.SHOPPING_MIN_AUTOSYNC_INTERVAL: # noqa: E501
up.shopping_auto_sync = settings.SHOPPING_MIN_AUTOSYNC_INTERVAL # noqa: E501
if up.shopping_auto_sync < settings.SHOPPING_MIN_AUTOSYNC_INTERVAL:
up.shopping_auto_sync = settings.SHOPPING_MIN_AUTOSYNC_INTERVAL
up.save()
if 'user_name_form' in request.POST:
user_name_form = UserNameForm(request.POST, prefix='name')
if user_name_form.is_valid():
request.user.first_name = user_name_form.cleaned_data['first_name'] # noqa: E501
request.user.last_name = user_name_form.cleaned_data['last_name'] # noqa: E501
request.user.first_name = user_name_form.cleaned_data['first_name']
request.user.last_name = user_name_form.cleaned_data['last_name']
request.user.save()
if 'password_form' in request.POST:
@ -339,7 +339,7 @@ def user_settings(request):
'preference_form': preference_form,
'user_name_form': user_name_form,
'password_form': password_form,
'api_token': api_token
'api_token': api_token,
})