示例#1
0
    def post(self):
        json_data = request.get_json(force=True)
        username = json_data.get('username')
        password = json_data.get('password')

        # Username is empty
        if is_empty(username):
            return request_return('username is null', 'none')
        # Password is empty
        if is_empty(password):
            return request_return('password is null', 'none')
        # Post data format is right
        else:
            user = User.query.filter_by(username=username).first()
            # User is exist
            if user is not None:
                # Argument must be hash password
                user_password = User(password_hash=user.password_hash)
                # Check login password
                if not user_password.verify_password(password):
                    return request_return('wrong password', 'none')
                # Login success, return token auth
                else:
                    return request_return(
                        {
                            'status': 'login success',
                            'data': Token(user.username).generate_auth_token()
                        }, 'success')
            # User is not exist in the database
            else:
                return request_return(
                    'user is not exist, please register first', 'none')
示例#2
0
    def post(self):
        token = request.headers.get('token')
        result_data = check_token({
            'token': token,
            'data': {}
        }, TaskListApi.new_task)

        return request_return(result_data['data'], result_data['code'])
示例#3
0
 def get(self, id):
     token = request.headers.get('token')
     result_data = check_token({
         'token': token,
         'data': {
             'id': id
         }
     }, self.get_task)
     return request_return(result_data['data'], result_data['code'])
示例#4
0
    def delete(self, task_id):
        token = request.headers.get('token')
        result_data = check_token(
            {
                'token': token,
                'data': {
                    'task_id': task_id
                }
            }, TaskApi.delete_task)

        return request_return(result_data['data'], result_data['code'])
示例#5
0
    def post(self):
        json_data = request.get_json(force=True)
        username = json_data.get('username')
        password = json_data.get('password')

        # Username is empty
        if is_empty(username):
            return request_return('username is null', 'none')
        # Password is empty
        if is_empty(password):
            return request_return('password is null', 'none')
        # User is already exist
        elif User.query.filter_by(username=username).first() is not None:
            return request_return('user is already exist', 'exist')
        # Register new user
        else:
            user = User(username=username)
            user.hash_password(password)
            user.save_to_db()
            return request_return('register success', 'success')
示例#6
0
    def get(self):
        token = request.headers.get('token')
        # if per_page is None, set default value 1
        page = request.args.get('page', 1, type=int)
        # if per_page is None, set default value 10
        per_page = request.args.get('per_page', 10, type=int)

        result_data = check_token(
            {
                'token': token,
                'data': {
                    'page': page,
                    'per_page': per_page
                }
            }, TaskListApi.get_task_list)

        return request_return(result_data['data'], result_data['code'])