Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xme committed May 18, 2018
1 parent dabafbc commit 171f92c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,19 @@ def post(self):
writeLog('[ERROR] Users database already initialized')
return Response(json.dumps([{ "message" : "The users database has already been initialized" }]), mimetype='application/json')

# Generate a random 10 characters password
m = hashlib.md5()
m.update(''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)).encode('utf-8'))
password = m.hexdigest()
request_json = request.get_json(force=True)
password = request_json.get('password')
if password is None:
# Generate a random 10 characters password
password = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)).encode('utf-8')

user = User(username = username)
user.hash_password(password)
db.session.add(user)
db.session.commit()

writeLog('[INFO] Users database successfully initialized')
return Response(json.dumps([{ "message" : "Users database successfully initialized" }]), mimetype='application/json')
return Response(json.dumps([{ "message" : "Users database successfully initialized" }, {"password" : password}]), mimetype='application/json')

class AddUser(Resource):

Expand Down Expand Up @@ -453,9 +454,7 @@ def post(self):

if password is None:
# Generate a random 10 characters password
m = hashlib.md5()
m.update(''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)).encode('utf-8'))
password = m.hexdigest()
passsword = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)).encode('utf-8')

if User.query.filter_by(username = username).first() is not None:
writeLog('[ERROR] Users already exists: %s' % username)
Expand Down Expand Up @@ -506,9 +505,7 @@ def post(self):

if newpassword is None:
# Generate a random 10 characters password
m = hashlib.md5()
m.update(''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)).encode('utf-8'))
newpassword = m.hexdigest()
newpassword = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)).encode('utf-8')

if User.query.filter_by(username = username).first() is None:
writeLog('[ERROR] Users %s do not exist: %s' % username)
Expand Down

0 comments on commit 171f92c

Please sign in to comment.