- login validation added

- register button added (in-progress)
- some string constants modified
This commit is contained in:
Matan Bar Yosef 2016-07-02 16:57:05 +03:00
parent 49785a5608
commit 3629fafd9a
3 changed files with 55 additions and 12 deletions

View file

@ -20,6 +20,7 @@ import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
@ -30,6 +31,8 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
@ -58,24 +61,31 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
private UserLoginTask mAuthTask = null;
// UI references.
private AutoCompleteTextView mUsernameView;
private AutoCompleteTextView mEmailView;
private EditText mPasswordView;
private View mProgressView;
private View mLoginFormView;
private final String baseUrl = "http://thesocialnotework-api.appspot.com/api";
private final String TAG = "Login Activity";
private final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
private final String REG_PATH = "/register";
private final String LOGIN_PATH = "/login";
private boolean loginSuccess = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form.
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
populateAutoComplete();
// mUsernameView = (AutoCompleteTextView) findViewById(R.id.username);
// populateAutoComplete();
// mUsernameView
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
@ -92,9 +102,8 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG, "Login.......");
attemptLogin();
Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class);
startActivity(personalSpaceActivity);
}
});
@ -158,9 +167,12 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
// Reset errors.
mEmailView.setError(null);
// mUsernameView.setError(null);
mPasswordView.setError(null);
// Store values at the time of the login attempt.
// String username = mUsernameView.getText().toString();
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
@ -195,6 +207,20 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
showProgress(true);
mAuthTask = new UserLoginTask(email, password);
mAuthTask.execute((Void) null);
// http request register
JSONObject tempJson = new JSONObject();
try {
tempJson.put("email", email);
tempJson.put("password", password);
} catch (Exception e) {
Log.d(TAG, e.toString());
}
VolleyUtilSingleton.getInstance(LoginActivity.this).newUser(BASE_URL + LOGIN_PATH, tempJson);
Intent personalSpaceActivity = new Intent(LoginActivity.this, PersonalSpaceActivity.class);
startActivity(personalSpaceActivity);
}
}

View file

@ -63,14 +63,30 @@
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button
android:id="@+id/al_login_button"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_login"
android:textStyle="bold" />
<Button
style="?android:textAppearanceSmall"
android:id="@+id/al_register_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_register"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -4,7 +4,8 @@
<!-- Strings related to login -->
<string name="prompt_email">Email</string>
<string name="prompt_password">Password (optional)</string>
<string name="action_sign_in">Sign in or register</string>
<string name="action_login">Login</string>
<string name="action_register">Register</string>
<string name="action_sign_in_short">Sign in</string>
<string name="error_invalid_email">This email address is invalid</string>
<string name="error_invalid_password">This password is too short</string>