def create(): if not request.json or 'username' not in request.json or 'password_hash' not in request.json: return jsonify(BAD_REQUEST), 401 account = Account(username=request.json['username'], password_hash=request.json['password_hash']) account.save() token = encodeAuthToken(account.pk) return jsonify({'status': 'success', 'auth_token': str(token)})
def login(): if not request.json or 'email' not in request.json or 'password' not in request.json: return jsonify(BAD_REQUEST), 401 account = Account.login(request.json['email'], request.json['password']) if not account: return jsonify(UNAUTHORIZED), 401 token = encodeAuthToken(account.pk) return jsonify({'status': 'success', 'auth_token': str(token)})