Пример #1
0
    def post(self, category, name):
        """Saves a resource in the cloud storage

        Multiple files are possible, if multiple files are uploaded the 'name' needs to be 'multiple'.
        For multiple files the file name is take as name.
        If multiple fils are uploaded without 'multiple' only the last file is saved.
        The function can also gerenate a serving link, this is either public or private (not guessable).

        If category or name (without extension) is a user key it needs to belong to the loged in user.
        """
        link = request.form.get(
            'link', default='private')  # either public, private or False
        gcs_links = []
        api_links = []
        private_links = []
        links = []
        print "Category: " + str(category)
        try:
            category_key = ndb.Key(urlsafe=category)
        except:
            category_key = False

        for k, f in request.files.iteritems(multi=False):
            if name == 'multiple':
                name = f.filename
            try:
                name_key = ndb.Key(
                    urlsafe=os.path.splitext(os.path.basename(name))[0])
            except:
                name_key = False

            if category_key or name_key:
                user_key = category_key or name_key
                if not auth.is_authorized(user_key):
                    return abort(403)

            write_retry_params = gcs.RetryParams(backoff_factor=1.1)
            adr = "{}/{}/{}".format(GCS_BUCKET, category, name)
            gcs_file = gcs.open(adr,
                                'w',
                                content_type=f.mimetype,
                                options={'x-goog-meta-name': f.filename},
                                retry_params=write_retry_params)
            f.save(gcs_file)  # saves file to cloud storage
            gcs_file.close()
            f.close()
            gcs_links.append("/_ah/gcs" + adr)
            api_links.append("/api/v1/upload/" + category + '/' + name)
            links.append("/resource/" + '/' + category + '/' + name)
            if link == 'private':  #TODO implement public links
                blob_key = blobstore.create_gs_key('/gs' + adr)
                img_url = images.get_serving_url(blob_key=blob_key)
                private_links.append(img_url)

        return {
            'links': links,
            'private_links': private_links,
            'gcs_links': gcs_links,
            'api_links': api_links
        }
Пример #2
0
def main():
    auth.load_auth()

    parser = GooeyParser(
        description='Fitnessd local edition - record your health on the go!')

    #Validating if exist data.  email and password
    if not auth.is_authorized():
        parser.add_argument("Email", default=auth.email)
        parser.add_argument("Password", widget="PassqordField")

    parser.add_argument('Rate', help='Resting heart rate', type=int)
    parser.add_argument('Weight', help='Weight in pounds', type=int)
    parser.add_argument('Date',
                        help='Date of measurement',
                        widget='DateChooser',
                        default=datetime.date.today())

    # Showing GUI
    data = parser.parse_args()
    weight = int(data.Weight)
    rate = int(data.Rate)
    recorded = dateutil.parser.parse(data.Date)

    if not auth.is_authorized():
        email = data.Email
        password = data.Password
        api_key = svc.authenticate(email, password)
        if not api_key:
            print('Error authenticating')
            return
        else:
            print('Login successful!')
        auth.save_auth(email, api_key)

    result = svc.save_measurement(auth.api_key, auth.email, rate, weight,
                                  recorded)
    if result:
        print('Done!')
    else:
        print('Could not save measurement.')
Пример #3
0
def main():
    auth.load_auth()

    parser = GooeyParser(
        description="Fitnessd local edition - record your health on the go!")

    if not auth.is_authorized():
        parser.add_argument("Email", default=auth.email)
        parser.add_argument("Password", widget="PasswordField")

    parser.add_argument('Rate', help="Resting heart rate", type=int)
    parser.add_argument('Weight', help="Weight in pounds", type=int)
    parser.add_argument('Date',
                        help="Date of measurement",
                        widget="DateChooser",
                        default=datetime.date.today())

    data = parser.parse_args()
    rate = int(data.Rate)
    weight = int(data.Weight)
    recorded = dateutil.parser.parse(data.Date)

    if not auth.is_authorized():
        email = data.Email
        password = data.Password
        api_key = svc.authenticate(email, password)
        if not api_key:
            print("Error authenticating")
            return
        else:
            print("Login successful")
        auth.save_auth(email, api_key)

    result = svc.save_measurement(auth.api_key, auth.email, rate, weight,
                                  recorded)
    if result:
        print("Done!")
    else:
        print("Error: Could not save measurement")
Пример #4
0
def setup():
    bean.BeanTableCreator(Template).register()
    bean.BeanRelationCreator(Template, UserGroup).register()
    bean.BeanTableCreator(UserGroup).register()
    bean.BeanTableCreator(ManglerMapping).register()
    bean.BeanTableCreator(Session).register()

    if not request.path.endswith("login"):

        if "auth_token" not in request.cookies:
            redirect_to_login = redirect("login")
            response = current_app.make_response(redirect_to_login)
            return response

        if not auth.is_authorized(request.cookies["auth_token"]):
            redirect_to_login = redirect("login")
            response = current_app.make_response(redirect_to_login)
            return response
Пример #5
0
 def is_authorized(self):
   return auth.is_authorized(self.handler.request)
Пример #6
0
 def is_authorized(self):
     return auth.is_authorized(self.handler.request)