|
@@ -1,11 +1,28 @@
|
|
-module(avz).
|
|
-module(avz).
|
|
--author('Maxim Sokhatsky').
|
|
|
|
--compile([export_all, nowarn_export_all]).
|
|
|
|
|
|
+%%-author('Maxim Sokhatsky').
|
|
|
|
+
|
|
-include_lib("avz/include/avz.hrl").
|
|
-include_lib("avz/include/avz.hrl").
|
|
--include_lib("n2o/include/wf.hrl").
|
|
|
|
|
|
+-include_lib("n4u/include/wf.hrl"). %% todo unbind avz -- todo avz usage example without nitro and n4u (n2o v4.4 fork) framework
|
|
-include_lib("kvs/include/metainfo.hrl").
|
|
-include_lib("kvs/include/metainfo.hrl").
|
|
-include_lib("kvs/include/user.hrl").
|
|
-include_lib("kvs/include/user.hrl").
|
|
|
|
|
|
|
|
+
|
|
|
|
+-export([
|
|
|
|
+ sha/1,
|
|
|
|
+ update/2,
|
|
|
|
+ coalesce/2,
|
|
|
|
+ merge/2,
|
|
|
|
+ callbacks/1,
|
|
|
|
+ sdk/1,
|
|
|
|
+ buttons/1,
|
|
|
|
+ event/1,
|
|
|
|
+ api_event/3,
|
|
|
|
+ login_user/1,
|
|
|
|
+ login/2,
|
|
|
|
+ version/0
|
|
|
|
+]).
|
|
|
|
+
|
|
|
|
+
|
|
sha(Pass) -> crypto:hmac(wf:config(n2o,hmac,sha256),n2o_secret:secret(),wf:to_binary(Pass)).
|
|
sha(Pass) -> crypto:hmac(wf:config(n2o,hmac,sha256),n2o_secret:secret(),wf:to_binary(Pass)).
|
|
update({K,V},P) -> wf:setkey(K,1,case P of undefined -> []; _P -> _P end,{K,V}).
|
|
update({K,V},P) -> wf:setkey(K,1,case P of undefined -> []; _P -> _P end,{K,V}).
|
|
|
|
|
|
@@ -35,7 +52,6 @@ api_event(Name, Args, Term) -> wf:info(?MODULE,"Unknown API event: ~p ~p ~p
|
|
login_user(User) -> wf:user(User), wf:redirect(?AFTER_LOGIN).
|
|
login_user(User) -> wf:user(User), wf:redirect(?AFTER_LOGIN).
|
|
login(_Key, [{error, E}|_Rest])-> wf:info(?MODULE,"Auth Error: ~p", [E]);
|
|
login(_Key, [{error, E}|_Rest])-> wf:info(?MODULE,"Auth Error: ~p", [E]);
|
|
login(Key, Args) ->
|
|
login(Key, Args) ->
|
|
-
|
|
|
|
LoginFun = fun(K) ->
|
|
LoginFun = fun(K) ->
|
|
Index = proplists:get_value(Key:index(K), Args),
|
|
Index = proplists:get_value(Key:index(K), Args),
|
|
case kvs:index(user,K,Index) of
|
|
case kvs:index(user,K,Index) of
|
|
@@ -46,12 +62,11 @@ login(Key, Args) ->
|
|
_ -> false end end,
|
|
_ -> false end end,
|
|
|
|
|
|
Keys = [K || M<-kvs:modules(),T<-(M:metainfo())#schema.tables, T#table.name==user, K<-T#table.keys],
|
|
Keys = [K || M<-kvs:modules(),T<-(M:metainfo())#schema.tables, T#table.name==user, K<-T#table.keys],
|
|
-
|
|
|
|
LoggedIn = lists:any(LoginFun, Keys),
|
|
LoggedIn = lists:any(LoginFun, Keys),
|
|
-
|
|
|
|
if (LoggedIn =:= true) -> ok; true ->
|
|
if (LoggedIn =:= true) -> ok; true ->
|
|
RegData = Key:registration_data(Args, Key, #user{}),
|
|
RegData = Key:registration_data(Args, Key, #user{}),
|
|
(?CTX#cx.module):event({register, RegData})
|
|
(?CTX#cx.module):event({register, RegData})
|
|
end.
|
|
end.
|
|
|
|
|
|
version() -> proplists:get_value(vsn,element(2,application:get_all_key(?MODULE))).
|
|
version() -> proplists:get_value(vsn,element(2,application:get_all_key(?MODULE))).
|
|
|
|
+
|