2021-04-22 16:46:41 +00:00
|
|
|
from flask import render_template, abort, jsonify, request
|
|
|
|
from ...database import *
|
|
|
|
from flask_jwt_extended import jwt_required
|
|
|
|
from ...gestione import *
|
2021-04-25 13:41:27 +00:00
|
|
|
from flask_cors import cross_origin
|
2021-04-22 16:46:41 +00:00
|
|
|
|
2021-04-25 13:41:27 +00:00
|
|
|
|
|
|
|
@cross_origin()
|
2021-04-22 16:46:41 +00:00
|
|
|
@jwt_required()
|
|
|
|
def page_user_create():
|
|
|
|
"""
|
|
|
|
The API call that allows to create new users. It requires:
|
|
|
|
:form email: The user's email
|
|
|
|
:form password: The users's password
|
|
|
|
:form username: The users's username
|
|
|
|
:return: Json-formatted data. If something goes wrong, it returns a
|
2021-04-25 13:41:27 +00:00
|
|
|
{'result':'failure', 'content':'something blew up'}, else it returns {'result':'success', 'content':newUser.to_json().
|
2021-04-22 16:46:41 +00:00
|
|
|
"""
|
|
|
|
user = find_user(get_jwt_identity())
|
|
|
|
if not user.isAdmin:
|
|
|
|
abort(403)
|
2021-04-25 13:41:27 +00:00
|
|
|
nUser = User(email=request.json.get("email"), password=gen_password(request.json.get("password")),
|
|
|
|
username=request.json.get("username"))
|
2021-04-22 16:46:41 +00:00
|
|
|
Base.session.add(nUser)
|
|
|
|
Base.session.commit()
|
2021-04-25 13:41:27 +00:00
|
|
|
return jsonify({"result": "success", "content": user.to_json()})
|