Login Api implement and handled first time if user not register in the app
This commit is contained in:
parent
9e9b1cf324
commit
bf299f8dfc
@ -28,6 +28,7 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
private PhotoProcessor photoProcessor;
|
private PhotoProcessor photoProcessor;
|
||||||
private Bitmap bitmap;
|
private Bitmap bitmap;
|
||||||
private static final String TAG="RegisterLocal";
|
private static final String TAG="RegisterLocal";
|
||||||
|
SharedPreferences shared;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VLPreferences preferences;
|
VLPreferences preferences;
|
||||||
@ -46,17 +47,13 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.photoProcessor = photoProcessor;
|
this.photoProcessor = photoProcessor;
|
||||||
this.bitmap = bitmap;
|
this.bitmap = bitmap;
|
||||||
|
shared = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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);
|
SharedPreferences shared = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
@ -78,12 +75,10 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
.setContentText("OK").show();
|
.setContentText("OK").show();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
SharedPreferences.Editor editor = shared.edit();
|
||||||
SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
|
||||||
editor.putBoolean("registerFirstTime",true);
|
editor.putBoolean("registerFirstTime",true);
|
||||||
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
|
||||||
// photoProcessor.calcFaceDescriptorFromBestFrame();
|
// photoProcessor.calcFaceDescriptorFromBestFrame();
|
||||||
byte[] bestFrameDescriptorByteArray = photoProcessor.getFaceDescriptorByteArray();
|
byte[] bestFrameDescriptorByteArray = photoProcessor.getFaceDescriptorByteArray();
|
||||||
|
|
||||||
@ -108,11 +103,6 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
onSuccess(descriptorEncrypted);
|
onSuccess(descriptorEncrypted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onFail(Throwable throwable) {
|
private void onFail(Throwable throwable) {
|
||||||
@ -123,13 +113,12 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
|||||||
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.Editor editor = shared.edit();
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
String registerUserName = shared.getString("RegisterUser", "");
|
||||||
editor.putString("login","demouser1");
|
editor.putString("login",registerUserName);
|
||||||
editor.putString("Descriptor",descriptor);
|
editor.putString("Descriptor",descriptor);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
Storage.getInstance().addToStorageLunaLocal("demouser1", descriptor);
|
Storage.getInstance().addToStorageLunaLocal(registerUserName, descriptor);
|
||||||
|
|
||||||
listener.onRegistrationSuccess();
|
listener.onRegistrationSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import com.android.volley.toolbox.Volley;
|
|||||||
import com.google.android.gms.location.FusedLocationProviderClient;
|
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||||
import com.google.android.gms.tasks.OnSuccessListener;
|
import com.google.android.gms.tasks.OnSuccessListener;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -41,6 +42,9 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import cn.pedant.SweetAlert.SweetAlertDialog;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -57,11 +61,15 @@ import ru.visionlab.femdemo.models.RegistrationNew;
|
|||||||
import ru.visionlab.femdemo.models.Users;
|
import ru.visionlab.femdemo.models.Users;
|
||||||
import ru.visionlab.femdemo.register.RegisterActivity;
|
import ru.visionlab.femdemo.register.RegisterActivity;
|
||||||
import ru.visionlab.femdemo.register.RegisterActivityNew;
|
import ru.visionlab.femdemo.register.RegisterActivityNew;
|
||||||
|
import ru.visionlab.femdemo.settings.VLPreferences;
|
||||||
|
|
||||||
public class LoginActivityNew extends AppCompatActivity {
|
public class LoginActivityNew extends AppCompatActivity {
|
||||||
|
|
||||||
public static final String MyPREFERENCES = "MyPrefs" ;
|
public static final String MyPREFERENCES = "MyPrefs" ;
|
||||||
public static final String ID = "id";
|
public static final String ID = "id";
|
||||||
|
@Inject
|
||||||
|
VLPreferences preferences;
|
||||||
|
SharedPreferences shared;
|
||||||
|
|
||||||
Button btnSignin;
|
Button btnSignin;
|
||||||
|
|
||||||
@ -89,6 +97,8 @@ public class LoginActivityNew extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_login_new);
|
setContentView(R.layout.activity_login_new);
|
||||||
|
|
||||||
|
shared = getApplication().getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
|
|
||||||
edt_empId = findViewById(R.id.edt_empId);
|
edt_empId = findViewById(R.id.edt_empId);
|
||||||
edt_pass = findViewById(R.id.edt_pass);
|
edt_pass = findViewById(R.id.edt_pass);
|
||||||
|
|
||||||
@ -97,6 +107,7 @@ public class LoginActivityNew extends AppCompatActivity {
|
|||||||
SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE);
|
SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE);
|
||||||
String login = shared.getString("login", "");
|
String login = shared.getString("login", "");
|
||||||
String Descriptor = shared.getString("Descriptor", "");
|
String Descriptor = shared.getString("Descriptor", "");
|
||||||
|
String Employeeid = shared.getString("Employeeid", "");
|
||||||
|
|
||||||
System.out.println("value of login and Descriptor in login new " + login + " " + Descriptor);
|
System.out.println("value of login and Descriptor in login new " + login + " " + Descriptor);
|
||||||
|
|
||||||
@ -116,57 +127,54 @@ public class LoginActivityNew extends AppCompatActivity {
|
|||||||
System.out.println("value of emp and pass " + empId + " " + pass);
|
System.out.println("value of emp and pass " + empId + " " + pass);
|
||||||
|
|
||||||
btnSignin = findViewById(R.id.btnSignin);
|
btnSignin = findViewById(R.id.btnSignin);
|
||||||
|
|
||||||
if(!login.equals("")){
|
|
||||||
btnSignin.setOnClickListener(new View.OnClickListener() {
|
btnSignin.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
if(!Employeeid.equals("")){
|
||||||
/*if (ContextCompat.checkSelfPermission(LoginActivityNew.this, android.Manifest.permission.ACCESS_FINE_LOCATION)
|
|
||||||
== PackageManager.PERMISSION_GRANTED) {
|
|
||||||
// Permission granted, so request location updates
|
|
||||||
requestLocationUpdates();
|
|
||||||
} else {
|
|
||||||
// Permission not granted, request it
|
|
||||||
ActivityCompat.requestPermissions(LoginActivityNew.this,
|
|
||||||
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
|
|
||||||
LOCATION_PERMISSION_REQUEST_CODE);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
isAllFieldsChecked = CheckAllFields();
|
isAllFieldsChecked = CheckAllFields();
|
||||||
if(isAllFieldsChecked) {
|
if(isAllFieldsChecked) {
|
||||||
// login();
|
// login();
|
||||||
System.out.println("After login activity new ");
|
loginUserWithCredential(edt_empId.getText().toString(), edt_pass.getText().toString());
|
||||||
/*Intent intent = new Intent(LoginActivityNew.this, RegisterActivity.class);
|
}
|
||||||
intent.putExtra("FromLoginPage",true);
|
}
|
||||||
startActivity(intent);*/
|
else {
|
||||||
//login();
|
new SweetAlertDialog(LoginActivityNew.this, SweetAlertDialog.WARNING_TYPE)
|
||||||
//loginVolley();
|
.setTitleText("Face not register")
|
||||||
loginVolleyNil();
|
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
|
||||||
//loginRetro();
|
@Override
|
||||||
|
public void onClick(SweetAlertDialog sDialog) {
|
||||||
|
sDialog.dismissWithAnimation();
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else{
|
|
||||||
Toast.makeText(LoginActivityNew.this,"Please register before logging in ",Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
faceImage = findViewById(R.id.faceImage);
|
faceImage = findViewById(R.id.faceImage);
|
||||||
|
|
||||||
if(!login.equals("")){
|
|
||||||
faceImage.setOnClickListener(new View.OnClickListener() {
|
faceImage.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
if(!Employeeid.equals("")){
|
||||||
Intent intent = new Intent(LoginActivityNew.this, RegisterActivity.class);
|
Intent intent = new Intent(LoginActivityNew.this, RegisterActivity.class);
|
||||||
intent.putExtra("FromLoginPage",true);
|
intent.putExtra("FromLoginPage",true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new SweetAlertDialog(LoginActivityNew.this, SweetAlertDialog.WARNING_TYPE)
|
||||||
|
.setTitleText("Face not register")
|
||||||
|
.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(SweetAlertDialog sDialog) {
|
||||||
|
sDialog.dismissWithAnimation();
|
||||||
|
}
|
||||||
|
}).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
back = findViewById(R.id.back);
|
back = findViewById(R.id.back);
|
||||||
back.setOnClickListener(new View.OnClickListener() {
|
back.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -176,11 +184,7 @@ public class LoginActivityNew extends AppCompatActivity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} public void createRetrofit(){
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createRetrofit(){
|
|
||||||
Retrofit retrofit=new Retrofit.Builder()
|
Retrofit retrofit=new Retrofit.Builder()
|
||||||
.baseUrl(Url.Base_url)
|
.baseUrl(Url.Base_url)
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
@ -531,4 +535,73 @@ public class LoginActivityNew extends AppCompatActivity {
|
|||||||
};
|
};
|
||||||
Volley.newRequestQueue(LoginActivityNew.this).add(stringRequest);
|
Volley.newRequestQueue(LoginActivityNew.this).add(stringRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loginUserWithCredential(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 _employeeid = jb1.getString("_employeeid");
|
||||||
|
String statuscode=jb2.getString("_statusCode");
|
||||||
|
System.out.println("_employeeid :" + _employeeid);
|
||||||
|
Log.d("status",statuscode);
|
||||||
|
Toast.makeText(LoginActivityNew.this, statuscode, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
if(statuscode.equals("200"))
|
||||||
|
{
|
||||||
|
// preferences.setUsername(username);
|
||||||
|
SharedPreferences.Editor editor = shared.edit();
|
||||||
|
editor.putString("RegisterUser",username);
|
||||||
|
editor.putString("Employeeid",_employeeid);
|
||||||
|
editor.commit();
|
||||||
|
|
||||||
|
Toast.makeText(LoginActivityNew.this, "Success Registration", Toast.LENGTH_SHORT).show();
|
||||||
|
Intent intent=new Intent(LoginActivityNew.this,RegisterActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we have to show alert
|
||||||
|
Toast.makeText(LoginActivityNew.this, "Username/password is not matching!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Toast.makeText(LoginActivityNew.this, 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(LoginActivityNew.this, "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(LoginActivityNew.this).add(stringRequest);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ package ru.visionlab.femdemo.register;
|
|||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -79,6 +80,7 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
EditText pass;
|
EditText pass;
|
||||||
|
|
||||||
String password="";
|
String password="";
|
||||||
|
SharedPreferences shared;
|
||||||
|
|
||||||
public RegisterFragment() {
|
public RegisterFragment() {
|
||||||
}
|
}
|
||||||
@ -116,6 +118,7 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
shared = getContext().getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||||
getActivity().setTitle(R.string.registration_title);
|
getActivity().setTitle(R.string.registration_title);
|
||||||
scrollView.setOnTouchListener((scrollViewView, motionEvent) -> {
|
scrollView.setOnTouchListener((scrollViewView, motionEvent) -> {
|
||||||
Utils.hideKeyboard(getContext(), getActivity().getCurrentFocus());
|
Utils.hideKeyboard(getContext(), getActivity().getCurrentFocus());
|
||||||
@ -123,7 +126,6 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
login.requestFocus();
|
login.requestFocus();
|
||||||
|
|
||||||
if (BuildConfig.IS_OFFLINE_VERSION) {
|
if (BuildConfig.IS_OFFLINE_VERSION) {
|
||||||
phoneWrapper.setVisibility(View.GONE);
|
phoneWrapper.setVisibility(View.GONE);
|
||||||
emailWrapper.setVisibility(View.GONE);
|
emailWrapper.setVisibility(View.GONE);
|
||||||
@ -179,32 +181,24 @@ public class RegisterFragment extends BaseFragment {
|
|||||||
Log.d("response",response);
|
Log.d("response",response);
|
||||||
JSONObject jb1=jsonArray.getJSONObject(0);
|
JSONObject jb1=jsonArray.getJSONObject(0);
|
||||||
JSONObject jb2=jb1.getJSONObject("statusModel");
|
JSONObject jb2=jb1.getJSONObject("statusModel");
|
||||||
|
String _employeeid = jb1.getString("_employeeid");
|
||||||
String statuscode=jb2.getString("_statusCode");
|
String statuscode=jb2.getString("_statusCode");
|
||||||
|
System.out.println("_employeeid :" + _employeeid);
|
||||||
Log.d("status",statuscode);
|
Log.d("status",statuscode);
|
||||||
Toast.makeText(getContext(), statuscode, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), statuscode, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
if(statuscode.equals("200"))
|
if(statuscode.equals("200"))
|
||||||
{
|
{
|
||||||
|
|
||||||
preferences.setUsername(username);
|
preferences.setUsername(username);
|
||||||
if (listener != null && validateFields(true, true)) {
|
SharedPreferences.Editor editor = shared.edit();
|
||||||
RegistrationModel registrationModel = new RegistrationModel();
|
editor.putString("RegisterUser",username);
|
||||||
// registrationModel.email = email.getText().toString().trim();
|
editor.putBoolean("registerFirstTime",false);
|
||||||
registrationModel.login = username;
|
editor.putString("Employeeid",_employeeid);
|
||||||
//registrationModel.password = password.getText().toString().trim();
|
editor.commit();
|
||||||
// registrationModel.phone = phone.getText().toString().trim();
|
|
||||||
listener.onSignUpClick(registrationModel);
|
|
||||||
|
|
||||||
|
|
||||||
Log.d("HH", String.valueOf(registrationModel));
|
|
||||||
|
|
||||||
}
|
|
||||||
Toast.makeText(getContext(), "Success Registration", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), "Success Registration", Toast.LENGTH_SHORT).show();
|
||||||
Intent intent=new Intent(getContext(),RegisterActivity.class);
|
Intent intent=new Intent(getContext(),RegisterActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user