Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.naufal.restoapps_user;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.net.URLEncoder;
- /**
- * Created by Naufal on 1/2/2017.
- */
- public class login_client extends AsyncTask<String,String,String> {
- EditText usernamelogin, passwordcx;
- Context context;
- String username="cxcx",passwor="cxcx",identitcx;
- login login=new login();TextView text;
- int client=0;
- public login_client(Context applicationContext,TextView textView) {
- this.context = applicationContext;
- this.text=textView;
- }
- @Override
- protected void onProgressUpdate(String... values) {
- super.onProgressUpdate(values);
- Toast.makeText(context, "hmm...", Toast.LENGTH_SHORT).show();
- }
- @Override
- protected String doInBackground(String... params) {
- String link = "http://nwebtekno.comxa.com/profilephone.php";
- String valuecx = "";
- try {
- String username = namaclient();
- String password = passwclient();
- URL url = new URL(link);
- HttpURLConnection urlconection = (HttpURLConnection) url.openConnection();
- urlconection.setDoInput(true);
- urlconection.setDoOutput(true);
- urlconection.setRequestMethod("POST");
- OutputStream writer = urlconection.getOutputStream();
- BufferedWriter write = new BufferedWriter(new OutputStreamWriter(writer));
- String passing;
- passing = URLEncoder.encode("username") + "=";
- passing += username+"&";
- passing += URLEncoder.encode("password")+"=" +
- password;
- write.write(passing);
- write.flush();
- InputStream input = urlconection.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input));
- String value = "";
- while ((value = reader.readLine()) != null) {
- valuecx += value;
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return valuecx;
- }
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- Toast.makeText(context, "please cx", Toast.LENGTH_SHORT).show();
- }
- @Override
- protected void onPostExecute(String s) {
- super.onPostExecute(s);
- String wellcome = s;
- try {
- JSONObject jsonObject=new JSONObject(s);
- int checkprofile=jsonObject.getInt("checkprofilecheck");
- if (checkprofile == 1) {
- String identitas=jsonObject.getString("identitas");
- text.setText(identitas);
- String cx= login.check(identitas);
- this.identitcx=identitas;
- Toast.makeText(context,"somnething cx"+checkprofile+"identitas"+identitas+""+cx,Toast.LENGTH_SHORT).show();
- }else if(checkprofile==4){
- Toast.makeText(context,"somnething check something ",Toast.LENGTH_SHORT).show();
- } else if(checkprofile==0){
- Toast.makeText(context, "server checkcx", Toast.LENGTH_SHORT).show();
- }
- }catch(Exception e){
- Toast.makeText(context,"something "+e,Toast.LENGTH_SHORT).show();
- }
- }
- public void nama(String username){
- this.username=username;
- }
- public void passwor(String passwor){
- this.passwor=passwor;
- }
- public String namaclient(){
- return this.username;
- }
- public String passwclient() {
- return this.passwor;
- }
- public String identitas(){
- return this.identitcx;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement