Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration Page #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions Registration Page
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Login extends ActionBarActivity {

public static android.content.SharedPreferences SharedPreferences = null;

private static final String PREFER_NAME = null;

Button buttonLogin;

EditText txtUsername, txtPassword;

// User Session Manager Class
UserSession session;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);

Button switchButton = (Button)findViewById(R.id.buttonReg);
switchButton.setOnClickListener (new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent=new Intent(Login.this, Reg.class);
startActivity(intent);

}
});


// User Session Manager
session = new UserSession(getApplicationContext());

// get Email, Password input text
txtUsername = (EditText) findViewById(R.id.txtUsername);
txtPassword = (EditText) findViewById(R.id.txtPassword);

Toast.makeText(getApplicationContext(),
"User Login Status: " + session.isUserLoggedIn(),
Toast.LENGTH_LONG).show();


// User Login button
buttonLogin = (Button) findViewById(R.id.buttonLogin);

SharedPreferences = getSharedPreferences(PREFER_NAME, Context.MODE_PRIVATE);


// Login button click event
buttonLogin.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {

// Get username, password from EditText
String username = txtUsername.getText().toString();
String password = txtPassword.getText().toString();

// Validate if username, password is filled
if(username.trim().length() > 0 && password.trim().length() > 0){

if (SharedPreferences.contains("name"))
{
String uName = (SharedPreferences).getString("name", "");

}

if (SharedPreferences.contains("email"))
{
String uEmail = (SharedPreferences).getString("email", "");

}

Object uName = null;
Object uEmail = null;
if(username.equals(uName) && password.equals(uEmail)){

session.createUserLoginSession(uName,
uEmail);

// Starting MainActivity
Intent i = new Intent(getApplicationContext(),MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

finish();

}else{

// username / password doesn't match&
Toast.makeText(getApplicationContext(),
"Username/Password is incorrect",
Toast.LENGTH_LONG).show();

}
}else{

// user didn't entered username or password
Toast.makeText(getApplicationContext(),
"Please enter username and password",
Toast.LENGTH_LONG).show();

}

}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = new MenuInflater(this);
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.MENU_1:
Intent intent1 = new Intent(this, Login.class);
this.startActivity(intent1);
break;
case R.id.MENU_2:
Intent intent2 = new Intent(this, MainActivity.class);
this.startActivity(intent2);
break;
default:
return super.onOptionsItemSelected(item);
}

return true;
}