login api implemented
This commit is contained in:
parent
f27734409c
commit
9e9b1cf324
@ -7,10 +7,13 @@ import android.graphics.Bitmap;
|
|||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import cn.pedant.SweetAlert.SweetAlertDialog;
|
import cn.pedant.SweetAlert.SweetAlertDialog;
|
||||||
import ru.visionlab.femdemo.Core.PhotoProcessor;
|
import ru.visionlab.femdemo.Core.PhotoProcessor;
|
||||||
import ru.visionlab.femdemo.Storage;
|
import ru.visionlab.femdemo.Storage;
|
||||||
import ru.visionlab.femdemo.register.RegistrationModel;
|
import ru.visionlab.femdemo.register.RegistrationModel;
|
||||||
|
import ru.visionlab.femdemo.settings.VLPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by luckydotaplay on 20.01.2017.
|
* Created by luckydotaplay on 20.01.2017.
|
||||||
@ -26,6 +29,9 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
private Bitmap bitmap;
|
private Bitmap bitmap;
|
||||||
private static final String TAG="RegisterLocal";
|
private static final String TAG="RegisterLocal";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
VLPreferences preferences;
|
||||||
|
|
||||||
public static class DescriptorNotExtractedException extends RuntimeException {
|
public static class DescriptorNotExtractedException extends RuntimeException {
|
||||||
|
|
||||||
public DescriptorNotExtractedException(String detailMessage) {
|
public DescriptorNotExtractedException(String detailMessage) {
|
||||||
@ -46,7 +52,17 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
public void registerPerson() {
|
public void registerPerson() {
|
||||||
Log.i("Route", "registerPerson registerapiimplocal");
|
Log.i("Route", "registerPerson registerapiimplocal");
|
||||||
// Log.i(TAG,"Login is"+registrationModel.login);
|
// Log.i(TAG,"Login is"+registrationModel.login);
|
||||||
|
/*SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.getBoolean("registerFirstTime",true);
|
||||||
|
|
||||||
|
editor.commit();*/
|
||||||
|
|
||||||
|
SharedPreferences shared = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
|
boolean isUserRegistered = shared.getBoolean("isUserRegistered", false);
|
||||||
|
|
||||||
|
if (isUserRegistered) {
|
||||||
if(registrationModel == null){
|
if(registrationModel == null){
|
||||||
new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE)
|
new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE)
|
||||||
.setTitleText("Face not recognised")
|
.setTitleText("Face not recognised")
|
||||||
@ -62,6 +78,12 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
.setContentText("OK").show();
|
.setContentText("OK").show();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
|
SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
|
editor.putBoolean("registerFirstTime",true);
|
||||||
|
|
||||||
|
editor.commit();
|
||||||
// photoProcessor.calcFaceDescriptorFromBestFrame();
|
// photoProcessor.calcFaceDescriptorFromBestFrame();
|
||||||
byte[] bestFrameDescriptorByteArray = photoProcessor.getFaceDescriptorByteArray();
|
byte[] bestFrameDescriptorByteArray = photoProcessor.getFaceDescriptorByteArray();
|
||||||
|
|
||||||
@ -74,6 +96,23 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
byte[] bestFrameDescriptorByteArray = photoProcessor.getFaceDescriptorByteArray();
|
||||||
|
|
||||||
|
if (bestFrameDescriptorByteArray == null || bestFrameDescriptorByteArray.length == 0) {
|
||||||
|
onFail(new DescriptorNotExtractedException("FAILED to register: could not extract descriptor "));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
String descriptorEncrypted = Base64.encodeToString(bestFrameDescriptorByteArray, Base64.DEFAULT);
|
||||||
|
onSuccess(descriptorEncrypted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onFail(Throwable throwable) {
|
private void onFail(Throwable throwable) {
|
||||||
@ -83,13 +122,13 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
private void onSuccess(String descriptor) {
|
private void onSuccess(String descriptor) {
|
||||||
Log.i("Route", "onSuccess");
|
Log.i("Route", "onSuccess");
|
||||||
Log.i(TAG,"Desctiptor has been saved : descr = "+descriptor);
|
Log.i(TAG,"Desctiptor has been saved : descr = "+descriptor);
|
||||||
System.out.println("Value of login after registration " + registrationModel.login);
|
// System.out.println("Value of login after registration " + registrationModel.login);
|
||||||
SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||||
editor.putString("login",registrationModel.login);
|
editor.putString("login","demouser1");
|
||||||
editor.putString("Descriptor",descriptor);
|
editor.putString("Descriptor",descriptor);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
Storage.getInstance().addToStorageLunaLocal(registrationModel.login, descriptor);
|
Storage.getInstance().addToStorageLunaLocal("demouser1", descriptor);
|
||||||
|
|
||||||
listener.onRegistrationSuccess();
|
listener.onRegistrationSuccess();
|
||||||
}
|
}
|
||||||
|
@ -421,6 +421,7 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen
|
|||||||
@Override
|
@Override
|
||||||
public void onSaveClick() {
|
public void onSaveClick() {
|
||||||
registerPerson();
|
registerPerson();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPerson() {
|
private void registerPerson() {
|
||||||
@ -543,7 +544,7 @@ public class RegisterActivity extends ToolbarActivity implements RegisterFragmen
|
|||||||
|
|
||||||
private void finishRegistration()
|
private void finishRegistration()
|
||||||
{
|
{
|
||||||
preferences.setUsername(registrationModel.login);
|
//preferences.setUsername(registrationModel.login);
|
||||||
|
|
||||||
// preferences.setPin(registrationModel.password);
|
// preferences.setPin(registrationModel.password);
|
||||||
Intent intent = new Intent(RegisterActivity.this, LoginActivityNew.class);
|
Intent intent = new Intent(RegisterActivity.this, LoginActivityNew.class);
|
||||||
|
@ -103,6 +103,8 @@ public class RegisterActivityNew extends AppCompatActivity {
|
|||||||
intent.putExtra("FromLoginPage",false);
|
intent.putExtra("FromLoginPage",false);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
||||||
|
System.out.println("Niladri");
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package ru.visionlab.femdemo.register;
|
package ru.visionlab.femdemo.register;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -15,9 +17,23 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
import com.android.volley.AuthFailureError;
|
||||||
|
import com.android.volley.Request;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
|
import com.android.volley.toolbox.StringRequest;
|
||||||
|
import com.android.volley.toolbox.Volley;
|
||||||
import com.google.android.material.textfield.TextInputLayout;
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -33,6 +49,7 @@ import ru.visionlab.femdemo.R;
|
|||||||
import ru.visionlab.femdemo.Storage;
|
import ru.visionlab.femdemo.Storage;
|
||||||
import ru.visionlab.femdemo.Utils;
|
import ru.visionlab.femdemo.Utils;
|
||||||
import ru.visionlab.femdemo.base.BaseFragment;
|
import ru.visionlab.femdemo.base.BaseFragment;
|
||||||
|
import ru.visionlab.femdemo.login.LoginActivityNew;
|
||||||
import ru.visionlab.femdemo.settings.VLPreferences;
|
import ru.visionlab.femdemo.settings.VLPreferences;
|
||||||
|
|
||||||
|
|
||||||
@ -130,15 +147,101 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
|
|
||||||
|
|
||||||
Utils.hideKeyboardRoutine(getContext(), getView());
|
Utils.hideKeyboardRoutine(getContext(), getView());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(login.getText().toString().isEmpty())
|
||||||
|
{
|
||||||
|
Toast.makeText(getContext(), "Please enter user name", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else if(pass.getText().toString().isEmpty())
|
||||||
|
{
|
||||||
|
Toast.makeText(getContext(), "Please enter password", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getRegistration(login.getText().toString(),pass.getText().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getRegistration(String username, String password) {
|
||||||
|
|
||||||
|
String url= "http://43.242.212.92:7001/api/lgt/Login";
|
||||||
|
StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray=new JSONArray(response);
|
||||||
|
Log.d("response",response);
|
||||||
|
JSONObject jb1=jsonArray.getJSONObject(0);
|
||||||
|
JSONObject jb2=jb1.getJSONObject("statusModel");
|
||||||
|
String statuscode=jb2.getString("_statusCode");
|
||||||
|
Log.d("status",statuscode);
|
||||||
|
Toast.makeText(getContext(), statuscode, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
if(statuscode.equals("200"))
|
||||||
|
{
|
||||||
|
|
||||||
|
preferences.setUsername(username);
|
||||||
if (listener != null && validateFields(true, true)) {
|
if (listener != null && validateFields(true, true)) {
|
||||||
RegistrationModel registrationModel = new RegistrationModel();
|
RegistrationModel registrationModel = new RegistrationModel();
|
||||||
registrationModel.email = email.getText().toString().trim();
|
// registrationModel.email = email.getText().toString().trim();
|
||||||
registrationModel.login = login.getText().toString().trim();
|
registrationModel.login = username;
|
||||||
//registrationModel.password = password.getText().toString().trim();
|
//registrationModel.password = password.getText().toString().trim();
|
||||||
registrationModel.phone = phone.getText().toString().trim();
|
// registrationModel.phone = phone.getText().toString().trim();
|
||||||
listener.onSignUpClick(registrationModel);
|
listener.onSignUpClick(registrationModel);
|
||||||
|
|
||||||
|
|
||||||
|
Log.d("HH", String.valueOf(registrationModel));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Toast.makeText(getContext(), "Success Registration", Toast.LENGTH_SHORT).show();
|
||||||
|
Intent intent=new Intent(getContext(),RegisterActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we have to show alert
|
||||||
|
Toast.makeText(getContext(), "Username/password is not matching!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}, new com.android.volley.Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
Log.d("error-=>",error.getMessage());
|
||||||
|
|
||||||
|
Toast.makeText(getContext(), "Faied", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> getParams() throws AuthFailureError {
|
||||||
|
HashMap<String,String> map=new HashMap<>();
|
||||||
|
map.put("username",username);
|
||||||
|
map.put("password",password);
|
||||||
|
map.put("imei","");
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Volley.newRequestQueue(getContext()).add(stringRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean validateFields(boolean changeFocus, boolean showError) {
|
private boolean validateFields(boolean changeFocus, boolean showError) {
|
||||||
boolean result;
|
boolean result;
|
||||||
@ -183,10 +286,10 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
loginWrapper.setError(getString(R.string.register_username_short, Config.MIN_LOGIN_LENGTH));
|
loginWrapper.setError(getString(R.string.register_username_short, Config.MIN_LOGIN_LENGTH));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Storage.getInstance().isLoginAlreadyExists(currentLogin) || Storage.getInstance().isLoginAlreadyExistsLocal(currentLogin)){
|
// if(Storage.getInstance().isLoginAlreadyExists(currentLogin) || Storage.getInstance().isLoginAlreadyExistsLocal(currentLogin)){
|
||||||
result = false;
|
// result = false;
|
||||||
loginWrapper.setError(getString(R.string.register_username_exist,currentLogin));
|
//// loginWrapper.setError(getString(R.string.register_username_exist,currentLogin));
|
||||||
}
|
// }
|
||||||
else {
|
else {
|
||||||
loginWrapper.setError(null);
|
loginWrapper.setError(null);
|
||||||
loginWrapper.setErrorEnabled(false);
|
loginWrapper.setErrorEnabled(false);
|
||||||
@ -228,5 +331,6 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
void onSignUpClick(RegistrationModel registrationModel);
|
void onSignUpClick(RegistrationModel registrationModel);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@
|
|||||||
android:layout_marginBottom="@dimen/button_margin_bottom"
|
android:layout_marginBottom="@dimen/button_margin_bottom"
|
||||||
android:layout_marginTop="35dp"
|
android:layout_marginTop="35dp"
|
||||||
android:background="@drawable/selector_button"
|
android:background="@drawable/selector_button"
|
||||||
android:enabled="false"
|
android:enabled="true"
|
||||||
android:text="NEXT"
|
android:text="NEXT"
|
||||||
android:textColor="@android:color/white"
|
android:textColor="@android:color/white"
|
||||||
android:textSize="14sp"/>
|
android:textSize="14sp"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user