Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. def handle_call({:become_admin, %{user: user_uuid, password: password}}, _from, state) do
  2. cond do
  3. state.password != password ->
  4. {:reply, %{status: :error, message: "invalid password"}, state}
  5. !Map.has_key?(state.users, user_uuid) ->
  6. {:reply, %{status: :error, message: "invalid user"}, state}
  7. true ->
  8. state = put_in(state.users[user_uuid].is_admin?, true)
  9. {:reply, %{status: :ok, message: state.users}, state}
  10. end
  11. end
  12.  
  13. def handle_call({:user_promote, %{admin: admin, user_uuid: user_uuid}}, _from, state) do
  14. cond do
  15. !Map.has_key?(state.users, admin) || !state.users[admin].is_admin? ->
  16. {:reply, %{status: :error, message: "invalid admin"}, state}
  17. true ->
  18. handle_call({:become_admin, %{user: user_uuid, password: state.password}}, {}, state)
  19. end
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement