Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Login extends AppCompatActivity implements View.OnClickListener {
- Button bLogin;
- TextView registerLink;
- EditText etUsername, etPassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- bLogin = (Button) findViewById(R.id.bLogin);
- etUsername = (EditText) findViewById(R.id.etUsername);
- etPassword = (EditText) findViewById(R.id.etPassword);
- registerLink = (TextView) findViewById(R.id.tvRegisterLink);
- bLogin.setOnClickListener(this);
- registerLink.setOnClickListener(this);
- }
- @Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.bLogin:
- String Username = etUsername.getText().toString();
- String Password = etPassword.getText().toString();
- Toast.makeText(this, "Loginin...", Toast.LENGTH_SHORT).show();
- new Authenticate(this).execute(Username, Password);
- break;
- case R.id.tvRegisterLink:
- Intent registerIntent = new Intent(Login.this, Register.class);
- startActivity(registerIntent);
- break;
- }
- }
- public void ParentLogin()
- {
- String Username = etUsername.getText().toString();
- String Password = etPassword.getText().toString();
- Intent Main = new Intent(Login.this, MainActivity.class);
- Main.putExtra("class","Parent");
- Main.putExtra("username",Username);
- Main.putExtra("password",Password);
- startActivity(Main);
- }
- public void NannyLogin()
- {
- String Username = etUsername.getText().toString();
- String Password = etPassword.getText().toString();
- Intent Main = new Intent(Login.this, MainActivity.class);
- Main.putExtra("class", "Nanny");
- Main.putExtra("username",Username);
- Main.putExtra("password",Password);
- startActivity(Main);
- }
- public class Authenticate extends AsyncTask<String, Void, String> {
- private Context context;
- public Authenticate(Context context) {
- this.context = context;
- }
- @Override
- protected void onPreExecute() {
- }
- @Override
- protected String doInBackground(String... arg0) {
- String Username = arg0[0];
- String Password = arg0[1];
- String link;
- String data;
- BufferedReader bufferedReader;
- String result;
- try {
- data = "?username=" + URLEncoder.encode(Username, "UTF-8");
- data += "&password=" + URLEncoder.encode(Password, "UTF-8");
- link = "http://juliusgoh.comxa.com/Authenticate.php" + data;
- URL url = new URL(link);
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
- result = bufferedReader.readLine();
- return result;
- } catch (Exception e) {
- return ("Exception: " + e.getMessage());
- }
- }
- @Override
- protected void onPostExecute(String result) {
- if (result != null) {
- try {
- JSONObject jsonObj = new JSONObject(result);
- String query_result = jsonObj.getString("query_result");
- switch (query_result) {
- case "PSUCCESS":
- Toast.makeText(context, "Login Successfully....Parent", Toast.LENGTH_SHORT).show();
- ParentLogin();
- break;
- case "NSUCCESS":
- Toast.makeText(context, "Login Successfully....Nanny", Toast.LENGTH_SHORT).show();
- NannyLogin();
- break;
- case "FAILURE":
- Toast.makeText(context, "Wrong Data. Login failed.", Toast.LENGTH_SHORT).show();
- break;
- default:
- Toast.makeText(context, "Couldn't connect to remote database.", Toast.LENGTH_SHORT).show();
- break;
- }
- } catch (JSONException e) {
- e.printStackTrace();
- Toast.makeText(context, "Error parsing JSON data.", Toast.LENGTH_SHORT).show();
- }
- } else {
- Toast.makeText(context, "Couldn't get any JSON data.", Toast.LENGTH_SHORT).show();
- }
- }
- }
- public String job;
- public String username;
- public String password;
- TextView qwe;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
- }
- });
- qwe = (TextView)findViewById(R.id.asd);
- Intent intent = new Intent();
- String strValue = intent.getStringExtra("class");
- String strValue1 = intent.getStringExtra("username");
- String strValue2 = intent.getStringExtra("password");
- qwe.setText(strValue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement