Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lbalzs.soft.moviedb;
- import android.content.Context;
- import android.content.Intent;
- import android.os.AsyncTask;
- import android.support.design.widget.Snackbar;
- import android.view.View;
- import android.widget.TextView;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URI;
- import java.net.URL;
- public class SignIn extends AsyncTask{
- private String userName;
- private String password;
- private Context context;
- private TextView status;
- public SignIn(String username, String password, TextView status, Context context){
- this.userName = username;
- this.password = password;
- this.context = context;
- this.status = status;
- }
- @Override
- protected Object doInBackground(Object[] objects) {
- try{
- String link = "http://users.atw.hu/moviedb/validatelogin.php?username="+userName+"&&password="+password;
- URL url = new URL(link);
- HttpClient client = new DefaultHttpClient();
- HttpGet request = new HttpGet();
- request.setURI(new URI(link));
- HttpResponse response = client.execute(request);
- BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- StringBuffer sb = new StringBuffer("");
- String line = "";
- while ((line = in.readLine()) != null){
- sb.append(line);
- }
- in.close();
- if(userName.equals("") || password.equals("")){
- return "entercredentials";
- }
- if(sb.toString().length() != 0){
- if(sb.toString().equals("nouserfound")){
- return "nouser";
- }
- else return sb.toString();
- }
- else {
- return "enterusername";
- }
- } catch(Exception e){
- return new String("fail");
- }
- }
- @Override
- protected void onPostExecute(Object o){
- String a = o.toString();
- if(!a.equals("nouser") && !a.equals("entercredentials")){
- Intent intent = new Intent(context, MainActivity.class);
- intent.putExtra("UNAME", a);
- context.startActivity(intent);
- }
- else if(a.equals("nouser")){
- Snackbar mySnackbar = Snackbar.make(this.findViewById(R.id.login_lay) , "User not found!", Snackbar.LENGTH_SHORT);
- mySnackbar.show();
- }
- else if(a.equals("entercredentials")){
- status.setText("Please enter your credentials");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement