diff --git a/apps/dgiot/src/transport/dgiot_mqtt.erl b/apps/dgiot/src/transport/dgiot_mqtt.erl index 870f34ad..5a6c913f 100644 --- a/apps/dgiot/src/transport/dgiot_mqtt.erl +++ b/apps/dgiot/src/transport/dgiot_mqtt.erl @@ -48,6 +48,7 @@ , get_message/2 , subopts/0 , subscribe_route_key/3 + , unsubscribe_route_key/1 ]). init_ets() -> @@ -72,6 +73,20 @@ subscribe_route_key(DeviceList, SessionToken, Route) -> end, [], DeviceList), dgiot_data:insert(?DGIOT_ROUTE_KEY, {SessionToken, TopicKey}, DeviceList). + +unsubscribe_route_key(SessionToken) -> + TopicKey = devicestate, + case dgiot_data:get(?DGIOT_ROUTE_KEY, {SessionToken, TopicKey}) of + not_find -> + pass; + OldTopic -> + lists:foldl(fun(X, _Acc) -> + Topic = <<"$dg/user/devicestate/", X/binary, "/report">>, + dgiot_mqtt:unsubscribe(SessionToken, Topic) + end, [], OldTopic) + end, + dgiot_data:delete(?DGIOT_ROUTE_KEY, {SessionToken, TopicKey}). + has_routes(Topic) -> emqx_router:has_routes(Topic). diff --git a/apps/dgiot_parse/src/dgiot_parse_auth.erl b/apps/dgiot_parse/src/dgiot_parse_auth.erl index 66a65e71..479c4785 100644 --- a/apps/dgiot_parse/src/dgiot_parse_auth.erl +++ b/apps/dgiot_parse/src/dgiot_parse_auth.erl @@ -48,7 +48,7 @@ -export([create_user/2, delete_user/2, put_user/2, disableusere/3, check_roles/1]). -export([login_by_account/2, login_by_token/2, login_by_mail_phone/1, do_login/1]). -export([create_user_for_app/1, get_token/1, set_cookies/3, add_acl/5]). --export([get_usersession/1, put_usersession/1]). +-export([get_usersession/1, put_usersession/1,del_usersession/1]). init_ets() -> @@ -62,6 +62,20 @@ put_usersession(SessionMap) -> User_session = maps:get(Depart_token, SessionMap), dgiot_data:insert(?DGIOT_USERSESSION, {Depart_token}, User_session). +del_usersession(User_session)-> + Fun = fun + ({Key, Value}) -> + case Value of + User_session -> + dgiot_data:delete(?DGIOT_USERSESSION, Key); + _-> + pass + end ; + (_) -> + pass + end, + dgiot_data:loop(?DGIOT_USERSESSION, Fun). + %% 登录 diff --git a/apps/dgiot_parse/src/handler/dgiot_user_handler.erl b/apps/dgiot_parse/src/handler/dgiot_user_handler.erl index d889bf7f..285bde8e 100644 --- a/apps/dgiot_parse/src/handler/dgiot_user_handler.erl +++ b/apps/dgiot_parse/src/handler/dgiot_user_handler.erl @@ -206,7 +206,9 @@ do_request(post_login, #{<<"username">> := UserName, <<"password">> := Password} do_request(post_logout, #{<<"sessionToken">> := SessionToken}, _Context, _Req) -> dgiot_auth:delete_session(SessionToken), SessionId = dgiot_parse_id:get_sessionId(SessionToken), - dgiot_parse:del_object(<<"_Session">>, SessionId); + dgiot_parse:del_object(<<"_Session">>, SessionId), + dgiot_mqtt:unsubscribe_route_key(SessionToken), + dgiot_parse_auth:del_usersession(SessionToken); %% RoleUser 概要: 导库 描述:json文件导库 %% OperationId:get_roleuser