fix: rename tab & params

This commit is contained in:
DDDHuang 2021-08-13 14:19:31 +08:00
parent 93dbdaa84a
commit 22dd6e1a86
7 changed files with 18 additions and 18 deletions

View File

@ -8,7 +8,7 @@ emqx_dashboard:{
## notice: sample_interval should be divisible by 60.
sample_interval: 10s
## api jwt timeout. default is 30 minute
jwt_exptime: 30m
token_expired_time: 60m
listeners: [
{
num_acceptors: 4

View File

@ -105,7 +105,7 @@ listener_name(Proto) ->
authorize_appid(Req) ->
case cowboy_req:parse_header(<<"authorization">>, Req) of
{bearer, Token} ->
case emqx_dashboard_admin:jwt_verify(Token) of
case emqx_dashboard_admin:verify_token(Token) of
ok ->
ok;
{error, token_timeout} ->

View File

@ -40,9 +40,9 @@
, check/2
]).
-export([ jwt_sign/2
, jwt_verify/1
, jwt_destroy_by_username/1
-export([ sign_token/2
, verify_token/1
, destroy_token_by_username/1
]).
-export([add_default_user/0]).
@ -166,20 +166,20 @@ check(Username, Password) ->
end.
%%--------------------------------------------------------------------
%% jwt
jwt_sign(Username, Password) ->
%% token
sign_token(Username, Password) ->
case check(Username, Password) of
ok ->
emqx_dashboard_jwt:sign(Username, Password);
emqx_dashboard_token:sign(Username, Password);
Error ->
Error
end.
jwt_verify(Token) ->
emqx_dashboard_jwt:verify(Token).
verify_token(Token) ->
emqx_dashboard_token:verify(Token).
jwt_destroy_by_username(Username) ->
emqx_dashboard_jwt:destroy_by_username(Username).
destroy_token_by_username(Username) ->
emqx_dashboard_token:destroy_by_username(Username).
%%--------------------------------------------------------------------
%% Internal functions

View File

@ -220,7 +220,7 @@ login(post, Request) ->
Params = emqx_json:decode(Body, [return_maps]),
Username = maps:get(<<"username">>, Params),
Password = maps:get(<<"password">>, Params),
case emqx_dashboard_admin:jwt_sign(Username, Password) of
case emqx_dashboard_admin:sign_token(Username, Password) of
{ok, Token} ->
Version = iolist_to_binary(proplists:get_value(version, emqx_sys:info())),
{200, #{token => Token, version => Version, license => #{edition => ?RELEASE}}};
@ -232,7 +232,7 @@ logout(_, Request) ->
{ok, Body, _} = cowboy_req:read_body(Request),
Params = emqx_json:decode(Body, [return_maps]),
Username = maps:get(<<"username">>, Params),
emqx_dashboard_admin:jwt_destroy_by_username(Username),
emqx_dashboard_admin:destroy_token_by_username(Username),
{200}.
users(get, _Request) ->

View File

@ -28,7 +28,7 @@ fields("emqx_dashboard") ->
, {default_username, fun default_username/1}
, {default_password, fun default_password/1}
, {sample_interval, emqx_schema:t(emqx_schema:duration_s(), undefined, "10s")}
, {jwt_exptime, emqx_schema:t(emqx_schema:duration(), undefined, "30m")}
, {token_expired_time, emqx_schema:t(emqx_schema:duration(), undefined, "30m")}
];
fields("http") ->

View File

@ -29,4 +29,4 @@ start_link() ->
init([]) ->
{ok, {{one_for_all, 10, 100},
[?CHILD(emqx_dashboard_jwt), ?CHILD(emqx_dashboard_collection)]}}.
[?CHILD(emqx_dashboard_token), ?CHILD(emqx_dashboard_collection)]}}.

View File

@ -14,7 +14,7 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_dashboard_jwt).
-module(emqx_dashboard_token).
-include("emqx_dashboard.hrl").
@ -148,7 +148,7 @@ jwk(Username, Password, Salt) ->
}.
jwt_expiration_time() ->
ExpTime = emqx_config:get([emqx_dashboard, jwt_exptime], ?EXPTIME),
ExpTime = emqx_config:get([emqx_dashboard, token_expired_time], ?EXPTIME),
erlang:system_time(millisecond) + ExpTime.
salt() ->