1 from flask import g, render_template, request, redirect, url_for, flash, \
3 from flask_login import current_user, login_required, login_user, logout_user
4 from flask_principal import RoleNeed, identity_changed, identity_loaded, Identity, \
5 AnonymousIdentity, UserNeed
8 import wradmin.template_helper
9 from wradmin.app import app, db, admin_permission, login_manager
10 from wradmin.auth import password_is_correct
11 from wradmin.auth.forms import LoginForm
12 from wradmin.controllers.bericht import BerichtController
13 from wradmin.controllers.coordtool import CoordtoolController
14 from wradmin.controllers.gasthaus import GasthausController
15 from wradmin.controllers.rodelbahn import RodelbahnController
19 def _before_request():
25 return render_template('index.html')
28 @app.route("/rodelbahn/list")
31 return RodelbahnController().list()
34 @app.route("/rodelbahn/view/<int:id>")
36 @admin_permission.require(403)
37 def rodelbahn_view(id):
38 return RodelbahnController().view(id)
41 @app.route("/rodelbahn/update")
43 def rodelbahn_update():
44 return RodelbahnController().update()
47 @app.route("/rodelbahn/update_regioncache")
49 def rodelbahn_update_regioncache():
50 return RodelbahnController().update_regioncache()
53 @app.route("/rodelbahn/update_mapcache")
55 def rodelbahn_update_mapcache():
56 return RodelbahnController().update_mapcache()
59 @app.route("/bericht/list")
61 @admin_permission.require(403)
63 return BerichtController().list()
66 @app.route("/bericht/view/<int:id>")
68 @admin_permission.require(403)
70 return BerichtController().view(id)
73 @app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
75 @admin_permission.require(403)
76 def bericht_change_date_invalid(id):
77 return BerichtController().change_date_invalid(id)
80 @app.route("/bericht/update_reportcache")
82 def bericht_update_reportcache():
83 return BerichtController().update_reportcache()
86 @app.route("/gasthaus/list")
89 return GasthausController().list()
92 @app.route("/gasthaus/view/<int:id>")
94 def gasthaus_view(id):
95 return GasthausController().view(id)
98 @app.route("/gasthaus/update")
100 def gasthaus_update():
101 return GasthausController().update()
104 @app.route("/coordtool/index")
106 def coordtool_index():
107 return CoordtoolController().index()
110 @app.route("/coordtool/convert", methods=['POST'])
112 def coordtool_convert():
113 return CoordtoolController().convert()
116 @app.route("/login", methods=['GET', 'POST'])
119 if form.validate_on_submit():
120 user = db.session.query(wradmin.model.MwUser).filter_by(user_name=form.user_name.data).first()
121 if user is not None and password_is_correct(form.password.data, user.user_password.decode()):
122 login_user(user, form.remember_me.data)
123 identity_changed.send(current_app._get_current_object(), identity=Identity(user.get_id()))
124 next = request.args.get('next')
125 if next is None or not next.startswith('/'):
126 next = url_for('index')
127 flash('Sie sind nun angemeldet.')
128 return redirect(next)
129 flash('Ungülter Benutzername oder ungültiges Passwort.')
130 return render_template('auth/login.html', form=form)
133 @app.route("/logout")
136 for key in ('identity.name', 'identity.auth_type'):
137 session.pop(key, None)
138 identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity())
139 flash('Sie wurden ausgeloggt.')
140 return redirect(url_for('index'))
143 @login_manager.user_loader
144 def user_loader(user_id):
145 return wradmin.db.session.query(wradmin.model.MwUser).get(user_id)
148 @identity_loaded.connect_via(app)
149 def on_identity_loaded(sender, identity):
150 identity.user = current_user
151 user_id = current_user.get_id()
152 if user_id is not None:
153 identity.provides.add(UserNeed(user_id))
154 if wradmin.db.session.query(wradmin.model.MwUserGroups).get((user_id, 'sysop')) is not None:
155 identity.provides.add(RoleNeed('admin'))