def index(): if 'username' in session: return render_template('index.html', data=get_all_experience(), gallery=get_all_images(), logged_in=True, user=session['username']) return render_template('index.html', data=get_all_experience(), gallery=get_all_images(), logged_in=False)
def gallery(): x = len(get_all_images()) // 4 if 'username' in session: return render_template('gallery.html', logged_in=True, gallery=get_all_images(), x=x, y=len(get_all_images()), user=session['username']) return render_template('gallery.html', logged_in=False, gallery=get_all_images(), x=x, y=len(get_all_images()))
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())
#!/usr/bin/python3.7 import db import base import session images = db.get_all_images() data = session.get_session_data() if data is None: print("Location: login.py") user = db.get_user(data['user_id']) if user[4] != 2: print("Location: upload.py") print("Content-type:text/html") print("") base.start_html() for image in images: print('<img src="../../images/%s" width=100 height=100>' % image[1]) print('<p>%s : viewed %d times</p>' % (image[1], image[2])) base.finish_html()
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!")
def get_all_images(): return jsonify(db.get_all_images()), 200