Browse Source

switch back to user provided by kvs 3.4

Andrii Zadorozhnii 8 years ago
parent
commit
5cb8821a99
10 changed files with 31 additions and 68 deletions
  1. 0 26
      include/avz_user.hrl
  2. 3 3
      rebar.config
  3. 5 5
      src/avz.erl
  4. 0 11
      src/avz_user.erl
  5. 3 3
      src/email.erl
  6. 4 4
      src/facebook.erl
  7. 5 5
      src/github.erl
  8. 4 4
      src/google.erl
  9. 3 3
      src/microsoft.erl
  10. 4 4
      src/twitter.erl

+ 0 - 26
include/avz_user.hrl

@@ -1,26 +0,0 @@
--ifndef(AVZ_USER_HRL).
--define(AVZ_USER_HRL, true).
-
--include_lib("kvs/include/kvs.hrl").
-
--record(avz_user,
-        {?ITERATOR(feed, true),
-         email,
-         username,
-         password,
-         display_name,
-         register_date,
-         tokens = [],
-         images,
-         names,
-         surnames,
-         birth,
-         sex,
-         date,
-         status,
-         zone,
-         type,
-         comments = []
-        }).
-
--endif.

+ 3 - 3
rebar.config

@@ -1,9 +1,9 @@
 {lib_dirs, ["deps",".."]}.
 {lib_dirs, ["deps",".."]}.
 {deps_dir, ["deps"]}.
 {deps_dir, ["deps"]}.
 {deps, [
 {deps, [
-    {nitro,         ".*", {git, "git://github.com/synrc/nitro",             {tag,"1.1"}}},
-    {n2o,           ".*", {git, "git://github.com/synrc/n2o",               {tag,"3.1"}}},
-    {kvs,           ".*", {git, "git://github.com/synrc/kvs",               {tag,"3.1"}}},
+    {nitro,         ".*", {git, "git://github.com/synrc/nitro",             {tag,"1.4"}}},
+    {n2o,           ".*", {git, "git://github.com/synrc/n2o",               {tag,"3.4"}}},
+    {kvs,           ".*", {git, "git://github.com/synrc/kvs",               {tag,"3.4"}}},
     {erlydtl,       ".*", {git, "git://github.com/evanmiller/erlydtl.git",  {tag,"0.8.0"}}},
     {erlydtl,       ".*", {git, "git://github.com/evanmiller/erlydtl.git",  {tag,"0.8.0"}}},
     {oauth,         ".*", {git, "git://github.com/tim/erlang-oauth",        {tag, "v1.6.0"}}}
     {oauth,         ".*", {git, "git://github.com/tim/erlang-oauth",        {tag, "v1.6.0"}}}
 ]}.
 ]}.

+ 5 - 5
src/avz.erl

@@ -1,7 +1,7 @@
 -module(avz).
 -module(avz).
 -author('Maxim Sokhatsky').
 -author('Maxim Sokhatsky').
 -compile(export_all).
 -compile(export_all).
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
 
 
@@ -19,8 +19,8 @@ buttons(Methods)   -> [ M:login_button() || M <- Methods].
 event(init) -> [];
 event(init) -> [];
 event(logout) -> wf:user(undefined), wf:redirect(?LOGIN_PAGE);
 event(logout) -> wf:user(undefined), wf:redirect(?LOGIN_PAGE);
 event(to_login) -> wf:redirect(?LOGIN_PAGE);
 event(to_login) -> wf:redirect(?LOGIN_PAGE);
-event({register, #avz_user{}=U}) -> kvs:put(U), login_user(U); % sample
-event({login, #avz_user{}=U, N}) -> Updated = merge(U,N), kvs:put(Updated), login_user(Updated); % sample
+event({register, #user{}=U}) -> kvs:put(U), login_user(U); % sample
+event({login, #user{}=U, N}) -> Updated = merge(U,N), kvs:put(Updated), login_user(Updated); % sample
 event({error, E}) -> (?CTX#cx.module):event({login_failed, E});
 event({error, E}) -> (?CTX#cx.module):event({login_failed, E});
 event({Method,Event}) -> Method:event({Method,Event});
 event({Method,Event}) -> Method:event({Method,Event});
 event(Ev) ->  wf:info(?MODULE,"Page Event ~p",[Ev]).
 event(Ev) ->  wf:info(?MODULE,"Page Event ~p",[Ev]).
@@ -35,12 +35,12 @@ 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) ->
     n2o_session:ensure_sid([],?CTX,[]),
     n2o_session:ensure_sid([],?CTX,[]),
-    case kvs:get(avz_user,Key:email_prop(Args,Key)) of
+    case kvs:get(user,Key:email_prop(Args,Key)) of
         {ok,Existed} ->
         {ok,Existed} ->
             RegData = Key:registration_data(Args, Key, Existed),
             RegData = Key:registration_data(Args, Key, Existed),
             (?CTX#cx.module):event({login, Existed, RegData});
             (?CTX#cx.module):event({login, Existed, RegData});
         {error,_} ->
         {error,_} ->
-            RegData = Key:registration_data(Args, Key, #avz_user{}),
+            RegData = Key:registration_data(Args, Key, #user{}),
             (?CTX#cx.module):event({register, RegData});
             (?CTX#cx.module):event({register, RegData});
         U -> wf:info(?MODULE,"Unknown Login: ~p",[U]) end.
         U -> wf:info(?MODULE,"Unknown Login: ~p",[U]) end.
 
 

+ 0 - 11
src/avz_user.erl

@@ -1,11 +0,0 @@
-
--module(avz_user).
--include("avz_user.hrl").
--include_lib("kvs/include/metainfo.hrl").
--compile(export_all).
-metainfo() ->
-    #schema{name = kvs,
-            tables = [#table{name = avz_user,
-                           container = feed,
-                           fields = record_info(fields, avz_user),
-                           keys = [email]}]}.

+ 3 - 3
src/email.erl

@@ -3,17 +3,17 @@
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 -compile(export_all).
 -compile(export_all).
 -export(?API).
 -export(?API).
 
 
 registration_data(Props, email, Ori)->
 registration_data(Props, email, Ori)->
   Email = email_prop(Props, email),
   Email = email_prop(Props, email),
-  Ori#avz_user{ id = Email,
+  Ori#user{ id = Email,
             display_name = Email,
             display_name = Email,
             email = Email,
             email = Email,
             register_date = os:timestamp(),
             register_date = os:timestamp(),
-            tokens = avz:update({email,Email},Ori#avz_user.tokens),
+            tokens = avz:update({email,Email},Ori#user.tokens),
             status = ok,
             status = ok,
             password = avz:sha(proplists:get_value(<<"password">>,Props))}.
             password = avz:sha(proplists:get_value(<<"password">>,Props))}.
 
 

+ 4 - 4
src/facebook.erl

@@ -3,7 +3,7 @@
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 
 
 -compile(export_all).
 -compile(export_all).
 -export(?API).
 -export(?API).
@@ -22,13 +22,13 @@ registration_data(Props, facebook, Ori)->
     Email = email_prop(Props, facebook),
     Email = email_prop(Props, facebook),
     [UserName|_] = string:tokens(binary_to_list(Email),"@"),
     [UserName|_] = string:tokens(binary_to_list(Email),"@"),
     Cover = case proplists:get_value(<<"cover">>,Props) of undefined -> ""; {P} -> case proplists:get_value(<<"source">>,P) of undefined -> ""; C -> binary_to_list(C) end end,
     Cover = case proplists:get_value(<<"cover">>,Props) of undefined -> ""; {P} -> case proplists:get_value(<<"source">>,P) of undefined -> ""; C -> binary_to_list(C) end end,
-    Ori#avz_user{   id = Email,
+    Ori#user{   id = Email,
                 display_name = UserName,
                 display_name = UserName,
-                images = avz:update({fb_cover,Cover},avz:update({fb_avatar,"https://graph.facebook.com/" ++ binary_to_list(Id) ++ "/picture?type=large"},Ori#avz_user.images)),
+                images = avz:update({fb_cover,Cover},avz:update({fb_avatar,"https://graph.facebook.com/" ++ binary_to_list(Id) ++ "/picture?type=large"},Ori#user.images)),
                 email = Email,
                 email = Email,
                 names = proplists:get_value(<<"first_name">>, Props),
                 names = proplists:get_value(<<"first_name">>, Props),
                 surnames = proplists:get_value(<<"last_name">>, Props),
                 surnames = proplists:get_value(<<"last_name">>, Props),
-                tokens = avz:update({facebook,Id},Ori#avz_user.tokens),
+                tokens = avz:update({facebook,Id},Ori#user.tokens),
                 birth = {element(3, BirthDay), element(1, BirthDay), element(2, BirthDay)},
                 birth = {element(3, BirthDay), element(1, BirthDay), element(2, BirthDay)},
                 register_date = os:timestamp(),
                 register_date = os:timestamp(),
                 status = ok }.
                 status = ok }.

+ 5 - 5
src/github.erl

@@ -2,7 +2,7 @@
 -author('Andrii Zadorozhnii').
 -author('Andrii Zadorozhnii').
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
 -compile(export_all).
 -compile(export_all).
 -export(?API).
 -export(?API).
@@ -53,14 +53,14 @@ registration_data(Props, github, Ori) ->
     Id = proplists:get_value(<<"id">>, Props),
     Id = proplists:get_value(<<"id">>, Props),
     Name = proplists:get_value(<<"name">>, Props),
     Name = proplists:get_value(<<"name">>, Props),
     Email = email_prop(Props, github),
     Email = email_prop(Props, github),
-    Ori#avz_user{   id= Email,
+    Ori#user{   id= Email,
                 username = binary_to_list(proplists:get_value(<<"login">>, Props)),
                 username = binary_to_list(proplists:get_value(<<"login">>, Props)),
                 display_name = Name,
                 display_name = Name,
-                images = avz:update({gh_avatar,proplists:get_value(<<"avatar_url">>, Props)},Ori#avz_user.images),
+                images = avz:update({gh_avatar,proplists:get_value(<<"avatar_url">>, Props)},Ori#user.images),
                 email = Email,
                 email = Email,
                 names  = Name,
                 names  = Name,
                 surnames = [],
                 surnames = [],
-                tokens = avz:update({github,Id},Ori#avz_user.tokens),
+                tokens = avz:update({github,Id},Ori#user.tokens),
                 register_date = os:timestamp(),
                 register_date = os:timestamp(),
                 status = ok }.
                 status = ok }.
 
 
@@ -68,7 +68,7 @@ email_prop(Props, github) ->
     Mail = proplists:get_value(<<"email">>, Props, undefined),
     Mail = proplists:get_value(<<"email">>, Props, undefined),
     L = wf:to_list(Mail),
     L = wf:to_list(Mail),
     case avz_validator:is_email(L) of
     case avz_validator:is_email(L) of
-        true -> L;
+        true -> Mail;
         false -> binary_to_list(proplists:get_value(<<"login">>, Props)) ++ "@github"
         false -> binary_to_list(proplists:get_value(<<"login">>, Props)) ++ "@github"
     end.
     end.
 
 

+ 4 - 4
src/google.erl

@@ -3,7 +3,7 @@
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 -compile(export_all).
 -compile(export_all).
 -export(?API).
 -export(?API).
 
 
@@ -25,13 +25,13 @@ registration_data(Props, google, Ori)->
     GivenName = proplists:get_value(<<"ofa">>, Props),
     GivenName = proplists:get_value(<<"ofa">>, Props),
     FamilyName = proplists:get_value(<<"wea">>, Props),
     FamilyName = proplists:get_value(<<"wea">>, Props),
     Email = email_prop(Props,google),
     Email = email_prop(Props,google),
-    Ori#avz_user{id = Email,
+    Ori#user{id = Email,
                 display_name = Name,
                 display_name = Name,
-                images = avz:update({google_avatar,Image},Ori#avz_user.images),
+                images = avz:update({google_avatar,Image},Ori#user.images),
                 email = Email,
                 email = Email,
                 names = GivenName,
                 names = GivenName,
                 surnames = FamilyName,
                 surnames = FamilyName,
-                tokens = avz:update({google,Id},Ori#avz_user.tokens),
+                tokens = avz:update({google,Id},Ori#user.tokens),
                 register_date = os:timestamp(),
                 register_date = os:timestamp(),
                 % sex = proplists:get_value(<<"gender">>, Props),
                 % sex = proplists:get_value(<<"gender">>, Props),
                 status = ok }.
                 status = ok }.

+ 3 - 3
src/microsoft.erl

@@ -3,7 +3,7 @@
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 -compile(export_all).
 -compile(export_all).
 -export(?API).
 -export(?API).
 
 
@@ -37,12 +37,12 @@ registration_data(Props, microsoft, Ori)->
     GivenName = proplists:get_value(<<"givenName">>, Props),
     GivenName = proplists:get_value(<<"givenName">>, Props),
     FamilyName = proplists:get_value(<<"surname">>, Props),
     FamilyName = proplists:get_value(<<"surname">>, Props),
     Email = email_prop(Props,microsoft),
     Email = email_prop(Props,microsoft),
-    Ori#avz_user{ id = Email,
+    Ori#user{ id = Email,
                 display_name = proplists:get_value(<<"displayName">>, Props),
                 display_name = proplists:get_value(<<"displayName">>, Props),
                 email = Email,
                 email = Email,
                 names = GivenName,
                 names = GivenName,
                 surnames = FamilyName,
                 surnames = FamilyName,
-                tokens = avz:update({microsoft,Id},Ori#avz_user.tokens),
+                tokens = avz:update({microsoft,Id},Ori#user.tokens),
                 register_date = os:timestamp(),
                 register_date = os:timestamp(),
                 sex = proplists:get_value(<<"gender">>, Props),
                 sex = proplists:get_value(<<"gender">>, Props),
                 status = ok }.
                 status = ok }.

+ 4 - 4
src/twitter.erl

@@ -3,7 +3,7 @@
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("n2o/include/wf.hrl").
 -include_lib("avz/include/avz.hrl").
 -include_lib("avz/include/avz.hrl").
--include_lib("avz/include/avz_user.hrl").
+-include_lib("kvs/include/user.hrl").
 -compile(export_all).
 -compile(export_all).
 -export(?API).
 -export(?API).
 -define(CONSUMER_KEY,    application:get_env(avz, tw_consumer_key,    [])).
 -define(CONSUMER_KEY,    application:get_env(avz, tw_consumer_key,    [])).
@@ -14,14 +14,14 @@ registration_data(Props, twitter, Ori)->
     Id = proplists:get_value(<<"id_str">>, Props),
     Id = proplists:get_value(<<"id_str">>, Props),
     UserName = binary_to_list(proplists:get_value(<<"screen_name">>, Props)),
     UserName = binary_to_list(proplists:get_value(<<"screen_name">>, Props)),
     Email = email_prop(Props,twitter),
     Email = email_prop(Props,twitter),
-    Ori#avz_user{   id = Email,
+    Ori#user{   id = Email,
                 username = re:replace(UserName, "\\.", "_", [{return, list}]),
                 username = re:replace(UserName, "\\.", "_", [{return, list}]),
                 display_name = proplists:get_value(<<"screen_name">>, Props),
                 display_name = proplists:get_value(<<"screen_name">>, Props),
-                images = avz:update({tw_avatar,proplists:get_value(<<"profile_image_url">>, Props)},Ori#avz_user.images),
+                images = avz:update({tw_avatar,proplists:get_value(<<"profile_image_url">>, Props)},Ori#user.images),
                 names = proplists:get_value(<<"name">>, Props),
                 names = proplists:get_value(<<"name">>, Props),
                 email = Email,
                 email = Email,
                 surnames = [],
                 surnames = [],
-                tokens = avz:update({twitter,Id},Ori#avz_user.tokens),
+                tokens = avz:update({twitter,Id},Ori#user.tokens),
                 register_date = os:timestamp(),
                 register_date = os:timestamp(),
                 status = ok }.
                 status = ok }.