Browse Source

some refactoring

Maxim Sokhatsky 12 years ago
parent
commit
56ff67d99a
5 changed files with 29 additions and 11 deletions
  1. 18 0
      LICENSE
  2. 2 2
      src/kvs.erl
  3. 1 1
      src/kvs_account.erl
  4. 1 1
      src/kvs_group.erl
  5. 7 7
      src/kvs_user.erl

+ 18 - 0
LICENSE

@@ -0,0 +1,18 @@
+Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+Software should be used for the great good and the true happiness of all sentient beings.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

+ 2 - 2
src/kvs.erl

@@ -117,7 +117,7 @@ add_sample_users() ->
         [ kvs_group:join(Me#user.username,G#group.id) || G <- Groups ],
           kvs_account:create_account(Me#user.username),
           kvs_account:transaction(Me#user.username, quota, Quota, #tx_default_assignment{}),
-          kvs:put(Me#user{password = sha(Me#user.password), starred = kvs_feed:create(), pinned = kvs_feed:create()})
+          kvs:put(Me#user{password = kvs:sha(Me#user.password), starred = kvs_feed:create(), pinned = kvs_feed:create()})
       end || Me <- UserList ],
 
     kvs_acl:define_access({user, "maxim"},    {feature, admin}, allow),
@@ -226,7 +226,7 @@ make_paid_fake(UId) ->
 
 save(Dir, Value) ->
     filelib:ensure_dir(Dir),
-    file:write_file(Key, term_to_binary(Value)).
+    file:write_file(Dir, term_to_binary(Value)).
 
 load(Key) ->
     {ok, Bin} = file:read_file(Key),

+ 1 - 1
src/kvs_account.erl

@@ -30,7 +30,7 @@ balance(AccountId, Currency) ->
          {ok, #account{debet = Debet, credit = Credit}} -> {ok, Debet - Credit};
          Error -> Error end.
 
-create_account(AccountId) -> [ kvs:put(#account{id={AccountId, Currency}) || Currency <- get_currencies() ].
+create_account(AccountId) -> [ kvs:put(#account{id={AccountId, Currency}}) || Currency <- get_currencies() ].
 
 check_quota(User) -> check_quota(User, 0).
 check_quota(User, Amount) ->

+ 1 - 1
src/kvs_group.erl

@@ -191,6 +191,6 @@ subscription_mq(Type, Action, Who, Where) ->
         {ok,Channel} ->
             case {Type,Action} of 
                 {group,add}     -> mqs_channel:bind_exchange(Channel, ?GROUP_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_group_feed(Where));
-                {groupr,remove}  -> mqs_channel:unbind_exchange(Channel, ?GROUP_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_group_feed(Where));
+                {groupr,remove}  -> mqs_channel:unbind_exchange(Channel, ?GROUP_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_group_feed(Where)) end,
             mqs_channel:close(Channel);
         {error,Reason} -> ?ERROR("subscription_mq error: ~p",[Reason]) end.

+ 7 - 7
src/kvs_user.erl

@@ -18,19 +18,19 @@ register(#user{username=UserName, email=Email, facebook_id = FacebookId} = Regis
             {ok, _} -> {error, email_taken} end end,
 
     GroupUser = case EmailUser of
-        {error, Reason} -> {error, Reason};
-        {ok, Name} -> case kvs_group:get(Name) of
-            {error, _} -> {ok, Name};
+        {error, Reason2} -> {error, Reason2};
+        {ok, Name2} -> case kvs_group:get(Name2) of
+            {error, _} -> {ok, Name2};
             {ok,_} -> {error, username_taken} end end,
 
-    case Group of
-        {ok, Name} -> process_register(Registeration#user{username=Name});
+    case GroupUser of
+        {ok, Name3} -> process_register(Registeration#user{username=Name3});
         Error -> Error end.
 
 process_register(#user{username=U} = RegisterData0) ->
     HashedPassword = case RegisterData0#user.password of
         undefined -> undefined;
-        PlainPassword -> sha(PlainPassword) end,
+        PlainPassword -> kvs:sha(PlainPassword) end,
     RegisterData = RegisterData0#user {
         feed     = kvs:feed_create(),
         direct   = kvs:feed_create(),
@@ -95,7 +95,7 @@ subscription_mq(Type, Action, Who, Whom) ->
         {ok,Channel} ->
             case {Type,Action} of 
                 {user,add}     -> mqs_channel:bind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_user_feed(Whom));
-                {user,remove}  -> mqs_channel:unbind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_user_feed(Whom));
+                {user,remove}  -> mqs_channel:unbind_exchange(Channel, ?USER_EXCHANGE(Who), ?NOTIFICATIONS_EX, rk_user_feed(Whom)) end,
             mqs_channel:close(Channel);
         {error,Reason} -> ?ERROR("subscription_mq error: ~p",[Reason]) end.