From 190a4357dc9aa386299074f073ceac97b5f69a78 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Thu, 10 May 2018 16:45:45 +0200
Subject: [PATCH] Fix #198: Removed Python 3.6 dependency (secrets module)

---
 api/funkwhale_api/users/models.py | 9 +++++++--
 changes/changelog.d/198.bugfix    | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
 create mode 100644 changes/changelog.d/198.bugfix

diff --git a/api/funkwhale_api/users/models.py b/api/funkwhale_api/users/models.py
index 773d60f3..f067a2a8 100644
--- a/api/funkwhale_api/users/models.py
+++ b/api/funkwhale_api/users/models.py
@@ -1,8 +1,9 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals, absolute_import
 
+import binascii
+import os
 import uuid
-import secrets
 
 from django.conf import settings
 from django.contrib.auth.models import AbstractUser
@@ -14,6 +15,10 @@ from django.utils.translation import ugettext_lazy as _
 from funkwhale_api.common import fields
 
 
+def get_token():
+    return binascii.b2a_hex(os.urandom(15)).decode('utf-8')
+
+
 @python_2_unicode_compatible
 class User(AbstractUser):
 
@@ -58,7 +63,7 @@ class User(AbstractUser):
         return self.secret_key
 
     def update_subsonic_api_token(self):
-        self.subsonic_api_token = secrets.token_hex(32)
+        self.subsonic_api_token = get_token()
         return self.subsonic_api_token
 
     def set_password(self, raw_password):
diff --git a/changes/changelog.d/198.bugfix b/changes/changelog.d/198.bugfix
new file mode 100644
index 00000000..dd2f4e8f
--- /dev/null
+++ b/changes/changelog.d/198.bugfix
@@ -0,0 +1 @@
+Removed Python 3.6 dependency (secrets module) (#198)
-- 
GitLab