Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def handle_call({:become_admin, %{user: user_uuid, password: password}}, _from, state) do
- cond do
- state.password != password ->
- {:reply, %{status: :error, message: "invalid password"}, state}
- !Map.has_key?(state.users, user_uuid) ->
- {:reply, %{status: :error, message: "invalid user"}, state}
- true ->
- state = put_in(state.users[user_uuid].is_admin?, true)
- {:reply, %{status: :ok, message: state.users}, state}
- end
- end
- def handle_call({:user_promote, %{admin: admin, user_uuid: user_uuid}}, _from, state) do
- cond do
- !Map.has_key?(state.users, admin) || !state.users[admin].is_admin? ->
- {:reply, %{status: :error, message: "invalid admin"}, state}
- true ->
- handle_call({:become_admin, %{user: user_uuid, password: state.password}}, {}, state)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement