Browse Source

[공통][Bug] 핀 정보는 로컬에 저장

hyodong.min 7 years ago
parent
commit
caba209435

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/model/LifeplusPreferences.java

@@ -101,7 +101,7 @@ public class LifeplusPreferences {
     preferences.put(ENCRYPTED_PIN, pin);
   }
 
-  public String getEncryptionPin() {
+  public String getEncryptedPin() {
     return preferences.get(ENCRYPTED_PIN, "");
   }
 

+ 17 - 11
app/src/main/java/kr/co/zumo/app/lifeplus/model/PinModel.java

@@ -3,9 +3,9 @@
  */
 package kr.co.zumo.app.lifeplus.model;
 
-import io.reactivex.Single;
-import kr.co.zumo.app.lifeplus.bean.LifeplusAuthBean;
-import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIService;
+import java.security.NoSuchAlgorithmException;
+
+import kr.co.zumo.app.lifeplus.util.StringUtil;
 
 /**
  * PinModel
@@ -50,16 +50,22 @@ public class PinModel extends Model {
   }
 
   /**
-   * 핀 검증
+   * 입력한 핀과 저장된 핀이 같은지 확인
    *
-   * @param uuid uuid
-   * @param pin  pin
-   * @return single with LifeplusAuthBean
+   * @param pin "0000"
+   * @return boolean
    */
-  public Single<LifeplusAuthBean> verifyPin(String uuid, String pin) {
-    // todo pin 암호화 처리 필요
-    String encryptedPin = pin;
-    return LifeplusAPIService.verifyPin(uuid, encryptedPin);
+  public boolean verifyPin(String pin) {
+    String encryptedPin;
+    try {
+      encryptedPin = StringUtil.convertToSHA256(StringUtil.convertToMD5(pin));
+    } catch (NoSuchAlgorithmException e) {
+      e.printStackTrace();
+      encryptedPin = "";
+    }
+    String savedPin = SuperModel.getInstance().getPreferences().getEncryptedPin();
+
+    return StringUtil.isFull(encryptedPin) && StringUtil.isFull(savedPin) && savedPin.equals(encryptedPin);
   }
 
   @Override

+ 45 - 41
app/src/main/java/kr/co/zumo/app/lifeplus/view/presenter/PinPresenter.java

@@ -5,16 +5,9 @@ package kr.co.zumo.app.lifeplus.view.presenter;
 
 import android.util.Log;
 
-import java.io.EOFException;
-import java.net.SocketTimeoutException;
-
-import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.disposables.Disposable;
 import kr.co.zumo.app.lifeplus.model.PinModel;
-import kr.co.zumo.app.lifeplus.model.SuperModel;
 import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
-import kr.co.zumo.app.lifeplus.util.AppUtil;
-import kr.co.zumo.app.lifeplus.util.StringUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.IPinView;
 import kr.co.zumo.app.lifeplus.view.command.ActivityChangeCommand;
@@ -79,36 +72,51 @@ public class PinPresenter extends Presenter<PinModel, IPinView> {
   public void verifyPin(String pin) {
 
     view.setDisabledPinDialog();
-    disposable = model.verifyPin(SuperModel.getInstance().getUuid(), pin)
-      .observeOn(AndroidSchedulers.mainThread())
-      .subscribe(bean -> {
-
-        Log.i("APP# PinPresenter | verifyPin", "|" + bean.toPrettyJson());
-
-        // todo 검증 학인 로직 필요
-        if (StringUtil.isFull(bean.getReturnMessage())) {
-          // 검증 완료
-          view.dismissPinDialog();
-          onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_MAIN, ScreenID.DIRECTION_NEXT));
-        }
-        else {
-          // 검증 실패, 재입력
-          countTrying(model, view);
-        }
-      }, e -> {
-        Log.e("APP# PinPresenter | verifyPin", "|" + e.getLocalizedMessage());
-
-        if (e instanceof EOFException) {
-          Log.e("APP#  PinPresenter | verifyPin", "| EOFException-- " + e.getLocalizedMessage());
-        }
-        else if (e instanceof SocketTimeoutException) {
-          Log.e("APP#  PinPresenter | verifyPin", "| SocketTimeoutException-- " + e.getLocalizedMessage());
-        }
-
-        // fixme 에러 종류에 따라서 처리 필요
-        // 통신 오류, 파싱 오류 등
-        countTrying(model, view);
-      });
+    boolean result = model.verifyPin(pin);
+
+    if (result) {
+      // 검증 완료
+      view.dismissPinDialog();
+      onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_MAIN, ScreenID.DIRECTION_NEXT));
+
+    }
+    else {
+      // 검증 실패, 재입력
+      countTrying(model, view);
+
+    }
+
+
+//    disposable = model.verifyPin(SuperModel.getInstance().getUuid(), pin)
+//      .observeOn(AndroidSchedulers.mainThread())
+//      .subscribe(bean -> {
+//
+//        Log.i("APP# PinPresenter | verifyPin", "|" + bean.toPrettyJson());
+//
+//        // todo 검증 학인 로직 필요
+//        if (StringUtil.isFull(bean.getReturnMessage())) {
+//          // 검증 완료
+//          view.dismissPinDialog();
+//          onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_MAIN, ScreenID.DIRECTION_NEXT));
+//        }
+//        else {
+//          // 검증 실패, 재입력
+//          countTrying(model, view);
+//        }
+//      }, e -> {
+//        Log.e("APP# PinPresenter | verifyPin", "|" + e.getLocalizedMessage());
+//
+//        if (e instanceof EOFException) {
+//          Log.e("APP#  PinPresenter | verifyPin", "| EOFException-- " + e.getLocalizedMessage());
+//        }
+//        else if (e instanceof SocketTimeoutException) {
+//          Log.e("APP#  PinPresenter | verifyPin", "| SocketTimeoutException-- " + e.getLocalizedMessage());
+//        }
+//
+//        // fixme 에러 종류에 따라서 처리 필요
+//        // 통신 오류, 파싱 오류 등
+//        countTrying(model, view);
+//      });
   }
 
   private void countTrying(PinModel model, IPinView view) {
@@ -116,10 +124,6 @@ public class PinPresenter extends Presenter<PinModel, IPinView> {
     final int count = model.getCount();
     int maxCount = model.getMaxTrying();
 
-    if (AppUtil.isDebug()) {
-      maxCount = 2;
-    }
-
     Log.i("APP# PinPresenter | count", "| current: " + model.getCount() + ", Max: " + maxCount);
 
     if (count < maxCount) {