aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_auth_sql.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ejabberd_auth_sql.erl')
-rw-r--r--src/ejabberd_auth_sql.erl34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/ejabberd_auth_sql.erl b/src/ejabberd_auth_sql.erl
index f6f4f9efb..413c6a02f 100644
--- a/src/ejabberd_auth_sql.erl
+++ b/src/ejabberd_auth_sql.erl
@@ -25,17 +25,15 @@
-module(ejabberd_auth_sql).
--compile([{parse_transform, ejabberd_sql_pt}]).
-author('alexey@process-one.net').
-behaviour(ejabberd_auth).
--behaviour(ejabberd_config).
-export([start/1, stop/1, set_password/3, try_register/3,
get_users/2, count_users/2, get_password/2,
remove_user/2, store_type/1, plain_password_required/1,
- convert_to_scram/1, opt_type/1, export/1, which_users_exists/2]).
+ convert_to_scram/1, export/1, which_users_exists/2]).
-include("scram.hrl").
-include("logger.hrl").
@@ -70,9 +68,9 @@ set_password(User, Server, Password) ->
end,
case ejabberd_sql:sql_transaction(Server, F) of
{atomic, _} ->
- ok;
+ {cache, {ok, Password}};
{aborted, _} ->
- {error, db_failure}
+ {nocache, {error, db_failure}}
end.
try_register(User, Server, Password) ->
@@ -85,8 +83,8 @@ try_register(User, Server, Password) ->
add_user(Server, User, Password)
end,
case Res of
- {updated, 1} -> ok;
- _ -> {error, exists}
+ {updated, 1} -> {cache, {ok, Password}};
+ _ -> {nocache, {error, exists}}
end.
get_users(Server, Opts) ->
@@ -106,16 +104,16 @@ count_users(Server, Opts) ->
get_password(User, Server) ->
case get_password_scram(Server, User) of
{selected, [{Password, <<>>, <<>>, 0}]} ->
- {ok, Password};
+ {cache, {ok, Password}};
{selected, [{StoredKey, ServerKey, Salt, IterationCount}]} ->
- {ok, #scram{storedkey = StoredKey,
- serverkey = ServerKey,
- salt = Salt,
- iterationcount = IterationCount}};
+ {cache, {ok, #scram{storedkey = StoredKey,
+ serverkey = ServerKey,
+ salt = Salt,
+ iterationcount = IterationCount}}};
{selected, []} ->
- error;
+ {cache, error};
_ ->
- error
+ {nocache, error}
end.
remove_user(User, Server) ->
@@ -221,8 +219,7 @@ users_number(LServer) ->
LServer,
fun(pgsql, _) ->
case
- ejabberd_config:get_option(
- {pgsql_users_number_estimate, LServer}, false) of
+ ejabberd_option:pgsql_users_number_estimate(LServer) of
true ->
ejabberd_sql:sql_query_t(
?SQL("select @(reltuples :: bigint)d from pg_class"
@@ -349,8 +346,3 @@ export(_Server) ->
(_Host, _R) ->
[]
end}].
-
--spec opt_type(atom()) -> fun((any()) -> any()) | [atom()].
-opt_type(pgsql_users_number_estimate) ->
- fun (V) when is_boolean(V) -> V end;
-opt_type(_) -> [pgsql_users_number_estimate].