Пример #1
0
def dbinsert():
    fff=request.form
    item= tuple(fff.values())
    print(item)
    db.create_table()
    db.insert_users(item)
    return redirect('/list')
Пример #2
0
def add_user():
    req_data = request.get_json()
    if len(req_data.keys()) != 3:
        return "number of arguments is incorrect"
    elif ('name') and ('mail') and ('pwd') in req_data:
        insert_users(req_data['name'], req_data['mail'], req_data['pwd'])
        return " {} is added to the database ".format(req_data['name'])
    return ("failed because the field of the request are wrong")
Пример #3
0
def build_database():
    logging.info("Build database\n")
    db.create_tables()
    db.insert_users()
    db.insert_seenits()
    db.insert_posts()
    db.insert_comments()
    db.insert_post_upvote()
    db.insert_comment_upvote()
Пример #4
0
def build_database():
    db.create_tables()
    db.insert_users()
    db.insert_seenits()
    db.insert_posts()
    db.insert_comments()
    db.insert_post_upvote()
    db.show_seenits()
    db.show_posts()
    db.show_comments()
    db.show_post_upvotes()
Пример #5
0
def build_database():
    f.writing("Build database\n")
    db.create_tables()
    db.insert_users()
    db.insert_seenits()
    db.insert_posts()
    db.insert_comments()
    db.insert_post_upvote()
    db.show_seenits()
    db.show_posts()
    db.show_comments()
    db.show_post_upvotes()
Пример #6
0
def sign():
    data_users = get_all_users()
    data = get_all_experience()
    logged_in = False
    if 'signin_username' in request.form:
        signin_username = request.form.get('signin_username')
        signin_password = request.form.get('signin_password')
        for user in data_users:
            if user['username'] == signin_username and user[
                    'password'] == signin_password:
                session['username'] = signin_username
                return render_template('index.html',
                                       signin_username=signin_username,
                                       logged_in=True,
                                       data=data,
                                       gallery=get_all_images(),
                                       user=session['username'])
        return render_template('index.html',
                               signin_username=signin_username,
                               logged_in=False,
                               data=data,
                               gallery=get_all_images(),
                               user=session['username'])
    else:
        signup_username = request.form.get('signup_username')
        signup_password = request.form.get('signup_password')
        message = "Signup completed"
        for user in data_users:
            if signup_username == user['username']:
                message = "Username already exists"
                return render_template('sign_up_noti.html',
                                       message=message,
                                       logged_in=logged_in,
                                       gallery=get_all_images())
        if len(signup_username) < 6 or len(signup_username) > 15 or len(
                signup_password) < 6 or len(signup_password) > 15:
            message = "Username or password not available"
            return render_template('sign_up_noti.html',
                                   message=message,
                                   logged_in=logged_in,
                                   gallery=get_all_images())
        insert_users(signup_username, signup_password)
        return render_template('sign_up_noti.html',
                               message=message,
                               logged_in=logged_in,
                               gallery=get_all_images())
Пример #7
0
def login_post():
    user = request.form.to_dict()
    print(list(user.values()))
    db.insert_users(list(user.values()))
    return redirect('/list')
Пример #8
0
def insert():
    # <form> 태그에서 넘어 오는 값을 dictionary로 바꾸고 result에다가 넣는다.
    # console 창을 보면 딕셔너리형식으로 찍히는 걸 볼 수 있다.
    user = request.form.to_dict()
    db.insert_users(list(user.values()))
    return redirect('/list') 
Пример #9
0
def sign():
    data_users = get_all_users()
    data = get_all_experience()
    logged_in = False
    if 'signin_username' in request.form:
        signin_username = request.form.get('signin_username')
        signin_password = request.form.get('signin_password')
        for user in data_users:
            if user['username'] == signin_username and user[
                    'password'] == signin_password:
                session['username'] = signin_username
                return render_template('index.html',
                                       signin_username=signin_username,
                                       logged_in=True,
                                       data=data,
                                       gallery=get_all_images(),
                                       user=session['username'])
        return render_template('index.html',
                               signin_username=signin_username,
                               logged_in=False,
                               data=data,
                               gallery=get_all_images(),
                               user=session['username'])
    elif 'signup_username' in request.form:
        signup_username = request.form.get('signup_username')
        signup_password = request.form.get('signup_password')
        message = "Signup completed"
        for user in data_users:
            if signup_username == user['username']:
                message = "Username already exists"
                return render_template('sign_up_noti.html',
                                       message=message,
                                       logged_in=logged_in,
                                       gallery=get_all_images())
        if len(signup_username) < 6 or len(signup_username) > 15 or len(
                signup_password) < 6 or len(signup_password) > 15:
            message = "Username or password not available"
            return render_template('sign_up_noti.html',
                                   message=message,
                                   logged_in=logged_in,
                                   gallery=get_all_images())
        insert_users(signup_username, signup_password)
        return render_template('sign_up_noti.html',
                               message=message,
                               logged_in=logged_in,
                               gallery=get_all_images())
    else:
        gmail_user = '******'
        gmail_password = '******'
        sent_from = gmail_user
        to = request.form.get('email_to_send')
        subject = 'Thank you for subscribing'
        body = 'Thank you for subscribing viet-traveling'

        email_text = """\  
        From: %s  
        To: %s  
        Subject: %s

        %s
        """ % (sent_from, to, subject, body)
        try:
            server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
            server.ehlo()
            server.login(gmail_user, gmail_password)
            server.sendmail(sent_from, to, email_text)
            server.close()
            return render_template('sub_noti.html',
                                   message="Thanks for subscribing")
        except:
            return render_template('sub_noti.html',
                                   message="Opps!! Some things went wrong!")