Add option to use email address as username

Added option email/no_username to disable username input on form, and
instead use the provided email address as the username. Also added
missing 'packaging' dep from pevious update.
This commit is contained in:
Harvey Tindall 2020-06-29 00:35:51 +01:00
parent 09bbe8fddf
commit 68a459023c
7 changed files with 49 additions and 6 deletions

View File

@ -36,6 +36,7 @@ A basic account management system for [Jellyfin](https://github.com/jellyfin/jel
* pytz * pytz
* python-dateutil * python-dateutil
* watchdog * watchdog
* packaging
``` ```
### Install ### Install
@ -120,6 +121,8 @@ contact_message = Need help? contact me.
help_message = Enter your details to create an account. help_message = Enter your details to create an account.
; Displayed when an account is created. ; Displayed when an account is created.
success_message = Your account has been created. Click below to continue to Jellyfin. success_message = Your account has been created. Click below to continue to Jellyfin.
; When true, disables username input on invite form and sets the Jellyfin username to the email address
no_username = false
[password_validation] [password_validation]
; Enables password validation. ; Enables password validation.
@ -182,7 +185,7 @@ api_key = your api key
encryption = starttls encryption = starttls
server = smtp.jellyf.in server = smtp.jellyf.in
; Uses SMTP_SSL, so make sure the port is for this, not starttls. ; Uses SMTP_SSL, so make sure the port is for this, not starttls.
port = 587 port = 465
password = smtp password password = smtp password
[files] [files]

View File

@ -106,6 +106,10 @@ for key in ["user_configuration", "user_displayprefs"]:
log.debug(f"Using default {key}") log.debug(f"Using default {key}")
config["files"][key] = str(data_dir / (key + ".json")) config["files"][key] = str(data_dir / (key + ".json"))
if "no_username" not in config["email"]:
config["email"]["no_username"] = "false"
log.debug("Set no_username to false")
with open(config["files"]["invites"], "r") as f: with open(config["files"]["invites"], "r") as f:
temp_invites = json.load(f) temp_invites = json.load(f)
if "invites" in temp_invites: if "invites" in temp_invites:

View File

@ -49,7 +49,9 @@ number = 1
special = 0 special = 0
[email] [email]
; Leave this whole section if you aren't using any email-related features. ; When true, disables username input on invite form and sets the Jellyfin username to the email address
no_username = false
; Leave the rest of this section if you aren't using any email-related features.
use_24h = true use_24h = true
; Date format follows datetime's strftime. ; Date format follows datetime's strftime.
date_format = %d/%m/%y date_format = %d/%m/%y

View File

@ -68,12 +68,14 @@
<form action="#" method="POST"> <form action="#" method="POST">
<div class="form-group"> <div class="form-group">
<label for="inputEmail">Email</label> <label for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail" name="email" placeholder="Email" value="{{ email }}" required> <input type="email" class="form-control" id="{% if username %}inputEmail{% else %}inputUsername{% endif %}" name="{% if username %}email{% else %}username{% endif %}" placeholder="Email" value="{{ email }}" required>
</div> </div>
{% if username %}
<div class="form-group"> <div class="form-group">
<label for="inputUsername">Username</label> <label for="inputUsername">Username</label>
<input type="username" class="form-control" id="inputUsername" name="username" placeholder="Username" required> <input type="username" class="form-control" id="inputUsername" name="username" placeholder="Username" required>
</div> </div>
{% endif %}
<div class="form-group"> <div class="form-group">
<label for="inputPassword">Password</label> <label for="inputPassword">Password</label>
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password" required> <input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password" required>
@ -133,6 +135,9 @@
toggleSpinner(); toggleSpinner();
var send = $("form").serializeObject(); var send = $("form").serializeObject();
send['code'] = code; send['code'] = code;
{% if not username %}
send['email'] = send['username'];
{% endif %}
send = JSON.stringify(send); send = JSON.stringify(send);
$.ajax('/newUser', { $.ajax('/newUser', {
data : send, data : send,

View File

@ -1,4 +1,3 @@
import json
from pathlib import Path from pathlib import Path
from flask import Flask, send_from_directory, render_template from flask import Flask, send_from_directory, render_template
from jellyfin_accounts import config, app, g, css, data_store from jellyfin_accounts import config, app, g, css, data_store
@ -69,6 +68,7 @@ def inviteProxy(path):
validate=config.getboolean("password_validation", "enabled"), validate=config.getboolean("password_validation", "enabled"),
requirements=validator.getCriteria(), requirements=validator.getCriteria(),
email=email, email=email,
username=(not config.getboolean("email", "no_username")),
) )
elif "admin.html" not in path and "admin.html" not in path: elif "admin.html" not in path and "admin.html" not in path:
return app.send_static_file(path) return app.send_static_file(path)

30
poetry.lock generated
View File

@ -189,6 +189,18 @@ version = "0.3.1"
[package.dependencies] [package.dependencies]
pynvim = ">=0.3.1" pynvim = ">=0.3.1"
[[package]]
category = "main"
description = "Core utilities for Python packages"
name = "packaging"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "20.4"
[package.dependencies]
pyparsing = ">=2.0.2"
six = "*"
[[package]] [[package]]
category = "main" category = "main"
description = "comprehensive password hashing framework supporting over 30 schemes" description = "comprehensive password hashing framework supporting over 30 schemes"
@ -259,6 +271,14 @@ six = ">=1.5.2"
docs = ["sphinx", "sphinx-rtd-theme"] docs = ["sphinx", "sphinx-rtd-theme"]
test = ["flaky", "pretend", "pytest (>=3.0.1)"] test = ["flaky", "pretend", "pytest (>=3.0.1)"]
[[package]]
category = "main"
description = "Python parsing module"
name = "pyparsing"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
version = "2.4.7"
[[package]] [[package]]
category = "main" category = "main"
description = "Extensions to the standard Python datetime module" description = "Extensions to the standard Python datetime module"
@ -380,7 +400,7 @@ dev = ["pytest", "pytest-timeout", "coverage", "tox", "sphinx", "pallets-sphinx-
watchdog = ["watchdog"] watchdog = ["watchdog"]
[metadata] [metadata]
content-hash = "f07c7cafa4edc558a016b9b7742290d7f28579b4e350762d2afbdce21f71796b" content-hash = "847ce2a6a3927efdfb3b78935b348e9b4dc63d7e60959af6cc8b9fbc5a24567b"
python-versions = "^3.6" python-versions = "^3.6"
[metadata.files] [metadata.files]
@ -556,6 +576,10 @@ msgpack = [
neovim = [ neovim = [
{file = "neovim-0.3.1.tar.gz", hash = "sha256:a6a0e7a5b4433bf4e6ddcbc5c5ff44170be7d84259d002b8e8d8fb4ee78af60f"}, {file = "neovim-0.3.1.tar.gz", hash = "sha256:a6a0e7a5b4433bf4e6ddcbc5c5ff44170be7d84259d002b8e8d8fb4ee78af60f"},
] ]
packaging = [
{file = "packaging-20.4-py2.py3-none-any.whl", hash = "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"},
{file = "packaging-20.4.tar.gz", hash = "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8"},
]
passlib = [ passlib = [
{file = "passlib-1.7.2-py2.py3-none-any.whl", hash = "sha256:68c35c98a7968850e17f1b6892720764cc7eed0ef2b7cb3116a89a28e43fe177"}, {file = "passlib-1.7.2-py2.py3-none-any.whl", hash = "sha256:68c35c98a7968850e17f1b6892720764cc7eed0ef2b7cb3116a89a28e43fe177"},
{file = "passlib-1.7.2.tar.gz", hash = "sha256:8d666cef936198bc2ab47ee9b0410c94adf2ba798e5a84bf220be079ae7ab6a8"}, {file = "passlib-1.7.2.tar.gz", hash = "sha256:8d666cef936198bc2ab47ee9b0410c94adf2ba798e5a84bf220be079ae7ab6a8"},
@ -578,6 +602,10 @@ pyopenssl = [
{file = "pyOpenSSL-19.1.0-py2.py3-none-any.whl", hash = "sha256:621880965a720b8ece2f1b2f54ea2071966ab00e2970ad2ce11d596102063504"}, {file = "pyOpenSSL-19.1.0-py2.py3-none-any.whl", hash = "sha256:621880965a720b8ece2f1b2f54ea2071966ab00e2970ad2ce11d596102063504"},
{file = "pyOpenSSL-19.1.0.tar.gz", hash = "sha256:9a24494b2602aaf402be5c9e30a0b82d4a5c67528fe8fb475e3f3bc00dd69507"}, {file = "pyOpenSSL-19.1.0.tar.gz", hash = "sha256:9a24494b2602aaf402be5c9e30a0b82d4a5c67528fe8fb475e3f3bc00dd69507"},
] ]
pyparsing = [
{file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"},
{file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"},
]
python-dateutil = [ python-dateutil = [
{file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"}, {file = "python-dateutil-2.8.1.tar.gz", hash = "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c"},
{file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"}, {file = "python_dateutil-2.8.1-py2.py3-none-any.whl", hash = "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"},

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "jellyfin-accounts" name = "jellyfin-accounts"
version = "0.2.2" version = "0.2.3"
readme = "README.md" readme = "README.md"
description = "A simple account management system for Jellyfin" description = "A simple account management system for Jellyfin"
authors = ["Harvey Tindall <harveyltindall@gmail.com>"] authors = ["Harvey Tindall <harveyltindall@gmail.com>"]
@ -29,6 +29,7 @@ pytz = "^2020.1"
python-dateutil = "^2.8.1" python-dateutil = "^2.8.1"
watchdog = "^0.10.2" watchdog = "^0.10.2"
waitress = "^1.4.3" waitress = "^1.4.3"
packaging = "^20.4"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
neovim = "^0.3.1" neovim = "^0.3.1"