Merge pull request #220 from mouse-reeve/ui-tweaks

Ui tweaks
This commit is contained in:
Mouse Reeve 2020-10-04 15:21:22 -07:00 committed by GitHub
commit 6dd56eb894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 38 deletions

View file

@ -3,7 +3,42 @@
<div class="columns">
<div class="column">
<div class="block">
<div class="box">
<h2 class="title">Log in</h2>
{% if login_form.non_field_errors %}
<p class="notification is-danger">{{ login_form.non_field_errors }}</p>
{% endif %}
<form name="login" method="post" action="/user-login">
{% csrf_token %}
<div class="field">
<label class="label" for="id_username">Username:</label>
<div class="control">
{{ login_form.username }}
</div>
{% for error in login_form.username.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div class="field">
<label class="label" for="id_password">Password:</label>
<div class="control">
{{ login_form.password }}
</div>
{% for error in login_form.password.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-primary" type="submit">Log in</button>
</div>
<div class="control">
<small><a href="/reset-password">Forgot your password?</a></small>
</div>
</div>
</form>
</div>
<div class="box has-background-primary-light">
{% if site_settings.allow_registration %}
<h2 class="title">Create an Account</h2>
<form name="register" method="post" action="/user-register">
@ -17,32 +52,6 @@
</div>
<div class="column">
<div class="block">
<h2 class="title">Log in</h2>
<form name="login" method="post" action="/user-login">
{% csrf_token %}
<div class="field">
<label class="label" for="id_username">Username:</label>
<div class="control">
{{ login_form.username }}
</div>
</div>
<div class="field">
<label class="label" for="id_password">Password:</label>
<div class="control">
{{ login_form.password }}
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-primary" type="submit">Log in</button>
</div>
<div class="control">
<small><a href="/reset-password">Forgot your password?</a></small>
</div>
</div>
</form>
</div>
<div class="block">
{% include 'snippets/about.html' with site_settings=site_settings %}
</div>

View file

@ -2,19 +2,28 @@
<div class="field">
<label class="label" for="id_username_register">Username:</label>
<div class="control">
<input type="text" name="username" maxlength="150" class="input" required="" id="id_username_register">
<input type="text" name="username" maxlength="150" class="input" required="" id="id_username_register" value="{% if register_form.username.value %}{{ register_form.username.value }} {% endif %}">
</div>
{% for error in register_form.username.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
<div class="field">
<label class="label" for="id_email_register">Email address:</label>
<div class="control">
<input type="email" name="email" maxlength="254" class="input" id="id_email_register">
<input type="email" name="email" maxlength="254" class="input" id="id_email_register" value="{% if register_form.email.value %}{{ register_form.email.value }}{% endif %}">
{% for error in register_form.email.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
</div>
<div class="field">
<label class="label" for="id_password_register">Password:</label>
<div class="control">
<input type="password" name="password" maxlength="128" class="input" required="" id="id_password_register">
{% for error in register_form.password.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</div>
</div>
<div class="field is-grouped">

View file

@ -23,14 +23,15 @@ def user_login(request):
if request.method == 'GET':
return redirect('/login')
register_form = forms.RegisterForm()
login_form = forms.LoginForm(request.POST)
register_form = forms.RegisterForm()
if not login_form.is_valid():
return TemplateResponse(
request,
'login.html',
{'login_form': login_form, 'register_form': register_form}
)
data = {
'site_settings': models.SiteSettings.get(),
'login_form': login_form,
'register_form': register_form
}
return TemplateResponse(request, 'login.html', data)
username = login_form.data['username']
username = '%s@%s' % (username, DOMAIN)
@ -39,7 +40,14 @@ def user_login(request):
if user is not None:
login(request, user)
return redirect(request.GET.get('next', '/'))
return redirect('/login')
login_form.non_field_errors = 'Username or password are incorrect'
data = {
'site_settings': models.SiteSettings.get(),
'login_form': login_form,
'register_form': register_form
}
return TemplateResponse(request, 'login.html', data)
def register(request):
@ -61,13 +69,27 @@ def register(request):
invite = None
form = forms.RegisterForm(request.POST)
errors = False
if not form.is_valid():
return redirect('/register/')
errors = True
username = form.data['username']
email = form.data['email']
password = form.data['password']
# check username and email uniqueness
if models.User.objects.filter(localname=username).first():
form.add_error('username', 'User with this username already exists')
errors = True
if errors:
data = {
'site_settings': models.SiteSettings.get(),
'login_form': forms.LoginForm(),
'register_form': form
}
return TemplateResponse(request, 'login.html', data)
user = models.User.objects.create_user(username, email, password)
if invite:
invite.times_used += 1

View file

@ -40,7 +40,8 @@ CELERY_RESULT_BACKEND = 'redis'
SECRET_KEY = '0a^0gpwjc1ap+lb$dinin=efc@e&_0%102$o3(&gt9e7lndiaw'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = env.bool('DEBUG', True)
ALLOWED_HOSTS = []