Example #1
0
    def post(self, folder_name, generate_flag):
        current_user_id = get_current_user_id()
        current_user = db_user_service.get_user_by_id(current_user_id)
        uploaded_urls = []

        if current_user:
            for key in request.files:
                uploaded_file = request.files.get(key)
                bucket_name = get_config_var('AWS_BUCKET_NAME')
                upload_result = aws_s3_service.upload_file(
                    uploaded_file, bucket_name, folder_name, generate_flag)
                if upload_result.get('result') == True:
                    # Use this code to screen the actual address
                    #    public_file_url = '/pic/{0}/{1}'.format(folder_name, upload_result.get('file_name'))
                    uploaded_urls.append(upload_result.get('file_url'))
                else:
                    return jsonify({
                        'result': False,
                        'error': 'Could not upload files...'
                    })
            return jsonify({
                'result': True,
                'file_urls': uploaded_urls
                #'file_name': upload_result.get('file_name')
            })
        return jsonify({'result': False, 'error': 'Cannot find user.'})
Example #2
0
 def post(self):
     current_user_id = get_current_user_id()
     current_user = db_user_service.get_user_by_id(current_user_id)
     if current_user:
         try:
             password = password_api.payload.get('password')
             new_password = password_api.payload.get('new_password')
             if current_user.verify_hash(password):
                 current_user.set_password(new_password)
                 current_user.save()
             else:
                 return jsonify({
                     'result': False,
                     'error': 'You are not authorized to change the password.'
                 })
         except Exception as ex:
             # to-do: log exception, for not just print it
             print('ERROR while saving new password')
             print(ex)
             return jsonify({
                 'result': False,
                 'error': 'Can not save a new password. Please refresh the page and try again.'
             })
         return jsonify({
             'result': True
         })
     return jsonify({
         'result': False,
         'error': 'Cannot find user.'
     })
Example #3
0
 def get(self):
     current_user_id = get_current_user_id()
     current_user = db_user_service.get_user_by_id(current_user_id)
     if current_user:
         return jsonify({
             'result': True,
             'username': current_user.username,
             'email': current_user.email
         })
     return jsonify({
         'result': False,
         'error': 'Cannot find user.'
     })
Example #4
0
    def delete(self, folder_name):
        current_user_id = get_current_user_id()
        current_user = db_user_service.get_user_by_id(current_user_id)
        bucket_name = get_config_var('AWS_BUCKET_NAME')
        if current_user:
            # Add additional checking preventing abuse deletion
            delete_result = aws_s3_service.delete_file(
                bucket_name, folder_name, uploader_api.payload.get('url'))
            return jsonify({
                'result': delete_result.get('result'),
                'error': delete_result.get('error')
            })

        return jsonify({'result': False, 'error': 'Cannot find user.'})
Example #5
0
 def post(self):
     current_user_id = get_current_user_id()
     current_user = db_user_service.get_user_by_id(current_user_id)
     if current_user:
         try:
             current_user.username = profile_api.payload.get('username')
             current_user.save()
         except Exception as ex:
             # to-do: log exception, for not just print it
             print('ERROR while saving profile')
             print(ex)
             return jsonify({
                 'result': False,
                 'error': 'Can not save user.'
             })
         return jsonify({
             'result': True
         })
     return jsonify({
         'result': False,
         'error': 'Cannot find user.'
     })