Exemplo n.º 1
0
def google_authorized(resp, est):
    if resp is None:
        msg.flash(
            'Access denied: reason=%s error=%s' %
            (request.args['error_reason'], request.args['error_description']))
        return redirect(url_for('index'))
    if str(type(resp)) == "<class 'flask_oauthlib.client.OAuthException'>":
        msg.flash('Access denied: desc=%s error=%s' %
                  (resp.data['error_description'], resp.data['error']))
        return redirect(url_for('index'))
    session['google_token'] = (resp['access_token'], '')
    person = google.get('userinfo')
    # person.data = {
    #     u'family_name': last_name,
    #     u'name': full_name,
    #     u'picture': url,
    #     u'gender': u'male' or u'female',
    #     u'email': email_addr,
    #     u'link': google_plus_url,
    #     u'given_name': first_name,
    #     u'id': u'101149719268028298009',
    #     u'hd': domain_name,
    #     u'verified_email': True  }
    session.pop('_flashes', None)
    email = person.data[u'email']
    authid = person.data[u'id']
    # picture_url = person.data[u'picture']
    if est == "new":
        user = database.create_user_byOAuth(email, authid, "google")
        if msg.is_bad(user):
            msg.flash(user)
            return redirect(url_for('index'))
        account = account__database.create_account(user, person.data[u'name'])
        if msg.is_bad(account):
            msg.flash(account)
            return redirect(url_for('index'))
        login_user(user)
        msg.flash(
            msg.success(
                'Welcome, your name has been determined to be <b>{}</b>'.
                format(account.s_name),
                return_def="index"))
        return redirect(url_for('index'))
    user = database.read_user_byOAuth(email, authid, "google")
    if msg.is_bad(user):
        msg.flash(user)
        return redirect(url_for('index'))
    login_user(user)
    msg.flash(msg.success('Welcome back.', return_def="index"))
    return redirect(url_for('index'))
Exemplo n.º 2
0
 def process_form(self, wtf, **kwargs):
     true_key = wtf.pkey.data.replace("_", "/")
     result = database.delete_article(true_key)
     if msg.is_good(result):
         return msg.success('Article deleted.',
                            return_def="page_admin_main")
     return result
Exemplo n.º 3
0
 def process_form(self, wtf, **kwargs):
     #
     # this is where any database processing would happen
     #
     msg.flash("Got it! string={}, integer={}, etc.".format(
         wtf.s.data, wtf.i.data))
     return msg.success("All good.", return_def="page_example_about")
Exemplo n.º 4
0
 def process_table(self, **kwargs):
     self.set_header(self.MTRow())
     for n in range(1, 5):
         r = self.MTRow()
         r.b.data = random.choice([True, False])
         r.d.data = datetime.datetime.now()
         r.dt.data = datetime.datetime.now()
         r.fl.data = random.random()
         r.i.data = random.randint(-1000, 1000)
         r.r.data = random.choice(r.r.choices)[0]
         r.sf.data = random.choice(r.sf.choices)[
             0]  # it does NOT display 'default'; it displays 'data'
         r.sfm.data = [
             random.choice(r.sfm.choices)[0],
             random.choice(r.sfm.choices)[0]
         ]
         # r.sfm.data = [k for k,v in random.choices(r.sfm.choices, k=random.randint(0,len(r.sfm.choices)))]
         r.s.data = random.choice(["hat", "apple", "ball", "fish"])
         r.h.data = "you can't see me."
         r.p.data = "still can't see me."
         r.t.data = "line1\nline2\nline3\n"
         # r.buf.data = x  # it does not matter what 'data' contains
         # r.dpf.data = x
         self.rows.append(r)
     return msg.success("random number of rows of things.")
Exemplo n.º 5
0
 def process_table(self, **kwargs):
     log_list = database.readlist_log(qty=50)
     self.set_header(self.LogRow())
     for log in log_list:
         r = self.LogRow()
         copy_fields(src=log, dest=r)
         self.rows.append(r)
     return msg.success("Event Logs.")
Exemplo n.º 6
0
 def process_table(self, **kwargs):
     self.set_header(self.TabTwoRow())
     for a in ["a", "b", "c"]:
         r = self.TabTwoRow()
         r.s_name.data = a
         r.s_something.data = "blah"
         self.rows.append(r)
     return msg.success("rows of stuff for table 2.")
Exemplo n.º 7
0
 def process_form(self, wtf, pkey=None):
     group_name = wtf.group_name.data
     page_name = wtf.page_name.data
     key = database.build_key(group_name, page_name)
     result = database.upsert_article(key, wtf)
     if msg.is_good(result):
         return msg.success('Article saved.')
     return result
Exemplo n.º 8
0
 def process_table(self, **kwargs):
     pic_list = database.readlist_articlePictures()
     self.set_header(self.PictureRow())
     for p in pic_list:
         r = self.PictureRow()
         copy_fields(dest=r, src=p)
         r.s_key.href = "/admin/picture/{}".format(r.s_key.data)
         r.usage_url.data = "/apic/{}.png".format(r.s_key.data)
         self.rows.append(r)
     return msg.success("Pictures.")
Exemplo n.º 9
0
 def process_table(self, **kwargs):
     self.set_header(self.Row())
     tdl = readlist_testDocument_all()
     for doc in tdl:
         r = self.Row()
         fondum_utility.copy_fields(src=doc, dest=r)
         r.delete.href = "/example/copy-fields-delete/{}/".format(
             doc.id)
         self.rows.append(r)
     self.rows.append(self.CreateButtonRow())
     return msg.success("all documents")
Exemplo n.º 10
0
 def process_table(self, **kwargs):
     article_list = database.read_articleList(list_type="all")
     self.set_header(self.ArticleRow())
     for a in article_list.arr_articles:
         r = self.ArticleRow()
         copy_fields(src=a, dest=r)
         ukey = "_".join(a.s_key.split("/"))
         r.s_key.href = "/admin/article/{}".format(ukey)
         r.delete_function.href = "/admin/article-delete/{}".format(
             ukey)
         self.rows.append(r)
     return msg.success("Articles.")
Exemplo n.º 11
0
 def process_table(self, pkey=None, **kwargs):
     product_list = database.readlist_product(categories=[])
     self.set_header(self.ProductRow())
     for a in product_list:
         r = self.ProductRow()
         copy_fields(dest=r, src=a)
         r.s_key.href = "/admin/product/{}".format(a.s_key)
         r.categories.data = ", ".join(a.arr_categories)
         r.delete_function.href = "/admin/product-delete/{}".format(
             a.s_key)
         self.rows.append(r)
     return msg.success("Products.")
Exemplo n.º 12
0
def upsert_articlePicture(key, wtf, details):
    p = read_articlePicture(key)
    if p:  # this is an update not an insert/create
        if details["success"]:  # but a new file was uploaded
            p.s_url = details['url']
            p.s_etag = details['etag']
            p.s_key = key
            p.s_notes = wtf.s_notes.data
            p.save()
            return msg.success("uploaded replacement file.")
        p.s_notes = wtf.s_notes.data
        p.s_key = key
        p.save()
        return msg.success("changed details about file.")
    p = models.ArticlePicture()
    p.s_url = details['url']
    p.s_etag = details['etag']
    p.s_key = key
    p.s_notes = wtf.s_notes.data
    p.save()
    return msg.success('uploaded "{}"'.format(details['name']))
