Browse code
Added a front controller for auth ease
- TODO: actually remove calls to check() and then reactivate it for use
when it makes sense
- NOTE: when this is deployed, the nginx.conf needs to be updated
Showing 6 changed files
- marrow.nginx.conf.sample
- src/main.py
- src/marrow/user.py
- static/js/new/controller.js
- static/js/new/login.js
- static/login.html
... | ... |
@@ -5,14 +5,14 @@ server { |
5 | 5 |
access_log /var/log/nginx/marrow.access.log; |
6 | 6 |
error_log /var/log/nginx/marrow.error.log; |
7 | 7 |
|
8 |
- root /path/to/marrow/static; |
|
9 |
- index index.html; |
|
8 |
+ root /home/edwlan/github_repos/marrow/static; |
|
9 |
+ index /api; |
|
10 | 10 |
|
11 | 11 |
|
12 | 12 |
location / { |
13 | 13 |
# pass unrecognized urls for index.html |
14 | 14 |
# angularJS will handle the routing of most of these |
15 |
- try_files $uri /index.html; |
|
15 |
+ try_files $uri /api; |
|
16 | 16 |
} |
17 | 17 |
|
18 | 18 |
# pass API requests to the python app |
... | ... |
@@ -1,5 +1,6 @@ |
1 |
-from flask import Flask, g, request |
|
1 |
+from flask import Flask, g, request, session |
|
2 | 2 |
from flask_limiter import Limiter |
3 |
+from flask.ext.login import login_required |
|
3 | 4 |
import os |
4 | 5 |
import base64 |
5 | 6 |
|
... | ... |
@@ -9,7 +10,7 @@ from marrow import bone |
9 | 10 |
|
10 | 11 |
app = Flask(__name__) |
11 | 12 |
app.teardown_appcontext(database.close_connection) |
12 |
-app.config["APPLICATION_ROOT"] = "/api" |
|
13 |
+# app.config["APPLICATION_ROOT"] = "/api" |
|
13 | 14 |
|
14 | 15 |
try: |
15 | 16 |
from marrow_config import config |
... | ... |
@@ -17,6 +18,7 @@ except ImportError: |
17 | 18 |
class config: |
18 | 19 |
secret_key = base64.b64encode(os.urandom(24)) |
19 | 20 |
debug = False |
21 |
+ static_root = os.path.join(os.path.dirname(__file__), os.path.pardir, 'static') |
|
20 | 22 |
|
21 | 23 |
app.secret_key = config.secret_key |
22 | 24 |
app.debug = config.debug |
... | ... |
@@ -34,7 +36,14 @@ app.register_blueprint(user.user_blueprint, url_prefix='/user') |
34 | 36 |
app.register_blueprint(bone.bone_blueprint, url_prefix='/bones') |
35 | 37 |
|
36 | 38 |
@app.route('/') |
37 |
-def index(): return 'Hello World' |
|
39 |
+def index(): |
|
40 |
+ filename = os.path.join(config.static_root, 'login.html') |
|
41 |
+ if 'username' in session: |
|
42 |
+ filename = os.path.join(config.static_root, 'index.html') |
|
43 |
+ with open(filename) as f: |
|
44 |
+ dat = f.read() |
|
45 |
+ print dat |
|
46 |
+ return dat |
|
38 | 47 |
|
39 | 48 |
if __name__ == '__main__': |
40 | 49 |
app.run(host='0.0.0.0') |
... | ... |
@@ -96,7 +96,7 @@ marrowApp.controller('RootCtrl', function ($scope,$http,$location,$route, Subscr |
96 | 96 |
if (is_loggedon.result === true) { |
97 | 97 |
angular.element(document.body).addClass('is-logged-on'); |
98 | 98 |
} else { |
99 |
- $window.location.href = '/login.html'; |
|
99 |
+ //$window.location.href = '/login.html'; |
|
100 | 100 |
} |
101 | 101 |
|
102 | 102 |
$scope.update(); |
... | ... |
@@ -255,7 +255,7 @@ marrowApp.controller('SidebarCtrl', function ($scope,$http,$location,$route, $wi |
255 | 255 |
|
256 | 256 |
$scope.logout = function() { |
257 | 257 |
$http.get('/api/user/logout').success(function() { |
258 |
- $window.location.href = '/login.html'; |
|
258 |
+ $window.location.href = '/'; |
|
259 | 259 |
}); |
260 | 260 |
}; |
261 | 261 |
}); |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-var loginModule = angular.module('marrowApp.login', ['ngResource','ngRoute','angulartics', 'angulartics.google.analytics']); |
|
1 |
+var loginModule = angular.module('marrowLogin', ['ngResource','ngRoute','angulartics', 'angulartics.google.analytics']); |
|
2 | 2 |
|
3 | 3 |
loginModule.controller('LoginCtrl', function ($scope,$http,$route,$window) { |
4 | 4 |
$scope.message = ''; |