def register(): username = request.form['username'] password = request.form['password'] confirm = request.form['confirm'] if not username or not password: return make_api_response(message='参数错误:缺少用户名或密码', statusCode=400) if confirm != password: return make_api_response(message='参数错误:两次输入密码不一致', statusCode=400) UserService.register(username=username, password=password) return make_api_response(message='注册成功')
def new_user(): data_schema = UserCreateInputSchema() try: handle_request_validation(data_schema) except ValidationError as err: return jsonify(err.message), 400 return UserService.save(request.get_json())
async def startup(): db_client.create_schema() await db_client.connect() user_service = UserService(db_client.database) await user_service.create_default_superuser(None) party_service = PartyService(db=db_client.database) qadmin_party = await party_service.create_qadmin_party(None) await blockchain_client.init_contracts(db_client.database, qadmin_party)
def post(): error = None user = None code = 201 try: payload = request.get_json() user = UserService.create(payload) except ValidationError as exception: code = 400 error = exception.messages return {'data': user, 'error': error}, code
def login(): username = request.form['username'] password = request.form['password'] if not username or not password: return make_api_response(message='参数错误:缺少用户名或密码', statusCode=400) (result, user) = UserService.login(username, password) if not result: return make_api_response(message='用户名或密码错误', statusCode=400) if not user.is_active: return make_api_response(message='账号已被冻结 请联系管理员', statusCode=400) login_user(user) return make_api_response()
def login(): title = 'Zaloguj się' if request.method == 'POST': username = request.form['username'] password = request.form['password'] user = UserService.get("", username, password) if user is not None: login_user(user) return redirect(url_for("admin")) else: return abort(401) else: return render_template('login.html', title=title)
import pandas as pd from flask import Blueprint, request, jsonify, redirect, Response, make_response from flask.views import MethodView from app import app, db from app.services import UserService userService = UserService() api_blueprint = Blueprint('api', __name__) class UserAPI(MethodView): def get(self): all_users = userService.find_all_users() if (not all_users): response = { 'status': 'error', 'message': 'No users currently registered.' } return make_response(jsonify(response), 404) response = {'status': 'success', 'users': all_users} return make_response(jsonify(response), 200) def delete(self): userService.delete_all_users() userService.commit_action() return Response(status=204)
def get_current_user(): if not is_logged(): return (jsonify({'message': 'Not Authorized'})), 401 return UserService.get_current_user()
def verify_password(pid, password='******'): return UserService.verify_password(pid, password)
def get_auth_token(): return UserService.get_auth_token(request.get_json())
def load_user(userid): return UserService.getById('', userid)
def _get_service(): return UserService(MockUserRepository(None))