]> khamidou — GitHub mirrors - kite.git/commitdiff
initial work on implementing login
authorkarim hamidou <khamidou@gmail.com>
Tue, 6 May 2014 14:38:57 +0000 (16:38 +0200)
committerkarim hamidou <khamidou@gmail.com>
Tue, 6 May 2014 14:38:57 +0000 (16:38 +0200)
src/back/kite/server.py
src/back/kite/users.py
src/back/kite/utils.py
src/front/app/css/bootstrap-theme.css
src/front/app/js/controllers.js
src/front/app/js/services.js
src/front/app/partials/login.html

index f87b0e2f923ac7f75afab6d3cba66e22243154db..8a037f5de2d47c210a7008cce0c2ef5ca908c6af 100755 (executable)
@@ -2,11 +2,26 @@
 import bottle
 import json
 import sys
+import users
 from cabinet import DatetimeCabinet
-from bottle import route, template, response, abort
+from bottle import route, template, response, abort, get, post
 from maildir import *
 from utils import serialize_json
 
+@post('/kite/auth')
+def index():
+    username = request.forms.get('username', None)
+    password = request.forms.get('password', None)
+    if username == None or password == None:
+        response.status = 401
+        return
+
+    if users.auth_user(username, password):
+        response.status = 200
+        token = users.gen_token(username, password)
+        response.set_cookie('XSRF-TOKEN', token, max_age=86400, httponly=False)
+        return
+
 @route('/kite/<user>/mail')
 def index(user):
             # FIXME: input sanitization - check permissions for user
index ba15c4e69c3038e43768414bfe97840b554a1fa4..5d9be5a5240c494ce1994ca81a3c736aa5b44620 100644 (file)
@@ -5,34 +5,14 @@ import jsonfile
 class UserError(Exception):
     pass
 
-
-def create_user(name, _base_folder=os.path.expanduser("~")):
-    """Create the basic structure for an user. Note: _base_folder is only used for testing"""
-    try:
-        os.mkdir(os.path.join(_base_folder, name))
-    except OSError:
-        raise UserError("Folder %s already exists" % name)
-    
-def get_threads_index_folder(email_path):
-    """This function gets the directory where the threads_index file of an user is located.
-    It's called by the inotify daemon with the full path of a new email.
-    ex: get_threads_index_folder("/home/kite/Maildirs/testuser/new/1234563.mail") => "/home/kite/Maildirs/testuser"
-    """
-    return os.path.abspath(os.path.join(os.path.dirname(email_path), os.path.pardir))
-
 def get_username_from_folder(email_path):
     """This function get the username from a maildir.
     ex: get_username_from_folder("/home/kite/Maildirs/testuser/new/1234563.mail") => "testuser" """
-    fullpath = get_threads_index_folder(email_path)
-    return os.path.basename(os.path.normpath(fullpath))
-
-def get_user_threads_index(email_path):
-    folder_name = get_threads_index_folder(email_path)
-    fullpath = os.path.join(folder_name, "threads_index.json")
-
-    jfile = jsonfile.JsonFile(fullpath)
+    # FIXME: refactor this monstrosity
+    return os.path.basename(os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(email_path), os.path.pardir))))
 
-    if not os.path.exists(fullpath): # the threads_index file doesn't exists yet
-        jfile.data = []
+def auth_user(username, password):
+    return True    
 
-    return jfile
+def gen_token(username, password):
+    return "BLAHBLAH"
index 513be2e4ebac7f549f8d499a19ce0c33b633b75e..79cb20245424668e496b87a4fc44b0b9f3953979 100644 (file)
@@ -15,7 +15,9 @@ class DatetimeEncoder(json.JSONEncoder):
         return json.JSONEncoder.default(self, obj)
 
 def serialize_json(obj):
-    return json.dumps(obj, cls=DatetimeEncoder)
+    # we prepend this strange string to prevent jsonp vulnerabilities.
+    # see: https://docs.angularjs.org/api/ng/service/$http for more info.
+    return ")]}',\n" + json.dumps(obj, cls=DatetimeEncoder)
 
 def deserialize_json(string):
     return json.loads(string, object_hook=deserialize_datetime)
index 69357538e8da96e3f4939795e9a57aee79947cbe..60dd1bff893f7c32b39c7a960235e57cf444fb86 100644 (file)
@@ -76,6 +76,7 @@ body {
     border: 1px solid #aaa;
     border-radius: 3px;
     padding: 10px;
+    margin-bottom: 0px;
 }
 
 /* topbar */
