def new_user():
"""
Creates a new user
"""
if not request.json:
abort(400)
username = request.json.get('username')
password = request.json.get('password')
name = request.json.get('name')
email = request.json.get('email')
if not username or not password or not name or not email:
abort(400, 'Username, password, name or email is not given.')
if User.query.filter_by(username=username).first() is not None:
abort(400, 'Username is already in use.')
user = User(username=username)
user.hash_password(password)
user.name = name
user.email = email
db.session.add(user)
db.session.commit()
return (jsonify({'username': user.username}), 201,
{'Location': url_for('get_user', id=user.id, _external=True)})
评论列表
文章目录