Ejemplo n.º 1
0
    def post(self):
        json_data = request.get_json()
        
        if not json_data:
            return {'message': 'No input data provided'}

        user_data = user_schema.load(json_data)

        if not UserModel.find_by_username(username=user_data['username']):
            return {'message': 'Username is not exists'}

        user_ = user_schema.dump(UserModel.find_by_username(username=user_data['username']))
        
        if Utils.decrypt_pass(user_data['password'], user_['password']):
            access_token = create_access_token(user_['username'])
            refresh_token = create_refresh_token(user_['username'])

            return {
                'message': "Login successful!",
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        else:
            return {
                'message': 'Username or password wrong!'
            }
Ejemplo n.º 2
0
    def post(self):
        json_data = request.get_json()
        if not json_data:
            return {'message': 'No data input provided'}

        if user_schema.dump(UserModel.find_by_username(json_data['username'])):
            return {'message': 'Username is already exists'}

        user = UserModel(username=json_data['username'],
                         password=Utils.encrypt_pass(json_data['password']))

        user.add()
        res = user_schema.dump(user)

        return {'result': res}