Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected String doInBackground(String... params) {
- String type = params[0];
- String login_url = "https://www.example.com";
- if (type.equals("login")) {
- try {
- String email = params[1];
- String password = params[2];
- URL url = new URL(login_url);
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.setDoOutput(true);
- httpURLConnection.setDoInput(true);
- OutputStream outputStream = httpURLConnection.getOutputStream();
- BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
- String post_data = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8") + "&"
- + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password, "UTF-8");
- bufferedWriter.write(post_data);
- bufferedWriter.flush();
- bufferedWriter.close();
- outputStream.close();
- InputStream inputStream = httpURLConnection.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
- while ((line = bufferedReader.readLine()) != null) {
- result += line;
- }
- bufferedReader.close();
- inputStream.close();
- httpURLConnection.disconnect();
- JSONObject obj= null;
- try {
- obj = new JSONObject(result);
- String status=obj.getString("status");
- JSONObject data_obj=obj.getJSONObject("data");
- win_user=data_obj.getString("id");
- name=data_obj.getString("name");
- logo=data_obj.getString("logo");
- return win_user;
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return result;
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();}
- }
- return null;
- }
- @Override
- protected void onPreExecute() {
- alertDialog = new AlertDialog.Builder(context).create();
- alertDialog.setTitle("Login Status");
- }
- @Override
- protected void onPostExecute(String result) {
- if (result == null ) {
- Toast pass = Toast.makeText(context, "Email or Password is not match!", Toast.LENGTH_SHORT);
- pass.show();
- }
- else
- {
- context.startActivity( new Intent(context,Main.class));
- Main.JSON_STRING = result;
- Main.name = name;
- Main.logo = logo;
- }
- }
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement