def bulk_add_shelters():
    for name in shelter_names:
        data = {
            "name": name,
            "_id": db_opp.create_uuid(),
            "phone": "1234567890",
            "email": "*****@*****.**",
            "address": "123 Fake Street",
            "city": "Screwston",
            "state": "Tejas"
        }
        db_opp.add_new_shelter(data)
Example #2
0
    def post(self):
        name = self.get_body_argument('name', None)
        email = self.get_body_argument('email', None)
        phone = self.get_body_argument('phone', None)
        address = self.get_body_argument('address', None)

        data = {
            "_id": db_opp.create_uuid(),
            "name": name,
            "email": email,
            "phone": phone,
            "address": address
        }
        db_opp.add_new_shelter(data)

        self.redirect("/profile")
def bulk_add_dogs():
    for name in dog_names:
        _id = db_opp.create_uuid()
        data = {
            "_id": _id,
            "name": name,
            "image": get_thumbnail(),
            "breed": get_breed(),
            "id_chip": "234234lkj234lkj234lkj",
            "age": get_age(),
            "date_found": get_date(),
            "location_found": "Houston",
            "prim_color": get_color(),
            "sec_color": get_color(),
            "height": get_height_weight(),
            "weight": get_height_weight(),
            "gender": get_bool("gend"),
            "fix": get_bool("bool"),
            "collar": get_bool("bool"),
            "collar_color": get_color(),
            "ear_type": get_ears(),
            "eye_color": get_color(),
            "notes": get_note(),
            "delete": False,
            "user_id": get_user(),
            "shelter_id": get_shelter()
        }

        db_opp.add_new_dog(data)

        dog = dogs.find({"_id": _id})

        for dog in dog:
            name = dog['name']
            gender = dog['gender']
            if gender == "male":
                gender = "He"
            else:
                gender = "She"
            breed = dog['breed']
            age = dog['age']
            print("Added {} to the DB. {} is a {} year old {}.".format(
                name, gender, age, breed))
Example #4
0
    def post(self):
        # import io
        # from PIL import Image

        file_path = db_opp.upload_dog_image(self.request.files['my_File'][0])

        # file_all =
        # file_name = file_all['filename']
        # file_body = file_all['body']
        #
        # import os
        #
        # file_path = os.path.join('static/img/dog_images/', file_name)
        # if not os.path.exists('static/img/dog_images/'):
        #     os.makedirs('static/img/dog_images/')
        # print(file_path)
        # with open(file_path, 'wb') as f:
        #     f.write(file_body)
        # f.closed

        # # File_Name = File_All.name
        #
        # print(File_Body)
        # # print("+" * 10)
        # # print(File_Name)
        #
        # img = Image.open(io.StringIO(File_Body))
        # import boto3
        # s3 = boto3.resource('s3')
        # bucket = s3.Bucket('images.findmypup.com')
        # obj = bucket.Object('mykey')
        #
        # with open(img, 'rb') as data:
        #     obj.upload_fileobj(data)
        # file_name = self.request.files['my_File'][0]['filename']

        # import boto3
        # s3 = boto3.client('s3')
        # bucket_name = 'images.findmypup.com'
        # s3.upload_file(file_path, bucket_name, file_name)

        # import base64
        # import json
        # image_64_encode = base64.encodestring(file_body)
        # print(image_64_encode)
        #
        user = db_opp.find_user_by_email(self.current_user.decode('utf-8'))
        data = {
            "_id": db_opp.create_uuid(),
            "name": self.get_body_argument('name'),
            "image": file_path,
            "breed": self.get_body_argument('breed').lower(),
            "id_chip": self.get_body_argument('id_chip'),
            "age": self.get_body_argument('age'),
            "date_found":datetimeconverter( self.get_body_argument('date_found')),
            "location_found": self.get_body_argument('location_found'),
            "prim_color": self.get_body_argument('prim_color').lower(),
            "sec_color": self.get_body_argument('sec_color').lower(),
            "height": self.get_body_argument('height'),
            "weight": self.get_body_argument('weight'),
            "gender": self.get_body_argument('gender', None),
            "fix": self.get_body_argument('fix', None),
            "collar": self.get_body_argument('collar', None),
            "collar_color": self.get_body_argument('collar_color').lower(),
            "ears": self.get_body_argument('ears').lower(),
            "eyes": self.get_body_argument('eyes').lower(),
            "notes": self.get_body_argument('notes'),
            "delete": False,
            "user_id": user['_id'],
            "shelter_id": user['shelter_id']
        }
        print(data)
        db_opp.add_new_dog(data)
        self.redirect('/dogs')
Example #5
0
    def get(self):
        # TRY: REMEMBER WHERE USER WANTED TO GO
        # request = self.request.headers.get("Referer")
        # question = request.find('=')
        # next_path = request[question+1:]
        # Set host: used for compatibility with localhost and external servers.
        host = self.request.host
        # if there is a code in the url
        if self.get_argument('code', False):
            print("code does not exist")
            # check if user is already authenticated
            user = yield self.get_authenticated_user(redirect_uri="http://{}/login-google".format(host),
                code= self.get_argument('code'))
            # if not, then there should not be a code and we throw error.
            if not user:
                self.clear_all_cookies()
                print("ERROR 500")
                raise tornado.web.HTTPError(500, 'Google authentication failed')

            # send the user back to google auth to reverify their token
            # take whatever access token is set in the browser
            access_token = str(user['access_token'])
            # send user to google authentication server
            http_client = self.get_auth_http_client()
            # load response
            response =  yield http_client.fetch('https://www.googleapis.com/oauth2/v1/userinfo?access_token='+access_token)
            # if there is no response... something went wrong
            if not response:
                self.clear_all_cookies()
                raise tornado.web.HTTPError(500, 'Google authentication failed')
            # If you are here, then google responded, continue reading the response
            user = json.loads(response.body)
            # unpack the info google sent
            name = user['name']
            given_name = user['given_name']
            family_name = user['family_name']
            email = user['email']
            avatar = user['picture']
            user_id = user["id"]

            # google says they are cool, and we believe them
            # save user here, save to cookie or database
            ###################################################################
            #   WRITE NEW USER TO DB                                          #
            ###################################################################
            #        WRITE USER WITH POSTGRES                                 #
            ###################################################################
            # If user does not exists by id in DB, create a user for them..
            # redirect to complete profile

            if db_opp.find_user_by_email(email):
                current_user = db_opp.find_user_by_email(email)
                self.set_secure_cookie('user', current_user['email'])
                self.redirect("/profile")

            else:
                data = {
                "_id": db_opp.create_uuid(),
                "given_name": given_name,
                "family_name": family_name,
                "email": email,
                "avatar": avatar,
                "type": "not_set",
                "shelter_id": "not_set"
                }
                db_opp.add_new_user(data)

                self.set_secure_cookie('user', email)
                self.redirect("/complete-profile")
                print("added user to db")

            return
        # cookie exists, forward user to site
        elif self.get_secure_cookie('user'):
            print("secure cookie exists.")
            self.redirect('/profile')
            return
        # no code, no cookie, try to log them in... via google oauth
        else:
            print("redirect to google")
            yield self.authorize_redirect(
                redirect_uri="http://{}/login-google".format(host),
                client_id= self.settings['google_oauth']['key'],
                scope=['email'],
                response_type='code',
                extra_params={'approval_prompt': 'auto'})
def add_dog_breeds():
    for breed in dog_breeds:
        breeds.insert_one({"id": db_opp.create_uuid(), "value": breed})