def uniquedashb(form, field):
    with engine.connect() as conn:
        sql_query = "SELECT title FROM dev.dashboardinfo ORDER BY dashboardid;"
        dashbdf = pd.read_sql(sql_query, conn)
        dashbdata = dashbdf.to_dict('list')["title"]
        if field.data in dashbdata:
            logging.error("Dashboard Title " + str(field.data) +
                          " already exists in database.")
            raise ValidationError("Error. Dashboard Title " + str(field.data) +
                                  " already exists.")
def enduservalid(form, field):
    with engine.connect() as conn:
        endusr = str(field.data)  # end user email address/username entered
        sql_query = "SELECT username, email FROM dev.usrcreds WHERE usertype='enduser' AND enabled=true ORDER BY user_id;"
        usrdatdf = pd.read_sql(sql_query, conn)
        usrmail = usrdatdf.to_dict('list')["email"]
        usrnm = usrdatdf.to_dict('list')["username"]
        if not (endusr in usrmail) and not (endusr in usrnm):
            logging.error(
                str("Enduser " + str(field.data) +
                    " doesn't exist in database."))
            raise ValidationError(
                str("Error. Enduser " + endusr + " does not exist in DB."))
class RegForm(FlaskForm):
    try:
        # Setting username requirements for registration form
        username = StringField(
            'Username',
            validators=[InputRequired(),
                        Length(min=3, max=30), uniquedata])
        email = StringField('Email',
                            validators=[
                                InputRequired(),
                                Email(),
                                Length(min=3, max=100), uniquedata
                            ])
        password = PasswordField(
            'Password', validators=[InputRequired(),
                                    Length(min=3, max=30)])
        pw_confirm = PasswordField('Re-type your password',
                                   validators=[
                                       InputRequired(),
                                       EqualTo('password',
                                               message="Incorrect password")
                                   ])
        submit = SubmitField('Sign up')
    except Exception as e:
        logging.error(str("Error: " + str(e)))
def uniquedata(form, field):
    with engine.connect() as conn:
        val = ''
        usrdatnm = str(field.label.text)
        if (usrdatnm == 'Username'):
            val = 'username'
        elif (usrdatnm == 'Email'):
            val = 'email'
        sql_query = "SELECT " + val + " FROM dev.usrcreds ORDER BY user_id;"
        usrdatadf = pd.read_sql(sql_query, conn)
        usrdata = usrdatadf.to_dict('list')[val]
        if field.data in usrdata:
            logging.error("Email/Username " + str(field.data) +
                          " already exists in database.")
            raise ValidationError("Error. Username/email " + str(field.data) +
                                  " already exists in database.")
class DashbinfoForm(FlaskForm):
    # Setting username requirements for registration form
    try:
        dbtitle = StringField(
            'Title',
            validators=[InputRequired(), uniquedashb,
                        Length(min=3, max=200)])
        dbcatg = StringField(
            'Category', validators=[InputRequired(),
                                    Length(min=3, max=200)])
        ddate = DateField(
            'Publication Date',
            validators=[InputRequired(),
                        DateRange(format='%m/%d/%Y')])
        author = StringField(
            'Author(s)', validators=[InputRequired(),
                                     Length(min=3, max=50)])
        enduser = StringField(
            'Enduser (Username/Email)',
            validators=[InputRequired(), enduservalid,
                        Length(min=3, max=100)]
        )  # later add dropdown for endusers. # add more email addresses to notify
        externurl = BooleanField('External Url?')
        submit = SubmitField('Request your Dashboard Page')
    # add description variable for dashbinfo later
    except Exception as e:
        logging.error(str("Error: " + str(e)))
class LoginForm(FlaskForm):
    try:
        # Setting username requirements for registration form
        username = StringField(
            'Username', validators=[InputRequired(),
                                    Length(min=3, max=30)])
        email = StringField(
            'Email',
            validators=[InputRequired(),
                        Email(),
                        Length(min=3, max=100)])
        password = PasswordField(
            'Password', validators=[InputRequired(),
                                    Length(min=3, max=30)])
        submit = SubmitField('Login')
    except Exception as e:
        logging.error(str("Error: " + str(e)))
Exemplo n.º 7
0
def page_not_found(error):
    logging.error("404 Error: Page not found")
    return render_template("all/pagenotfound.html",
                           title="Page Not Found"), 404
Exemplo n.º 8
0
def Forbidden(error):
    logging.error("403 Error: Attempt to access forbidden page")
    return render_template("all/Forbidden.html", title="Forbidden"), 403