Ejemplo n.º 1
0
# -*- coding: utf-8 -*-
from flask import current_app, jsonify

from app.lib.redprint import Redprint
from app.model.user import User
from app.validator.form import UserLoginForm
from itsdangerous import TimedJSONWebSignatureSerializer

api = Redprint('token')


@api.route('', methods=['POST'])
def get_token():
    # 验证输入格式
    form = UserLoginForm().execute_validate()
    # 验证账号,成果即返回{email,scope}
    user_info = User.verify(form['email'], form['password'])
    expiration = current_app.config['TOKEN_EXPIRATION']
    token = generator_token(user_info, expiration)
    result = {
        'email': user_info['email'],
        'token': token.decode('ascii')
    }
    return jsonify(result)


def generator_token(user_info, expiration=3600):
    # 生成令牌
    s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY'], expires_in=expiration)
    return s.dumps({
        'email': user_info['email'],
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
from flask import Response, jsonify

from app.lib.auth import auth
from app.lib.error_code import DatabaseError, Success
from app.lib.permission import Permission, Ring
from app.lib.redprint import Redprint
from app.model.mock import Mock
from app.model.project import Project
from app.schema.schema import MockSchema
from app.validator.form import CreateMockForm

api = Redprint('mock')


# 获取单个mock的信息
@api.route('/<int:id>', methods=['GET'])
def get_mock(id):
    mock = Mock.fetch_mock(mock_id=id)
    mock_schema = MockSchema()
    data = mock_schema.dump(mock).data
    data['user'] = mock.user.email
    data['project'] = mock.project.name
    # 所有项目
    projects = Project.fetch_all()
    project_list = []
    for project in projects:
        project_list.append(project.name)

    data['projects'] = project_list
Ejemplo n.º 3
0
# -*- coding: utf-8 -*-
from app.lib.auth import auth
from app.lib.error_code import Success, ParameterException, DatabaseError
from app.lib.permission import Permission, Ring
from app.lib.redprint import Redprint
from app.model.user import User
from app.validator.form import UserRegisterForm, PromotePrivilegeForm
from app.lib.orm import db

api = Redprint("user")


# 注册用户
@api.route('', methods=['POST'])
def register():
    form = UserRegisterForm().execute_validate()
    result = User.register_by_email(form['email'], form['password'])
    if result:
        return Success()
    else:
        return DatabaseError()


# 禁用用户
@api.route('/<string:email>', methods=['DELETE'])
@auth.login_required
@Permission.require(Ring.Administrator)
def ban_user(email):
    User.delete('email', email)
    return Success()
Ejemplo n.º 4
0
"""
 Created by YefanSulayman on 2020/3/31 16:14.
"""
from app.lib.redprint import Redprint

__author__ = 'YefanSulayman'

api = Redprint('book')


@api.route('', methods=['GET'])
def book():
    return {'book': 'quran'}
Ejemplo n.º 5
0
"""
 Created by YefanSulayman on 2020/3/31 17:34.
"""
from flask import request

from app.lib.enums import ClientTypeEnum
from app.lib.redprint import Redprint
from app.models.user import User
from app.validators.forms import ClitentForm

__author__ = 'YefanSulayman'

api = Redprint('client')


@api.route('register', methos=['POST'])
def create_client():
    data = request.json
    # 如果时json 的话 需要data=data 才行
    form = ClitentForm(data=data)
    if form.validate():
        promise = {
            ClientTypeEnum.USER_EMAIL: __register_user_by_email(form),
            ClientTypeEnum.USER_MINA: __register_user_by_mini
        }


def __register_user_by_email(form):
    # form 中没有nickname
    User.register_by_email(,form.account.data,form.secret.data)
    pass
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
from flask import jsonify

from app.lib.auth import auth
from app.lib.error_code import DatabaseError, Success
from app.lib.permission import Ring, Permission
from app.lib.redprint import Redprint
from app.model.project import Project
from app.schema.schema import ProjectSchema, MockSchema
from app.validator.form import CreateProjectForm

api = Redprint('project')


# 创建一个项目
@api.route('', methods=['POST'])
@auth.login_required
@Permission.require(Ring.Member)
def create_project():
    form = CreateProjectForm().execute_validate()
    result = Project.insert(form['name'], form['desc'])
    if result:
        return Success()
    else:
        return DatabaseError()


# 获取一个项目的信息
@api.route('/<int:id>', methods=['GET'])
def get_project(id):
    project = Project.fetch_project(id)
Ejemplo n.º 7
0
"""
 Created by YefanSulayman on 2020/3/31 16:14.
"""
from app.lib.redprint import Redprint

__author__ = 'YefanSulayman'

api = Redprint('user')


@api.route('', methods=['GET'])
def get_user():
    return {'user': '******'}