core/usermanager.lua
author Matthew Wild <mwild1@gmail.com>
Wed, 01 May 2013 13:54:44 +0100
branchtls
changeset 5556 7407b1160b46
parent 60 44800be871f5
child 228 875842235836
permissions -rw-r--r--
Close 'tls' branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     1
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     2
require "util.datamanager"
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     3
local datamanager = datamanager;
53
14ea0fe6ca86 Session destruction fixes, some debugging code while we fix the rest. Also change logger to be more useful.
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
     4
local log = require "util.logger".init("usermanager");
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     5
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     6
module "usermanager"
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     7
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
     8
function validate_credentials(host, username, password)
53
14ea0fe6ca86 Session destruction fixes, some debugging code while we fix the rest. Also change logger to be more useful.
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
     9
	log("debug", "User '%s' is being validated", username);
0
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
    10
	local credentials = datamanager.load(username, host, "accounts") or {};
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
    11
	if password == credentials.password then return true; end
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
    12
	return false;
3e3171b59028 First commit, where do you want to go tomorrow?
matthew
parents:
diff changeset
    13
end
38
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
    14
60
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    15
function user_exists(username, host)
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    16
	return datamanager.load(username, host, "accounts") ~= nil;
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    17
end
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    18
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    19
function create_user(username, password, host)
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    20
	return datamanager.store(username, host, "accounts", {password = password});
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    21
end
44800be871f5 User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents: 53
diff changeset
    22
38
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
    23
return _M;