-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.py
46 lines (36 loc) · 1.42 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from config import MEDIA_FOLDER, TEMPLATE_FOLDER
from flask import Flask
app = Flask("PersonalPassword", template_folder=TEMPLATE_FOLDER, static_folder=MEDIA_FOLDER,static_path='/assets')
app.config.from_object('settings')
from google.appengine.ext import db
from google.appengine.api import users
from flask import redirect, url_for, request, render_template, abort, flash, get_flashed_messages
class SecretStore(db.Model):
user = db.UserProperty(auto_current_user=True)
website = db.StringProperty()
password = db.StringProperty()
@app.route('/')
def index():
user = users.get_current_user()
passwds = SecretStore.all().filter('user =', user)
return render_template('index.html', user=user, logout_url=users.create_logout_url("/"), passwds=passwds);
@app.route('/', methods=['POST'])
def passwd_post():
website = request.form['website']
password = request.form['password']
if not website or not password:
return redirect(url_for('index'))
passwd = SecretStore(website = website, password=password)
passwd.user = users.get_current_user()
passwd.put()
return redirect(url_for('index'))
@app.route('/delete/<int:id>')
def password_delete(id):
passwd = SecretStore.get_by_id(id)
if passwd and passwd.user == users.get_current_user():
passwd.delete()
else:
abort(404)
return redirect(url_for('index'))
if __name__ == '__main__':
app.run()