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 Bitmap bitmap;
|
||||
private static final String TAG="RegisterLocal";
|
||||
SharedPreferences shared;
|
||||
|
||||
@Inject
|
||||
VLPreferences preferences;
|
||||
@ -46,17 +47,13 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
||||
this.listener = listener;
|
||||
this.photoProcessor = photoProcessor;
|
||||
this.bitmap = bitmap;
|
||||
shared = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPerson() {
|
||||
Log.i("Route", "registerPerson registerapiimplocal");
|
||||
// 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);
|
||||
|
||||
@ -78,12 +75,10 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
||||
.setContentText("OK").show();
|
||||
}
|
||||
else{
|
||||
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
SharedPreferences.Editor editor = shared.edit();
|
||||
editor.putBoolean("registerFirstTime",true);
|
||||
|
||||
editor.commit();
|
||||
|
||||
// photoProcessor.calcFaceDescriptorFromBestFrame();
|
||||
byte[] bestFrameDescriptorByteArray = photoProcessor.getFaceDescriptorByteArray();
|
||||
|
||||
@ -108,11 +103,6 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
||||
onSuccess(descriptorEncrypted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void onFail(Throwable throwable) {
|
||||
@ -123,13 +113,12 @@ public class RegisterApiImplLocal implements RegisterApiInterface {
|
||||
Log.i("Route", "onSuccess");
|
||||
Log.i(TAG,"Desctiptor has been saved : descr = "+descriptor);
|
||||
// System.out.println("Value of login after registration " + registrationModel.login);
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("login","demouser1");
|
||||
SharedPreferences.Editor editor = shared.edit();
|
||||
String registerUserName = shared.getString("RegisterUser", "");
|
||||
editor.putString("login",registerUserName);
|
||||
editor.putString("Descriptor",descriptor);
|
||||
editor.commit();
|
||||
Storage.getInstance().addToStorageLunaLocal("demouser1", descriptor);
|
||||
|
||||
Storage.getInstance().addToStorageLunaLocal(registerUserName, descriptor);
|
||||
listener.onRegistrationSuccess();
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import com.android.volley.toolbox.Volley;
|
||||
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -41,6 +42,9 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import cn.pedant.SweetAlert.SweetAlertDialog;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
@ -57,11 +61,15 @@ import ru.visionlab.femdemo.models.RegistrationNew;
|
||||
import ru.visionlab.femdemo.models.Users;
|
||||
import ru.visionlab.femdemo.register.RegisterActivity;
|
||||
import ru.visionlab.femdemo.register.RegisterActivityNew;
|
||||
import ru.visionlab.femdemo.settings.VLPreferences;
|
||||
|
||||
public class LoginActivityNew extends AppCompatActivity {
|
||||
|
||||
public static final String MyPREFERENCES = "MyPrefs" ;
|
||||
public static final String ID = "id";
|
||||
@Inject
|
||||
VLPreferences preferences;
|
||||
SharedPreferences shared;
|
||||
|
||||
Button btnSignin;
|
||||
|
||||
@ -89,6 +97,8 @@ public class LoginActivityNew extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login_new);
|
||||
|
||||
shared = getApplication().getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||
|
||||
edt_empId = findViewById(R.id.edt_empId);
|
||||
edt_pass = findViewById(R.id.edt_pass);
|
||||
|
||||
@ -97,6 +107,7 @@ public class LoginActivityNew extends AppCompatActivity {
|
||||
SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE);
|
||||
String login = shared.getString("login", "");
|
||||
String Descriptor = shared.getString("Descriptor", "");
|
||||
String Employeeid = shared.getString("Employeeid", "");
|
||||
|
||||
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);
|
||||
|
||||
btnSignin = findViewById(R.id.btnSignin);
|
||||
|
||||
if(!login.equals("")){
|
||||
btnSignin.setOnClickListener(new View.OnClickListener() {
|
||||
btnSignin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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();
|
||||
if(isAllFieldsChecked) {
|
||||
// login();
|
||||
System.out.println("After login activity new ");
|
||||
/*Intent intent = new Intent(LoginActivityNew.this, RegisterActivity.class);
|
||||
intent.putExtra("FromLoginPage",true);
|
||||
startActivity(intent);*/
|
||||
//login();
|
||||
//loginVolley();
|
||||
loginVolleyNil();
|
||||
//loginRetro();
|
||||
|
||||
isAllFieldsChecked = CheckAllFields();
|
||||
if(isAllFieldsChecked) {
|
||||
// login();
|
||||
loginUserWithCredential(edt_empId.getText().toString(), edt_pass.getText().toString());
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
Toast.makeText(LoginActivityNew.this,"Please register before logging in ",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
faceImage = findViewById(R.id.faceImage);
|
||||
|
||||
if(!login.equals("")){
|
||||
faceImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
faceImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(!Employeeid.equals("")){
|
||||
Intent intent = new Intent(LoginActivityNew.this, RegisterActivity.class);
|
||||
intent.putExtra("FromLoginPage",true);
|
||||
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.setOnClickListener(new View.OnClickListener() {
|
||||
@ -176,11 +184,7 @@ public class LoginActivityNew extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void createRetrofit(){
|
||||
} public void createRetrofit(){
|
||||
Retrofit retrofit=new Retrofit.Builder()
|
||||
.baseUrl(Url.Base_url)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
@ -531,4 +535,73 @@ public class LoginActivityNew extends AppCompatActivity {
|
||||
};
|
||||
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.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.Editable;
|
||||
@ -79,6 +80,7 @@ public class RegisterFragment extends BaseFragment {
|
||||
EditText pass;
|
||||
|
||||
String password="";
|
||||
SharedPreferences shared;
|
||||
|
||||
public RegisterFragment() {
|
||||
}
|
||||
@ -116,6 +118,7 @@ public class RegisterFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
shared = getContext().getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
|
||||
getActivity().setTitle(R.string.registration_title);
|
||||
scrollView.setOnTouchListener((scrollViewView, motionEvent) -> {
|
||||
Utils.hideKeyboard(getContext(), getActivity().getCurrentFocus());
|
||||
@ -123,7 +126,6 @@ public class RegisterFragment extends BaseFragment {
|
||||
}
|
||||
);
|
||||
login.requestFocus();
|
||||
|
||||
if (BuildConfig.IS_OFFLINE_VERSION) {
|
||||
phoneWrapper.setVisibility(View.GONE);
|
||||
emailWrapper.setVisibility(View.GONE);
|
||||
@ -179,32 +181,24 @@ public class RegisterFragment extends BaseFragment {
|
||||
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(getContext(), statuscode, Toast.LENGTH_SHORT).show();
|
||||
|
||||
if(statuscode.equals("200"))
|
||||
{
|
||||
|
||||
preferences.setUsername(username);
|
||||
if (listener != null && validateFields(true, true)) {
|
||||
RegistrationModel registrationModel = new RegistrationModel();
|
||||
// registrationModel.email = email.getText().toString().trim();
|
||||
registrationModel.login = username;
|
||||
//registrationModel.password = password.getText().toString().trim();
|
||||
// registrationModel.phone = phone.getText().toString().trim();
|
||||
listener.onSignUpClick(registrationModel);
|
||||
SharedPreferences.Editor editor = shared.edit();
|
||||
editor.putString("RegisterUser",username);
|
||||
editor.putBoolean("registerFirstTime",false);
|
||||
editor.putString("Employeeid",_employeeid);
|
||||
editor.commit();
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user