]> khamidou — GitHub mirrors - kite.git/commitdiff
login WIP
authorkarim hamidou <khamidou@gmail.com>
Sat, 10 May 2014 10:29:59 +0000 (12:29 +0200)
committerkarim hamidou <khamidou@gmail.com>
Sat, 10 May 2014 10:29:59 +0000 (12:29 +0200)
src/back/kite/server.py
src/front/app/js/app.js
src/front/app/js/services.js

index cadf50c11e2f044b6fe856be8575bc70ed53664f..061e22815672defe7f8a7eb2e1449cc0167c36a5 100755 (executable)
@@ -8,6 +8,12 @@ from bottle import route, template, request, response, abort, get, post
 from maildir import *
 from utils import serialize_json
 
+@get('/kite/auth')
+def index():
+    response.status = 200
+    response.set_cookie('XSRF-TOKEN', "blah", max_age=86400)
+    return
+
 @post('/kite/auth')
 def index():
     username = request.json.get('username', None)
index c10f1d25dd247eb0333e94f007cea8372e232cb9..5da6de02b4eace13d9a97769ba27be3afdff8f86 100644 (file)
@@ -8,4 +8,14 @@ angular.module('KiteMail', ['ngRoute', 'KiteMail.filters', 'KiteMail.services',
     $routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'LoginController'});
     $routeProvider.when('/thread/:id', {templateUrl: 'partials/thread.html', controller: 'ThreadController'});
     $routeProvider.otherwise({redirectTo: '/login'});
+  }]).run(['$rootScope', '$location', 'Auth', function($rootScope, $location, Auth) { 
+   $rootScope.$on( "$routeChangeStart", function(event, next, current) {
+        console.log(Auth.loggedOn());
+        if (!Auth.loggedOn()) {
+            // no logged user, redirect to /login
+            if (next.templateUrl != "partials/login.html") {
+                $location.path("/login");
+            }
+        }
+    }); 
   }]);
index 9b1323f0b2a91272ff0bd0f252c8431e8ad1b2ff..a0003f9f86358036da72d6b8b1ec53ad78db50ca 100644 (file)
@@ -45,12 +45,13 @@ factory('Emails', ['$resource',
     var _isAuth = false;
     var _username = null
     return {
-        isAuth: _isAuth,
+        loggedOn: function() { return _isAuth },
         username: _username,
         doLogin: function(username, password, success, failure) {
             _username = username;
             $http({url: '/kite/auth', method:'POST',  data: {"username": username, "password": password}}).
                         success(function(data, status, headers, config) {
+                            _isAuth = true;
                             success(data);
                         });
         },