Registration Screen - User Replay

0

I have a post code, which registers my users, but they can be repeated, I would like help to make a code so that users can not repeat themselves, however I am new to Android and I do not know how to do this , my code:

public class onbuttonclickHttpPost  extends AsyncTask<String, Void, String> {

            protected void onPreExecute() {
            }


            protected String doInBackground(String... arg0) {


                try {


                    URL url = new URL("http://192.168.1.207/api/v2/bookdemo/_table/cad_users");

                    JSONObject postDataParams = new JSONObject();


                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setRequestProperty("Content-type", "application/json");
                    conn.setRequestProperty("Accept", "application/json");
                    conn.setRequestProperty("X-DreamFactory-Api-Key", "XXXXXXXX");
                    conn.setRequestProperty("X-DreamFactory-Session-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjE0LCJ1c2VyX2lkIjoxNCwiZW1haWwiOiJ0aGlhZ28uY2FtYXJnb0Bldm9sdXRpb25pdC5jb20uYnIiLCJmb3JldmVyIjpmYWxzZSwiaXNzXXXXXXXXmp0aSXXXXXXXXX.hiid9z55BD_THe-oJc6WpTropgVDE7gtw2m9TKayo-I");
                    conn.setRequestProperty("Authorization", "Basic XXXXX");
                    conn.setRequestMethod("POST");
                    conn.setReadTimeout(15000 /* milliseconds */);
                    conn.setConnectTimeout(15000 /* milliseconds */);
                    conn.setDoInput(true);
                    conn.setDoOutput(true);

                    postDataParams.put("tx_name", mName);
                    postDataParams.put("tx_nickname", mNick);
                    postDataParams.put("dt_nascimento", mData);
                    postDataParams.put("tp_sexo", mSexo);
                    postDataParams.put("nu_cellphone", mNumber);
                    postDataParams.put("password", mPassword);
                    postDataParams.put("tx_email", mEmail);
                    Log.e("resource", postDataParams.toString());


                    JSONObject resource = new JSONObject();
                    JSONArray array = new JSONArray();
                    array.put(postDataParams);
                    resource.put("resource", array);

                    System.out.println(resource.toString());



                    conn.connect();

                    OutputStream os = conn.getOutputStream();
                    BufferedWriter writer = new BufferedWriter(
                            new OutputStreamWriter(os, "UTF-8"));
                    //writer.write(getPostDataString(postDataParams));
                    writer.write(resource.toString());

                    writer.flush();
                    writer.close();
                    os.close();

                    int responseCode = conn.getResponseCode();





                    if (responseCode == HttpsURLConnection.HTTP_OK) {
                        Intent intent = new Intent(PostCadastro.this, LoginActivity.class);
                        startActivity(intent);


                        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                        StringBuffer sb = new StringBuffer("");
                        String line = "";



                        while ((line = in.readLine()) != null) {

                            sb.append(line);
                            break;
                        }

                        in.close();
                        return sb.toString();

                    } else {
                        return new String("false : " + responseCode);
                    }
                } catch (Exception e) {
                    return new String("Exception: " + e.getMessage());
                }
            }

            @Override
            protected void onPostExecute(String result) {
                Toast.makeText(getApplicationContext(), result,
                        Toast.LENGTH_LONG).show();

            }
        }
    private boolean hasContent(EditText et) {

        boolean bHasContent = false;

        if (et.getText().toString().trim().length() > 0) {
            // Got content
            bHasContent = true;
        }
        return bHasContent;
    }
}
    
asked by anonymous 22.05.2017 / 20:27

1 answer

2

You need to do this validation on the backend:

It would be necessary to create a search engine to be executed when the user clicks the register button, so before you insert it into the database, you would do a select to validate if it already exists this name in the table.

If it exists then you will need to return a message to the user on the registration screen. If it does not exist, you can successfully register it.

This mechanism can only be implemented in the backend.

    
22.05.2017 / 21:44