Sprawdzanie loginu i hasła w Login Activity

This commit is contained in:
Przemek Grondek 2014-07-14 13:43:54 +02:00
parent a1ae369973
commit 60df46d48c
6 changed files with 71 additions and 16 deletions

View file

@ -3,23 +3,28 @@ package info.nerull7.mysqlbrowser;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import info.nerull7.mysqlbrowser.db.DatabaseConnector;
/**
* Created by nerull7 on 07.07.14.
*/
public class LoginFragment extends Fragment implements View.OnClickListener {
EditText uri;
EditText login;
EditText password; // TODO: Mega super epic security (RSA/AES maybe?)
EditText urlTextbox;
EditText loginTextbox;
EditText passwordTextbox; // TODO: Mega super epic security (RSA/AES maybe?)
public LoginFragment(){
@ -31,24 +36,42 @@ public class LoginFragment extends Fragment implements View.OnClickListener {
View rootView = inflater.inflate(R.layout.fragment_login, container, false);
rootView.findViewById(R.id.buttonLogin).setOnClickListener(this);
this.uri = (EditText) rootView.findViewById(R.id.editURL);
this.login = (EditText) rootView.findViewById(R.id.editLogin);
this.password = (EditText) rootView.findViewById(R.id.editPassowrd);
this.urlTextbox = (EditText) rootView.findViewById(R.id.editURL);
this.loginTextbox = (EditText) rootView.findViewById(R.id.editLogin);
this.passwordTextbox = (EditText) rootView.findViewById(R.id.editPassowrd);
return rootView;
}
@Override
public void onClick(View view) {
// DatabaseFragment databaseFragment = DatabaseFragment.newInstance(login.getText().toString(),
// password.getText().toString(),
// uri.getText().toString());
//
// getFragmentManager().beginTransaction()
// .add(R.id.container, databaseFragment)
// .remove(this)
// .commit();
Intent intent = new Intent(getActivity(), DatabaseActivity.class);
startActivity(intent);
checkLogin();
}
private void checkLogin(){
String login, password, url;
login = loginTextbox.getText().toString();
password = passwordTextbox.getText().toString();
url = urlTextbox.getText().toString();
if(DatabaseConnector.checkLogin(login, password, url)) {
Static.databaseConnector = new DatabaseConnector(login, password, url);
Intent intent = new Intent(getActivity(), DatabaseActivity.class);
startActivity(intent);
}
else {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(DatabaseConnector.errorMsg);
builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Nothing to do here
// Cleaning inputs is stupid
}
});
builder.setTitle(R.string.error);
builder.setIcon(R.drawable.ic_action_warning);
builder.create();
builder.show();
}
}
}

View file

@ -0,0 +1,16 @@
package info.nerull7.mysqlbrowser;
import info.nerull7.mysqlbrowser.db.DatabaseConnector;
/**
* Created by nerull7 on 14.07.14.
*/
public class Static {
public static DatabaseConnector databaseConnector = null;
public static boolean isDatabaseConnectorActive(){
if (databaseConnector==null)
return false;
return true;
}
}

View file

@ -15,12 +15,25 @@ public class DatabaseConnector {
private String database;
private String table;
public static String errorMsg;
public DatabaseConnector(String login, String password, String url){
this.login = login;
this.password = password;
this.url = url;
}
// TODO Real checking
public static boolean checkLogin(String login, String password, String url){
if (login.compareTo("nerull7")==0)
return true;
if(password==null)
errorMsg = "No Password";
else
errorMsg = "I don't know";
return false;
}
public void setDatabaseInUse(String database){
this.database = database;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

View file

@ -10,5 +10,8 @@
<string name="title_activity_main">MainActivity</string>
<string name="title_activity_database">DatabaseActivity</string>
<string name="hello_world">Hello world!</string>
<string name="login_error">Wrong login/password</string>
<string name="ok">OK</string>
<string name="error">Error</string>
</resources>