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:
|
2021-04-26 15:03:18 +00:00
|
|
|
:parameter email: The user's email
|
|
|
|
:parameter password: The users's password
|
|
|
|
:parameter username: The users's username
|
2021-04-22 16:46:41 +00:00
|
|
|
: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-27 22:51:31 +00:00
|
|
|
new_user = User(email=request.json.get("email"), password=gen_password(request.json.get("password")),
|
2021-04-28 17:55:59 +00:00
|
|
|
username=request.json.get("username"))
|
2021-04-27 22:51:31 +00:00
|
|
|
Base.session.add(new_user)
|
2021-04-22 16:46:41 +00:00
|
|
|
Base.session.commit()
|
2021-04-27 22:51:31 +00:00
|
|
|
return json_success(new_user.to_json())
|