Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from flask import Flask, render_template, request, redirect, session, flash
- from uuid import uuid4
- import random
- import string
- wszystkie = 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuioplkjhgfdsazxcvbnm123456789'
- def losuj():
- wynik = []
- i=0
- l = len(wszystkie)
- a=random.randint(1, 5)
- while(i<=a):
- wynik.append(wszystkie[random.randint(0, l - 1)])
- i = i+1
- return wynik
- app_url = '/molasym/session'
- app = Flask(__name__)
- app.secret_key = 'a1s8dAS@#f=+D23d%^$$#*(T'
- tab = {}
- tab2 = {}
- #from werkzeug.debug import DebuggedApplication
- #app.debug = True
- #app.wsgi_app = DebuggedApplication(app.wsgi_app, True)
- @app.route(app_url + '/logout')
- def logout():
- session.pop('username', None)
- return redirect(app_url + '/login')
- @app.route(app_url + '/')
- def index():
- if 'username' not in session:
- return redirect(app_url + '/login')
- username = session['username']
- return render_template('login_success.html')
- @app.route(app_url + '/shorten', methods=['GET', 'POST'])
- def shorten():
- if request.method == 'POST':
- url = request.form.get('link')
- if 'username' not in session:
- kod = ''.join(losuj())
- tab2[url]=kod
- return render_template('login_form.html', link = kod, old = url)
- if 'username' in session:
- tab[url]=''.join(losuj())
- return render_template('login_success.html', link = tab)
- if request.method == 'GET':
- return 'Zła metoda - GET'
- @app.route(app_url + '/login', methods=['GET','POST'])
- def login():
- if request.method == 'GET':
- return render_template('login_form.html')
- if request.method == 'POST':
- username = request.form.get('username')
- password = request.form.get('password')
- if username == 'moli' and password == 'molasy':
- session['uid'] = uuid4()
- session['username'] = username
- return render_template('login_success.html', link = tab )
- return render_template('login_failure.html', username=username)
- @app.route(app_url + '/error')
- def ret_err():
- return render_template('brak_linka.html')
- @app.route(app_url + '/<url_shortened>')
- def url_shortened_redirect(url_shortened):
- print url_shortened
- if 'username' in session:
- for x, y in tab.iteritems():
- if y == url_shortened:
- return redirect(x, code = 301)
- return redirect("http://edi.zetis.pw/molasym/session/error", code=404)
- if 'username' not in session:
- for x, y in tab2.iteritems():
- if y == url_shortened:
- return redirect(x, code = 301)
- return redirect("http://edi.zetis.pw/molasym/session/error", code = 404)
- if __name__ == '__main__':
- app.run(host='0.0.0.0')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement