Exemple #1
0
    def post(self):
        data = parser.parse_args()

        current_user = UserModel.find_username(data['username'])
        if not current_user:
            return {
                'message': 'User {} doesn\'t exist'.format(data['username'])
            }

        if UserModel.verify_hash(data['password'], current_user.password):
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'Logged in as {}'.format(current_user.username),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        else:
            return {'message': 'Wrong Password'}
Exemple #2
0
 def post(self):
     data = parser.parse_args()
     current_user = UserModel.find_username(data['username'])
     if not current_user:
         return jsonify(
             {"Message": "User {} not found".format(data['username'])})
     if UserModel.verify_hash(data['password'], current_user.password):
         access_token = create_access_token(identity=data['username'])
         refresh_token = create_refresh_token(identity=data['username'])
         return jsonify({
             'Message':
             'Login of user {} is successful'.format(data['username']),
             "access_token":
             access_token,
             "refresh_token":
             refresh_token
         })
     else:
         return jsonify({'Message': 'wrong credentials'})
Exemple #3
0
    def post(self):
        data = parser.parse_args()

        if UserModel.find_username(data['username']):
            return {
                'message': 'User {} already exists'.format(data['username'])
            }

        new_user = UserModel(username=data['username'],
                             password=UserModel.generate_hash(
                                 data['password']))
        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])
            return {
                'message': 'User {} was created'.format(data['username']),
                'access_token': access_token,
                'refresh_token': refresh_token
            }
        except:
            return {'message': 'Something went wrong'}, 500
Exemple #4
0
    def post(self):
        data = parser.parse_args()
        new_user = UserModel(data['username'],
                             UserModel.generate_hash(data['password']))
        if UserModel.find_username(data['username']):
            return jsonify(
                {'Message': "{} user already exists".format(data['username'])})

        try:
            new_user.save_to_db()
            access_token = create_access_token(identity=data['username'])
            refresh_token = create_refresh_token(identity=data['username'])

            return jsonify({
                "Message":
                "{} who is a new user has been added.".format(
                    data['username']),
                "access_token":
                access_token,
                "refresh_token":
                refresh_token
            })
        except:
            return jsonify({'Message': "There was an error adding the user"})