Commit bb07f5687c7b2aeba3759304842b7f05bb3ed807

Add basic admin login

  Admin login needed to edit. Basic admin login in place.
Configure your admin username and password in the conf file.
  
88
99 def __init__(self):
1010 """@todo: to be defined1 """
11 self.id = object.id
12 self.tags = object.tags
13 self.type = object.type
14 self.body = object.body
11 self.id = object.id
12 self.tags = object.tags
13 self.type = object.type
14 self.body = object.body
  
77'''
88HOST = '0.0.0.0'
99PORT = 5000
10SECRET_KEY = 'a-uuid-string-see-python-uuid'
11ADMIN_USERNAME = 'youradminusername'
12ADMIN_PASSWORD = 'youradminpassword'
  
4949
5050@app.route('/edit', methods=['GET'])
5151def edit():
52 return flask.render_template('editor.html', content=getContent(),
53 title=conf.SITE_TITLE)
52 if "logged_in" in flask.session:
53 flask.session['key'] = conf.SECRET_KEY
54 return flask.render_template('editor.html', content=getContent(),
55 title=conf.SITE_TITLE)
56 else:
57 return flask.redirect(flask.url_for('login'))
5458
5559
5660@app.route('/page', methods=['POST'])
108108def updateMenu(_id):
109109 if flask.request.method == 'PUT':
110110 changedMenu = flask.request.json
111 print "changed menu:"
111112 print changedMenu
112113 res = siteMenu.update({'_id': bson.ObjId(_id)}, changedMenu)
113114 print res
122122 # return flask.jsonify(status='deleted')
123123
124124
125# Basic login for one single admin user whose credentials are in conf.py
126@app.route('/login', methods=['GET', 'POST'])
127def login():
128 error = None
129 if flask.request.method == 'POST':
130 print flask.request.form
131 if flask.request.form['username'] != conf.ADMIN_USERNAME:
132 error = 'Invalid username'
133 elif flask.request.form['password'] != conf.ADMIN_PASSWORD:
134 error = 'Invaid password'
135 else:
136 flask.session['logged_in'] = True
137 flask.session['key'] = conf.SECRET_KEY
138 flask.flash('You were logged in')
139 return flask.redirect(flask.url_for('edit'))
140 return flask.render_template('login.html', error=error)
141
142@app.route('/logout')
143def logout():
144 flask.session.pop('logged_in', None)
145 flask.flash('You were logged out')
146 return flask.redirect(flask.url_for('login'))
147
148@app.route('/robots.txt')
149@app.route('/crossdomain.xml')
150def static_from_root():
151 return flask.send_from_directory(app.static_folder, request.path[1:])
152
153
154app.config.from_object(conf)
125155
126156if __name__ == "__main__":
127157 app.run(debug=True, host=conf.HOST, port=conf.PORT)
  
2323 <![endif]-->
2424
2525 <div class="container" id="container">
26 <div id="header"><div id="notifications"></div></div>
27 <div id="content-container"></div>
26 <div id="header">
27 <div id="hud">
28 <span class="pull-right">Howdy! | <a href="/logout">Logout</a></span>
29 </div>
30 <div id="notifications"></div>
31 </div>
32 <div id="content-container">
33 </div>
2834 <div id="footer">
2935 </div>
3036 </div>
  
1<!DOCTYPE html>
2<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
6 <head>
7 <meta charset="utf-8">
8 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
9 <title> Mouchak | Login</title>
10 <meta name="description" content="">
11 <meta name="viewport" content="width=device-width">
12
13 <!-- Place favicon.ico in the root directory -->
14
15 <link rel="stylesheet" href="/static/css/normalize.css">
16 <link rel="stylesheet" href="/static/css/bootstrap.css">
17 <style type="text/css">
18 .form-wrapper {
19 height: 300px;
20 width: 500px;
21 margin: 100px auto;
22 padding: 30px;
23 }
24 </style>
25 </head>
26 <body>
27 <!--[if lt IE 7]>
28 <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
29 <![endif]-->
30
31 <div class="container" id="container">
32 <div class="form-wrapper well">
33 {% if error %}
34 <div class="alert alert-error"><b>Error:</b> {{ error }} </div>
35 {% endif %}
36 <h3> Mouchak Login </h3>
37 <p class="lead"> Please enter admin credentials to login</p>
38 <form class="form-horizontal" action="{{ url_for('login') }}" method="POST">
39 <div class="control-group">
40 <label class="control-label" for="inputUsername">Username</label>
41 <div class="controls">
42 <input type="text" id="inputUsername" name="username" placeholder="Username">
43 </div>
44 </div>
45 <div class="control-group">
46 <label class="control-label" for="inputPassword">Password</label>
47 <div class="controls">
48 <input type="password" id="inputPassword" name="password" placeholder="Password">
49 </div>
50 </div>
51 <div class="control-group">
52 <div class="controls">
53 <!--label class="checkbox">
54 <input type="checkbox"> Remember me
55 </label-->
56 <button type="submit" class="btn btn-primary">Login</button>
57 </div>
58 </div>
59 <div class="clearfix"></div>
60 </form>
61 </div>
62 </div>
63 </body>
64</html>