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
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"
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)
border: 1px solid #aaa;
border-radius: 3px;
padding: 10px;
+ margin-bottom: 0px;
}
/* topbar */
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;
{"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);
};
}]);
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);
+ });
+ },
+
+ };
+
+}]);
<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>