commit 657e3e9e2dfa3a4503836bb51e1804b747c81ffb
parent d6196a159087d98e51efa182ee0d252def3b1659
Author: parazyd <parazyd@dyne.org>
Date: Tue, 22 Jan 2019 17:29:59 +0100
Make the initial user the administrator. Everyone following will not have admin caps.
Also update the welcome message.
Diffstat:
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/diaspora.py b/diaspora.py
@@ -218,7 +218,6 @@ def write():
delkey,
Markup(request.form['Story']).striptags()[:127],
]
- print(storyargs)
sql_insert(storyargs)
new_account = False
@@ -445,6 +444,4 @@ if __name__ == '__main__':
help='Debug mode')
args = parser.parse_args()
- make_profile('Diaspora Diaries', 'admin@diasporadiaries.eu')
-
app.run(host=args.l, port=args.p, threaded=True, debug=args.d)
diff --git a/utils.py b/utils.py
@@ -28,7 +28,8 @@ from time import gmtime, strftime, time
from bcrypt import gensalt, hashpw
from flask import Markup
-from db import (sql_select_col_where, sql_insert, sql_delete_row_where)
+from db import (sql_select_col_where, sql_select_col, sql_insert,
+ sql_delete_row_where)
COUNTRYMAP = {}
@@ -228,6 +229,11 @@ def make_profile(name, email):
plain_pw = randomstring(24)
+ # If it's the first user, make them an admin.
+ cap = 2
+ if sql_select_col('id', table='users'):
+ cap = 0
+
# hashed = bcrypt.hashpw(password, bcrypt.gensalt())
# bcrypt.hashpw(plaintext, hashed) == hashed
password = hashpw(plain_pw.encode(), gensalt())
@@ -237,7 +243,7 @@ def make_profile(name, email):
email,
name,
password,
- 2,
+ cap,
int(time()),
0,
]
@@ -246,8 +252,10 @@ def make_profile(name, email):
msgpath = join('messages', email)
makedirs(msgpath, exist_ok=True)
+ # XXX: Unseen in UI because it's not a real user.
+ welcome_msg = "Welcome to Diaspora Diaries! Enjoy your stay :)"
with open(join(msgpath, 'admin@diasporadiaries.eu'), 'w') as msgfile:
- json.dump([{'from': 'Diaspora Diaries', 'message': 'Welcome!',
+ json.dump([{'from': 'Diaspora Diaries', 'message': welcome_msg,
'time': int(time())}], msgfile)
return plain_pw