@@ -162,17 +163,19 @@ ul.inboxList li.currentInbox {
     border-top: 1px solid #ccc;
 }
 
-button.btn {
+input[type="input"].btn, button.btn {
         border-radius: 3px;
 }
 
-button.btn.btn-primary {
+input[type="input"].btn.btn-primary, button.btn.btn-primary {
     background-image: linear-gradient(to bottom, #889ED3, #4162AF);
     background-image: -webkit-linear-gradient(top, #889ED3, #4162AF);
     background-image: -o-linear-gradient(top, #889ED3, #4162AF);
     background-image: -ms-linear-gradient(top, #889ED3, #4162AF);
 }
 
+input[type="input"].btn.btn-primary:hover,
+input[type="input"].btn.btn-primary:focus,
 button.btn.btn-primary:hover,
 button.btn.btn-primary:focus {
     background-position: 0px;
index a42f260650eb79c02f43b85d3c9a449753c46c6c..244bbe64942e15cd7b4453c24ad2f619e77f684d 100644 (file)
@@ -9,15 +9,17 @@ angular.module('KiteMail.controllers', []).
             {"name": "Trash", },
             {"name": "Spam",  },];
             
-}).controller('MailsListController', ['$scope', 'Emails', function($scope, Emails) {
+}).controller('MailsListController', ['$scope', 'Emails', 'Auth', function($scope, Emails, Auth) {
         $scope.threads = Emails.threads({username: "testuser"});
-}]).controller('LoginController', function($scope) {
-    
-}).controller('ThreadController', ['$scope', '$routeParams', '$sce', 'Emails', function($scope, $routeParams, $sce, Emails) {
+}]).controller('LoginController', ['Auth', function($scope, Auth) {
+    $scope.doLogin = function() {
+        if($scope.password) {
+            console.log("PASS" + $scope.password);            
+        }
+    }    
+}]).controller('ThreadController', ['$scope', '$routeParams', '$sce', 'Emails', function($scope, $routeParams, $sce, Emails) {
     $scope.thread = Emails.thread({username: "testuser", "id": $routeParams.id});
-    console.log("YOLO");
     $scope.trustHTML = function(html_code) {
-        console.log("called");
         return $sce.trustAsHtml(html_code);
     };
 }]);
index 72e30802a8ae4e96acaaef25f6a9b2eb100aa903..9c6a73b4f0d69a3a90538b1dc558e3f0fc05b1cb 100644 (file)
@@ -41,6 +41,22 @@ factory('Emails', ['$resource',
             return (date+'').split(' ');
         }
     };   
-});
+}).factory('Auth', ['$http', function() {
+    var _isAuth = false;
+    var _username = null
+    return {
+        isAuth: _isAuth,
+        username: _username,
+        doLogin: function(username, password, success, failure) {
+            _username = username;
+            $http.post({url: '/kite/auth', params: {"username": username, "password": password}}).
+                        success(function(data, status, headers, config) {
+                            sucess(data);
+                        });
+        },
+
+    };
+    
+}]);
 
 
index 79d36691ea46cc5fca3b219b1f908c104403c892..983dab33a1e2c706bbd95ccec6ad44dfda2a9b42 100644 (file)
@@ -1,26 +1,25 @@
 <div class="loginPage">
     <div class="container loginContainer">
-        <div class="loginForm">
+        <form class="loginForm" ng-submit="doLogin()" ng-controller="LoginController">
             <div class="row-fluid">
                 <div class="span12">
                     <label for="loginField">User name:</label>
-                    <input type="text" name="login" id="loginField" placeholder="User name" value="test"></input>
+                    <input type="text" ng-model="login" id="loginField" placeholder="User name" value="test"></input>
                 </div>
             </div>
 
             <div class="row-fluid">
                 <div class="span12">
                     <label for="passwordField">Password:</label>
-                    <input type="text" name="password" id="passwordField" placeholder="Password" value="test"></input>
+                    <input type="text" ng-model="password" id="passwordField" placeholder="Password" value="test"></input>
                 </div>
             </div>
 
             <div class="row-fluid">
                 <div class="span12">
-                    <a ng-href="#/mail"><button class="loginButton btn btn-primary" id="loginButton">Log me in!</button></a>
+                    <input type="submit" class="loginButton btn btn-primary" id="loginButton" value="Log me in!"></input>
                 </div>
             </div>
-        </div>
-
+        </form>
     </div>
 </div>