Exemplo n.º 13
0
def sendmail(group_id, to_addr=None, plain_text=None, creole_text=None, html=None, subject=None, from_addr=None):
    config = current_app.config
    #
    # do sanity checks first
    #
    if not config.get('HAS_SENDMAIL', False):
        return msg.bug("Sendmail not active in config.")
    if group_id not in config.get("SENDGRID_UNSUBSCRIBE_GROUPS", {}):
        return msg.bug("Sendgrid unsubscribe group_id {} not found.".format(group_id))
    from_header = from_addr or config.get("SENDGRID_DEFAULT_FROM_ADDRESS", None)
    if not from_header:
        return msg.bug("missing 'from' address.")
    to_header = to_addr
    if not to_header:
        return msg.bug("missing 'to' address.")
    subject_header = subject or config.get("SENDGRID_DEFAULT_SUBJECT", None)
    if not from_header:
        return msg.bug("missing subject.")
    if plain_text:
        body = plain_text
        mimetype = "text/plain"
    if creole_text:
        body = parsing.creole2html(creole_text)
        mimetype = "text/html"
    if html:
        body = html
        mimetype = "text/html"
    if not body:
        return msg.bug("missing body contents (via 'creole_text' or 'html' parameters.")
    #
    # 
    #
    # email_id = uuid.uuid4()
    # message.set_headers({'X-Fondum-EmailID': str(email_id)});
    try:
        sg = sendgrid.SendGridAPIClient(apikey=config['SENDGRID_API_KEY'])
        message = h.Mail(
            h.Email(from_header),
            subject_header,
            h.Email(to_header),
            h.Content(mimetype, body)
        )
        message.asm = h.ASM(group_id)
        response = sg.client.mail.send.post(request_body=message.get())
    except sg_except.UnauthorizedError as e:
        return msg.bug("SENDGRID unauthorized error (check SENDGRID_API_KEY): {}".format(str(e)))
    except Exception as e:
        return msg.bug("SENDGRID general error: {}".format(str(e)))
    return msg.success("Message sent to {}".format(to_header))
Exemplo n.º 14
0
def update_product(product, wtf):
    product.s_title = wtf.s_title.data or "[NO TITLE]"
    product.s_made_by = wtf.s_made_by.data or None
    try:
        product.fl_price = Decimal(wtf.fl_price.data)
    except:
        product.fl_price = None
    product.s_shipping_detail = wtf.s_shipping_detail.data or None
    product.s_short_description = wtf.s_short_description.data or ""
    product.s_img_key = wtf.s_img_key.data or None
    product.s_url = wtf.s_url.data
    cats = wtf.categories.data.split(",")
    product.arr_categories = [c.strip() for c in cats]
    product.save()
    return msg.success("Product {} updated.".format(product.s_key))
Exemplo n.º 15
0
 def process(self, TABLE_NAME=None, **kwargs):
     self.url_params = kwargs
     #
     # PROCESS TABLES
     #
     if self.has_tables:
         self.current_table_name = None
         self.tables = []
         for table_class in self.table_order:
             self.tables.append(table_class(outer_page_instance=self))
         self.default_table_name = self.tables[0].key_name
         if not TABLE_NAME:
             TABLE_NAME = self.default_table_name
         self.table_name = TABLE_NAME
         self.status = msg.err("table name [{}] not found".format(
             self.table_name))
         self.skip_table_body = True
         for table in self.tables:
             if table.key_name == self.table_name:
                 self.display_table = table
                 self.status = table.process_table(
                     **
                     kwargs)  # should we add TABLE_NAME to start of params?
                 if not isinstance(self.status, EmptyTable):
                     self.skip_table_body = False
     #
     # PROCESS CATALOG
     #
     if self.has_catalog:
         self.catalog = self.MainCatalog(self)
         self.catalog.process_catalog(TABLE_NAME=TABLE_NAME, **kwargs)
     #
     # PROCESS MAIN FORM
     #
     if self.has_form:
         # fondum_utility.handle_form_imports(self.MainForm)
         self.wtf = self.MainForm(outer_page_instance=self,
                                  style=self.form_style)
     #
     self.status = msg.success("page processed")
Exemplo n.º 16
0
 def process_form(self, wtf, pkey=None, **kwargs):
     result = database.delete_product(pkey)
     if msg.is_good(result):
         return msg.success('Product deleted.',
                            return_def="page_admin_main")
     return result
Exemplo n.º 17
0
def delete_product(key):
    product = read_product(key)
    if msg.is_bad(product):
        return msg.err("Product {} missing; possibly already deleted.".format(key))
    product.delete()
    return msg.success("Product {} deleted.".format(product.s_key))
Exemplo n.º 18
0
def create_testDocument(wtf):
    doc = TestDocument()
    copy_fields(src=wtf, dest=doc)
    doc.save()
    return msg.success('Created TestDocument "{}"'.format(doc.name))
Exemplo n.º 19
0
def delete_testDocument(doc_id):
    doc = read_testDocument(doc_id)
    if msg.is_message(doc):
        return doc
    doc.delete()
    return msg.success("TestDocument document deleted.")