fix(auth): move log outside of transaction
This commit is contained in:
parent
729ab6f60d
commit
4ba43d3aea
|
@ -63,7 +63,12 @@ force_add_user(Login, Password) ->
|
||||||
password = encrypted_data(Password),
|
password = encrypted_data(Password),
|
||||||
created_at = erlang:system_time(millisecond)
|
created_at = erlang:system_time(millisecond)
|
||||||
},
|
},
|
||||||
ret(mnesia:transaction(fun insert_or_update_user/2, [Password, User])).
|
case ret(mnesia:transaction(fun insert_or_update_user/2, [Password, User])) of
|
||||||
|
{ok, override} ->
|
||||||
|
?LOG(warning, "[Mnesia] (~p)'s password has be updated.", [Login]),
|
||||||
|
ok;
|
||||||
|
Other -> Other
|
||||||
|
end.
|
||||||
|
|
||||||
insert_or_update_user(NewPwd, User = #emqx_user{login = Login}) ->
|
insert_or_update_user(NewPwd, User = #emqx_user{login = Login}) ->
|
||||||
case mnesia:read(?TABLE, Login) of
|
case mnesia:read(?TABLE, Login) of
|
||||||
|
@ -72,9 +77,8 @@ insert_or_update_user(NewPwd, User = #emqx_user{login = Login}) ->
|
||||||
case emqx_auth_mnesia:match_password(NewPwd, hash_type(), [Pwd]) of
|
case emqx_auth_mnesia:match_password(NewPwd, hash_type(), [Pwd]) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false ->
|
false ->
|
||||||
Res = mnesia:write(User),
|
ok = mnesia:write(User),
|
||||||
?LOG(warning, "[Mnesia] (~p)'s password has be updated.", [Login]),
|
{ok, override}
|
||||||
Res
|
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -128,7 +132,7 @@ comparing({?TABLE, _, _, CreatedAt1},
|
||||||
{?TABLE, _, _, CreatedAt2}) ->
|
{?TABLE, _, _, CreatedAt2}) ->
|
||||||
CreatedAt1 >= CreatedAt2.
|
CreatedAt1 >= CreatedAt2.
|
||||||
|
|
||||||
ret({atomic, ok}) -> ok;
|
ret({atomic, Res}) -> Res;
|
||||||
ret({aborted, Error}) -> {error, Error}.
|
ret({aborted, Error}) -> {error, Error}.
|
||||||
|
|
||||||
encrypted_data(Password) ->
|
encrypted_data(Password) ->
|
||||||
|
|
Loading…
Reference in New Issue