anchor.diff:          Id ->  string:to_lower(Id)
       end.
   
  +
   %% @doc
   %% Function: add_server_side_fields/1
   %% Purpose: Used to add all the fields that should be added server side
  
positive.code:             {description, Description},
              {image_url, URL},
              {access_token, AccToken},
              {refresh_token, RefToken}
          ]
      }).
  
  
  -spec user_is_new(UserData::string()) -> tuple().
  user_is_new(UserData) ->
      Username = binary_to_list(proplists:get_value(<<"id">>, UserData)),
      check_and_sanitize(Username).
      % Username = binary_to_list(lib_json:get_field(UserJSON, "username")),
      % case check_and_sanitize(Username) of
      %     invalidcharacters ->
  
negative.code: %% @end
  -spec process_post(ReqData::tuple(), State::string()) -> {true, tuple(), string()}.
  process_post(ReqData, State) ->
      URIList = string:tokens(wrq:path(ReqData), "/"),
      Req = string:sub_string(lists:nth(length(URIList),URIList),1,7),
      case Req of
          "_auth"   -> process_auth_request(ReqData, State);
          "_signin" -> process_signin(ReqData, State);
          "_search" -> process_search(ReqData, State, post);
          _ -> create_user(ReqData, State)
      end.
      % case api_help:is_auth(ReqData) of
      %     true  -> process_auth_request(ReqData, State);
      %     false ->
      %         case api_help:is_search(ReqData) of
      %             true  -> process_search(ReqData,State, post);
      %             false -> create_user(ReqData, State)
      %         end
      % end.
  
  -spec process_signin(ReqData::string(), State::string()) -> {true, tuple(), string()}.
  process_signin(ReqData, State) ->
  
      .
  
  -spec create_user(ReqData::tuple(), State::string()) -> {true, tuple(), string()}.
  create_user(ReqData, State) ->
      {UserJson, _, _} = api_help:json_handler(ReqData, State),
  
      case lib_json:get_field(UserJson, "username") of
          undefined ->
              UserName = undefined,
              UserNameApproved = false;
          UserBinary ->
              %% CHECK AND SANITIZE USERNAME
              UserName = string:to_lower(binary_to_list(UserBinary)),
              UserNameApproved = check_and_sanitize(UserName)
      end,
  
      case {api_help:do_only_fields_exist(UserJson,?ACCEPTEDFIELDSUSERS),UserNameApproved,UserName =/= undefined} of
          {_,_,false} ->
              {{halt,403}, wrq:set_resp_body("Username missing", ReqData), State};
          {false,_,_} ->
              {{halt,403}, wrq:set_resp_body("Unsupported field(s)", ReqData), State};
          {true,false,_} ->
              {{halt,409}, wrq:set_resp_body("Non unique username given", ReqData), State};
          {true,invalidcharacters,_} ->
              {{halt,409}, wrq:set_resp_body("Invalid characters in username. You may only use a-z, 0-9, _ and -", ReqData), State};
          {true,{Code1,Body1},_} ->
              ErrorString1 = api_help:generate_error(Body1, Code1),
              {{halt, Code1}, wrq:set_resp_body(ErrorString1, ReqData), State};
          {true,true,_} ->
              NewUserJson = lib_json:replace_field(UserJson, "username", list_to_binary(UserName)),
              FieldsAdded = add_server_side_fields(NewUserJson),
              JSON = add_access_token(FieldsAdded),
              case erlastic_search:index_doc_with_id(?INDEX, "user", UserName, JSON) of
                  {error, {Code2, Body2}} ->
                      ErrorString2 = api_help:generate_error(Body2, Code2),
                      {{halt, Code2}, wrq:set_resp_body(ErrorString2, ReqData), State};
                  {ok,List} ->
                      {true, wrq:set_resp_body(lib_json:encode(List), ReqData), State}
              end
      end.
  
  