Пример #1
0
    def post(self):
        data = dict()
        for key in request.form:
            data[key] = request.form[key]
        if not Influencer.objects(email=data['email']):
            return make_response(
                jsonify(role='influencer',
                        message='Influencer does not exist in database'),
                status.HTTP_404_NOT_FOUND)
        else:
            influencer = Influencer.objects(email=data['email']).first()
            file = request.files['file']
            filename = secure_filename(file.filename)
            fileLocation = os.path.join('static/uploads/influencer_campaign/',
                                        filename)
            file.save(fileLocation)
            influencer.campaignImages = '/' + fileLocation

            for key in data:
                if key == 'campaignImages':
                    continue
                else:
                    influencer[key] = data[key]
            influencer.save()
            if 'password' in data:
                User(email=data['email'],
                     password=User.generate_hash(data['password']),
                     role='influencer').save()
            return make_response(
                jsonify(
                    role='influencer',
                    message=
                    'Influencer Campaign details updated successfully in database'
                ), status.HTTP_200_OK)
Пример #2
0
    def post(self):
        data = dict()
        data['email'] = request.form['email']

        if not Influencer.objects(email=data['email']):
            return make_response(
                jsonify(role='influencer',
                        message='Influencer does not exist in database'),
                status.HTTP_404_NOT_FOUND)
        else:
            influencer = Influencer.objects(email=data['email']).first()
            file = request.files['file']
            filename = secure_filename(file.filename)
            fileLocation = os.path.join(
                'static/uploads/influencer_profile_pictures/', filename)
            file.save(fileLocation)
            influencer.image = '/' + fileLocation
            influencer.save()
            User(email=data['email'],
                 password=User.generate_hash(data['password']),
                 role='influencer').save()
            return make_response(
                jsonify(role='influencer',
                        message=
                        'Influencer details updated successfully in database'),
                status.HTTP_200_OK)
Пример #3
0
    def post(self):
        data = request.get_json(force=True)
        if Admin.objects(email=data['email']):
            return make_response(
                jsonify(role='admin',
                        message='Email Address: ' + data['email'] +
                        ' already exists!'), status.HTTP_409_CONFLICT)
        else:

            admin = Admin(email=data['email'],
                          password=Admin.generate_hash(
                              data['password'])).save()
            User(email=data['email'],
                 password=User.generate_hash(data['password']),
                 role='admin').save()
            try:
                return make_response(
                    jsonify(role='admin',
                            message='admin added successfully in database',
                            email=data['email']), status.HTTP_201_CREATED)
            except:
                return make_response(
                    jsonify(role='admin',
                            message='Admin registration failed!'),
                    status.HTTP_500_INTERNAL_SERVER_ERROR)
Пример #4
0
    def put(self):
        data = dict()
        for key in request.form:
            data[key] = request.form[key]
        if not Brand.objects(email=data['email']):
            return make_response(
                jsonify(role='brand',
                        message='brand does not exist in database'),
                status.HTTP_404_NOT_FOUND)
        else:
            brand = Brand.objects(email=data['email']).first()
            file = request.files['file']
            filename = secure_filename(file.filename)
            fileLocation = os.path.join('static/uploads/brand_profile/',
                                        filename)
            file.save(fileLocation)
            brand.image = '/' + fileLocation

            for key in data:
                if key == 'image':
                    continue
                else:
                    brand[key] = data[key]
            brand.save()
            if 'password' in data:
                user = User.objects(email=data['email']).first()
                user.password = User.generate_hash(data['password'])
                user.save()
            return make_response(
                jsonify(
                    role='brand',
                    message='brand details updated successfully in database'),
                status.HTTP_200_OK)
Пример #5
0
 def post(self):
     data = request.get_json(force=True)
     user = User.objects(email=data['email']).first()
     if user:
         if User.verify_hash(data['password'], user['password']):
             user.authenticated = True
             user.save()
             access_token = create_access_token(identity=data['email'])
             refresh_token = create_refresh_token(identity=data['email'])
             temp = {}
             if user['role'] == 'influencer':
                 influencer = Influencer.objects(
                     email=data['email']).first()
                 temp['first_name'] = influencer.first_name
                 temp['last_name'] = influencer.last_name
                 temp['email'] = influencer.email
                 temp[
                     'big_deal_on_option1'] = influencer.big_deal_on_option1
                 temp[
                     'big_deal_on_option2'] = influencer.big_deal_on_option2
                 temp[
                     'big_deal_on_option3'] = influencer.big_deal_on_option3
                 temp[
                     'big_deal_on_option4'] = influencer.big_deal_on_option4
                 temp[
                     'big_deal_on_option5'] = influencer.big_deal_on_option5
                 temp[
                     'website_social_media_handles'] = influencer.website_social_media_handles
                 temp['followers'] = influencer.followers
                 temp['areas_of_interest'] = influencer.areas_of_interest
                 temp['gender'] = influencer.gender
                 temp['dob'] = influencer.dob
             elif user['role'] == 'brand':
                 brand = Brand.objects(email=data['email']).first()
                 temp['company_name'] = brand.company_name
                 temp['email'] = brand.email
                 temp['address'] = brand.address
                 temp['isapproved'] = brand.isapproved
                 temp['isactive'] = brand.isactive
             elif user['role'] == 'admin':
                 admin = Admin.objects(email=data['email']).first()
                 temp['email'] = admin.email
             return make_response(
                 jsonify(role=user['role'],
                         email=temp['email'],
                         userobject=temp,
                         message='login successful!',
                         access_token=access_token,
                         refresh_token=refresh_token), status.HTTP_200_OK)
         else:
             return make_response(
                 jsonify(role=user['role'], message='Incorrect password!'),
                 status.HTTP_401_UNAUTHORIZED)
     else:
         return make_response(jsonify(message='Email not found'),
                              status.HTTP_404_NOT_FOUND)
Пример #6
0
    def post(self):
        data = request.get_json()
        if Influencer.objects(email=data['email']):
            return make_response(jsonify(role='influencer', message='Influencer already exists in the database'),
                                 status.HTTP_409_CONFLICT)
        else:
            influencer = Influencer()
            for key in data:
                influencer[key] = data[key]
            influencer.save()
            User(
                email=data['email'],
                password=User.generate_hash(data['password']),
                role='influencer'
            ).save()

            return make_response(jsonify(role='influencer', message='Influencer added to the database'),
                                 status.HTTP_201_CREATED)
Пример #7
0
    def post(self):
        data = request.get_json(force=True)
        if Brand.objects(email=data['email']):
            return make_response(
                jsonify(role='brand',
                        message='brand already exists in database'),
                status.HTTP_409_CONFLICT)
        else:
            Brand(company_name=data['company_name'],
                  address=data['address'],
                  email=data['email'],
                  password=data['password'],
                  confirm_password=data['confirm_password']).save()

            User(email=data['email'],
                 password=User.generate_hash(data['password']),
                 role="brand").save()

            return make_response(
                jsonify(role='brand',
                        message='brand added successfully in database'),
                status.HTTP_201_CREATED)
Пример #8
0
 def post(self):
     data = request.get_json(force=True)
     if not Influencer.objects(email=data['email']):
         return make_response(
             jsonify(role='admin',
                     message='influencer does not exist in database'),
             status.HTTP_404_NOT_FOUND)
     else:
         user = Influencer.objects(email=data['email']).first()
         user.delete()
         user = User.objects(email=data['email']).first()
         user.delete()
         return make_response(
             jsonify(role='admin',
                     message='influencer has been removed from database'),
             status.HTTP_200_OK)
Пример #9
0
# read config details into configFile dictionary
configFile = open("config.txt")
config = dict()
for line in configFile:
    arr = line[:-1].split("=")
    config[arr[0]] = arr[1]
configFile.close()
connect(config['dbname'], host=config['host'])
defaultAdminEmail = "*****@*****.**"
defaultAdminPassword = "******"

# add default admin for this system
if not Admin.objects(email=defaultAdminEmail):
    Admin(email=defaultAdminEmail,password=Admin.generate_hash(defaultAdminPassword)).save()
    User(email=defaultAdminEmail,password=User.generate_hash(defaultAdminPassword),role='admin').save()

@app.route("/")
def hello():
    return send_file('templates/index.html')

@jwt.token_in_blacklist_loader
def check_if_token_in_blacklist(decrypted_token):
    print('In check_if_token_in_blacklist...', decrypted_token['jti'])
    jti = decrypted_token['jti']
    return RevokedToken.is_jti_blacklisted(jti)


api.add_resource(BrandAPI, '/brand')
api.add_resource(BrandGetProfileDetails, '/brand/getProfileDetails')
api.add_resource(UserSignInAPI, '/user/signin')