Esempio n. 1
0
    def post(self):
        user = db_opp.find_user_by_email(self.current_user.decode("utf-8"))

        _id = self.get_body_argument('_id')
        data = {}

        if not self.request.files:
            print("no files")
            pass
        else:
            data['image'] = db_opp.upload_dog_image(self.request.files['my_File'][0])

        ######################################################################

        data["name"] = self.get_body_argument('name')
        data["gender"] = self.get_body_argument('gender', None)
        data["collar"] = self.get_body_argument('collar', None)
        data["collar_color"] = self.get_body_argument('collar_color').lower()
        data["fix"] = self.get_body_argument('fix', None)
        data["breed"] = self.get_body_argument('breed').lower()
        data["location_found"] = self.get_body_argument('location_found')
        data["prim_color"] = self.get_body_argument('prim_color').lower()
        data["sec_color"] = self.get_body_argument('sec_color').lower()
        data["height"] = self.get_body_argument('height')
        data["weight"] = self.get_body_argument('weight')
        data["eyes"] = self.get_body_argument('eyes').lower()
        data["ears"] = self.get_body_argument('ears').lower()
        data["age"] = self.get_body_argument('age')
        data["notes"] = self.get_body_argument('notes')
        data["id_chip"] = self.get_body_argument('id_chip')

        db_opp.update_dog_by_id(_id, data)
        self.redirect('/dogs/' + _id)
Esempio n. 2
0
    def get(self):
        user = db_opp.find_user_by_email(self.current_user.decode('utf-8'))

        self.set_header(
          'Cache-Control',
          'no-store, no-cache, must-revalidate, max-age=0')
        self.render_template("/pages/complete-profile.html", {"user": user})
Esempio n. 3
0
    def get(self):
        user = db_opp.find_user_by_email(self.current_user.decode('utf-8'))

        shelters_list = db_opp.find_all_shelters()

        self.set_header(
          'Cache-Control',
          'no-store, no-cache, must-revalidate, max-age=0')
        self.render_template("/pages/shelters.html", {"user": user, "shelters_list": shelters_list})
Esempio n. 4
0
 def get(self):
     user = db_opp.find_user_by_email(self.current_user.decode('utf-8'))
     print(user)
     if user['type'] == "shelter":
         self.set_header(
           'Cache-Control',
           'no-store, no-cache, must-revalidate, max-age=0')
         self.render_template("/pages/dog-form.html", {})
     else:
         self.redirect("/dogs?user=owner")
Esempio n. 5
0
    def get(self):
        if self.get_secure_cookie('user'):
            # do this
            logged_in = True
            user = db_opp.find_user_by_email(self.current_user.decode('utf-8'))
            # name = user['given_name']
        else:
            logged_in = False
            # name = "Guest"

        self.set_header(
          'Cache-Control',
          'no-store, no-cache, must-revalidate, max-age=0')
        self.render_template("/pages/index.html", {"logged_in": logged_in})
Esempio n. 6
0
    def get(self, _id):
        user = db_opp.find_user_by_email(self.current_user.decode("utf-8"))
        dog = db_opp.find_dog_by_id(_id)
        added_by = db_opp.find_user_by_id(dog['user_id'])
        shelter = db_opp.find_shelter_by_id(dog['shelter_id'])

        if user['shelter_id'] == dog['shelter_id']:
            edit = True
        else:
            edit = False

        self.set_header(
          'Cache-Control',
          'no-store, no-cache, must-revalidate, max-age=0')
        self.render_template("/pages/dog-profile.html", {'dog': dog, "user": added_by, "shelter": shelter, "edit": edit})
Esempio n. 7
0
    def get(self):
        user = db_opp.find_user_by_email(self.current_user.decode('utf-8'))
        shelter = False
        type = user['type']
        if type == "not_set":
            self.redirect("/complete-profile")
        elif type == "shelter":
            shelter = True

        shelters_list = db_opp.find_all_shelters()

        self.set_header(
          'Cache-Control',
          'no-store, no-cache, must-revalidate, max-age=0')
        self.render_template("/pages/profile.html", {
            "user": user,
            "shelters_list": shelters_list,
            "shelter": shelter
        })
Esempio n. 8
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')
Esempio n. 9
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'})