Esempio n. 1
0
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='注册成功')
Esempio n. 2
0
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())
Esempio n. 3
0
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)
Esempio n. 4
0
 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
Esempio n. 5
0
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()
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
def get_current_user():
    if not is_logged():
        return (jsonify({'message': 'Not Authorized'})), 401
    return UserService.get_current_user()
Esempio n. 9
0
def verify_password(pid, password='******'):
    return UserService.verify_password(pid, password)
Esempio n. 10
0
def get_auth_token():
    return UserService.get_auth_token(request.get_json())
Esempio n. 11
0
def load_user(userid):
    return UserService.getById('', userid)
Esempio n. 12
0
 def _get_service():
     return UserService(MockUserRepository(None))