fix mysql auth error
This commit is contained in:
parent
f3dbb7ba54
commit
5a75e59dd1
|
@ -179,6 +179,7 @@ handle_call({register_mod, Type, Mod, Opts}, _From, State) ->
|
|||
ets:insert(?ACCESS_CONTROL_TAB, {tab_key(Type), [{Mod, ModState}|Mods]}),
|
||||
ok;
|
||||
{'EXIT', Error} ->
|
||||
lager:error("Access Control: register ~s error - ~p", [Mod, Error]),
|
||||
{error, Error}
|
||||
end;
|
||||
_ ->
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
]},
|
||||
{emqttd_auth_mysql, [
|
||||
{users_table, mqtt_users},
|
||||
{password_hash, plain},
|
||||
{field_mapper, [
|
||||
{username, username},
|
||||
{password, password, plain}
|
||||
{password, password}
|
||||
]}
|
||||
]}
|
||||
|
|
|
@ -38,15 +38,19 @@
|
|||
|
||||
init(Opts) ->
|
||||
Mapper = proplists:get_value(field_mapper, Opts),
|
||||
{ok, #state{user_table = proplists:get_value(user_table, Opts, mqtt_users),
|
||||
{ok, #state{user_table = proplists:get_value(user_table, Opts),
|
||||
name_field = proplists:get_value(username, Mapper),
|
||||
pass_field = proplists:get_value(password, Mapper),
|
||||
pass_hash = proplists:get_value(Opts, password_hash)}}.
|
||||
pass_hash = proplists:get_value(password_hash, Opts)}}.
|
||||
|
||||
check(#mqtt_client{username = undefined}, _Password, _State) ->
|
||||
{error, "Username undefined"};
|
||||
check(#mqtt_client{username = <<>>}, _Password, _State) ->
|
||||
{error, "Username undefined"};
|
||||
check(_Client, undefined, _State) ->
|
||||
{error, "Password undefined"};
|
||||
check(_Client, <<>>, _State) ->
|
||||
{error, "Password undefined"};
|
||||
check(#mqtt_client{username = Username}, Password,
|
||||
#state{user_table = UserTab, pass_hash = Type,
|
||||
name_field = NameField, pass_field = PassField}) ->
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
start(_StartType, _StartArgs) ->
|
||||
Env = application:get_all_env(),
|
||||
emqttd_access_control:register_mod(auth, emqttd_auth_mysql, Env),
|
||||
ok = emqttd_access_control:register_mod(auth, emqttd_auth_mysql, Env),
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
prep_stop(State) ->
|
||||
|
|
|
@ -9,7 +9,12 @@
|
|||
% {encoding, utf8}
|
||||
% ]},
|
||||
% {emqttd_auth_mysql, [
|
||||
% {user_table, mqtt_users}
|
||||
% {users_table, mqtt_users},
|
||||
% {password_hash, plain},
|
||||
% {field_mapper, [
|
||||
% {username, username},
|
||||
% {password, password}
|
||||
% ]}
|
||||
% ]}
|
||||
%
|
||||
% {emqttd_dashboard, [
|
||||
|
|
Loading…
Reference in New Issue