Skip to content

Commit

Permalink
feat: refresh_session
Browse files Browse the repository at this point in the history
  • Loading branch information
AvantLiu committed Nov 15, 2021
1 parent 04c6988 commit c56a594
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
12 changes: 6 additions & 6 deletions apps/dgiot_evidence/src/dgiot_evidence.erl
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ create_report(ProductParentId, Config, DevType, Name, Num, Imagurl, WordUrl, Ses
NewNum = dgiot_utils:to_binary(dgiot_utils:to_int(Num) + 1),
ProductName = <<Name/binary, NewNum/binary>>,
NodeType = 0,
NewConfig = maps:merge(#{<<"konva">> => #{
NewConfig = maps:merge(Config, #{<<"konva">> => #{
<<"Stage">> => #{<<"attrs">> => #{
<<"width">> => 1200,
<<"height">> => 700},
<<"width">> => 800,
<<"height">> => 1000},
<<"className">> => <<"Stage">>,
<<"children">> => [
#{<<"attrs">> => #{
Expand All @@ -538,8 +538,8 @@ create_report(ProductParentId, Config, DevType, Name, Num, Imagurl, WordUrl, Ses
#{<<"attrs">> => #{
<<"id">> => <<"bg">>,
<<"type">> => <<"bg-image">>,
<<"width">> => 1200,
<<"height">> => 700,
<<"width">> => 660,
<<"height">> => 935,
<<"src">> => Imagurl},
<<"className">> => <<"Image">>},
#{<<"attrs">> =>
Expand All @@ -553,7 +553,7 @@ create_report(ProductParentId, Config, DevType, Name, Num, Imagurl, WordUrl, Ses
<<"name">> => <<"dblclick">>,
<<"width">> => 72.04296875,
<<"height">> => 48.8},
<<"className">> => <<"Tag">>}]}]}]}}}, Config),
<<"className">> => <<"Tag">>}]}]}]}}}),
case dgiot_product:create_product(#{
<<"config">> => NewConfig#{
<<"reporttemp">> => dgiot_utils:to_binary(WordUrl)
Expand Down
22 changes: 6 additions & 16 deletions apps/dgiot_parse/priv/swagger/swagger_parse.json
Original file line number Diff line number Diff line change
Expand Up @@ -624,29 +624,19 @@
"tags": [
"_User"
]
},
"put": {
}
},
"/refresh_session": {
"get": {
"summary": "刷新Token",
"description": "刷新Token",
"parameters": [],
"responses": {
"200": {
"description": "Returns success",
"schema": {
"$ref": "#/definitions/Token"
}
"description": ""
},
"404": {
"description": "object not found",
"schema": {
"$ref": "#/definitions/Error"
}
},
"400": {
"description": "Bad Request"
},
"500": {
"description": "Server Internal error"
"description": ""
}
},
"tags": [
Expand Down
8 changes: 8 additions & 0 deletions apps/dgiot_parse/src/dgiot_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ get_sessionId(SessionToken) ->

get_objectid(Class, Map) ->
case Class of
<<"post_classes_session">> ->
get_objectid(<<"Session">>, Map);
<<"Session">> ->
SessionToken = maps:get(<<"sessionToken">>, Map, <<"">>),
<<Pid:10/binary, _/binary>> = dgiot_utils:to_md5(<<"_Session", SessionToken/binary>>),
Map#{
<<"objectId">> => Pid
};
<<"post_classes_article">> ->
get_objectid(<<"Article">>, Map);
<<"Article">> ->
Expand Down
18 changes: 12 additions & 6 deletions apps/dgiot_parse/src/handler/dgiot_parse_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,16 @@ handle(post_token, #{<<"appid">> := AppId, <<"secret">> := Secret}, _Context, _R
{error, Err} -> {500, Err}
end;

%% IoTDevice 概要: 获取应用token 描述:Token查询
%% OperationId: post_token
%% IoTDevice 概要: 刷新Token 描述:刷新Token
%% OperationId: get_refresh_session
%% POST /token
handle(put_token, _Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
dgiot_parse:refresh_session(SessionToken);
handle(get_refresh_session, _Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
case dgiot_parse:refresh_session(SessionToken) of
{ok, Ref} ->
{200, Ref};
{error, Err} ->
{500, Err}
end;

%% IoTDevice 概要: 获取应用token 描述:更新token
%% OperationId: put_token
Expand Down Expand Up @@ -690,8 +695,9 @@ put_user(#{<<"username">> := UserName, <<"department">> := RoleId} = Body, Sessi
%% 用户名和密码登录
login_by_account(UserName, Password) ->
case dgiot_parse:login(UserName, Password) of
{ok, UserInfo} ->
do_login(UserInfo);
{ok, #{<<"objectId">> := UserId} = _UserInfo} ->
create_session(UserId, dgiot_auth:ttl(), UserName);
%% do_login(UserInfo);
{error, Msg} ->
{error, Msg}
end.
Expand Down

0 comments on commit c56a594

Please sign in to comment.