From: karim hamidou Date: Sat, 10 May 2014 10:29:59 +0000 (+0200) Subject: login WIP X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=36a6ac25d0d3bfc1c3b86f27d3e8cbc36a23222e;p=kite.git login WIP --- diff --git a/src/back/kite/server.py b/src/back/kite/server.py index cadf50c..061e228 100755 --- a/src/back/kite/server.py +++ b/src/back/kite/server.py @@ -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) diff --git a/src/front/app/js/app.js b/src/front/app/js/app.js index c10f1d2..5da6de0 100644 --- a/src/front/app/js/app.js +++ b/src/front/app/js/app.js @@ -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"); + } + } + }); }]); diff --git a/src/front/app/js/services.js b/src/front/app/js/services.js index 9b1323f..a0003f9 100644 --- a/src/front/app/js/services.js +++ b/src/front/app/js/services.js @@ -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); }); },