public string UpdateOption([FromBody] JObject value) { try { var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL]; if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_UPDATE_OPTION)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } var code = ""; if (value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_UPDATE_OPTION_CODE)) { code = value[ParseDataKeyApi.KEY_TWO_FA_UPDATE_OPTION_CODE].ToString(); } bool isVerify = false; switch (userModel.IsTwoFactor) { case 1: if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code); break; case 2: if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } var secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken); if (string.IsNullOrEmpty(secretAuthToken.UpdateOptionVerification)) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } isVerify = HelpersApi.CheckCodeSms(secretAuthToken.UpdateOptionVerification, code, userModel); break; case 0: isVerify = true; break; } if (!isVerify) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } var option = value[ParseDataKeyApi.KEY_TWO_FA_UPDATE_OPTION]; userModel.Verification = (int)option; _userBusiness.AddActionLog(userModel.Email, userModel.Id, ActionLog.UPDATE_OPTION_VETIFY, HelpersApi.GetIp(Request)); return(_userBusiness.UpdateProfile(userModel).ToJson()); } catch (Exception e) { _logger.Error(KeyLogger.TWOFA_OPTION_UPDATE + e); return(HelpersApi.CreateDataError(e.Message)); } }
public string VerifyCodeTransaction([FromBody] JObject value) { try { var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL]; var code = ""; var codeGG = ""; if (value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_SMS)) { code = value[ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_SMS].ToString(); } if (value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_2FA)) { codeGG = value[ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_2FA].ToString(); } bool isVerify = false; switch (userModel.IsTwoFactor) { case 1: if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_SMS)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, codeGG); break; case 2: if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_SMS)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } var secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken); if (string.IsNullOrEmpty(secretAuthToken.SendTransaction)) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } isVerify = HelpersApi.CheckCodeSms(secretAuthToken.SendTransaction, code, userModel); break; case 0: isVerify = true; break; } if (!isVerify) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } // userModel.Verification = (int) option; // su ly data gui len //to do var request = value.ToObject <SendTransaction>(); var userRequest = new UserSendTransaction() { UserId = userModel.Id, Type = "send", To = request.Detail.SendByAd ? request.Detail.RecipientWalletAddress : request.Detail.RecipientEmailAddress, SendByBlockchainAddress = request.Detail.SendByAd, Amount = request.Detail.VkcAmount, PricePerCoin = request.Detail.PricePerCoin, Currency = request.NetworkName, Description = request.Detail.VkcNote, }; ReturnObject result = null; result = AddSendTransaction(userRequest); return(JsonHelper.SerializeObject(result)); } catch (Exception e) { return(HelpersApi.CreateDataError(e.Message)); } }
public string CustomTwo([FromBody] JObject value) { try { var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL]; if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_UPDATE_STATUS)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } var status = value[ParseDataKeyApi.KEY_TWO_FA_UPDATE_STATUS]; var code = ""; if (value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { code = value[ParseDataKeyApi.KEY_PASS_DATA_GET_CODE].ToString(); } var token = ""; if (value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_ENABLE_GOOGLE_TOKEN)) { token = value[ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_ENABLE_GOOGLE_TOKEN].ToString(); } bool isVerify = false; ActionCode secretAuthToken; switch (userModel.IsTwoFactor) { case 1: if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } if ((int)status == 2) { secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken); if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa)) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } isVerify = HelpersApi.CheckCodeSms(secretAuthToken.CustomTwofa, code, userModel); } else if ((int)status == 0) { isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code); } break; case 2: if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } if ((int)status == 0) { secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken); if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa)) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } isVerify = HelpersApi.CheckCodeSms(secretAuthToken.CustomTwofa, code, userModel); } else if ((int)status == 1) { isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code); } break; case 0: if ((int)status == 1) { if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } Console.WriteLine(userModel.TwoFactorSecret); isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code); } else if ((int)status == 2) { if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE)) { return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID)); } secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken); if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa)) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } isVerify = HelpersApi.CheckCodeSms(secretAuthToken.CustomTwofa, code, userModel); } break; } Console.WriteLine(isVerify); if (!isVerify) { return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR)); } userModel.IsTwoFactor = (int)status; _userBusiness.AddActionLog(userModel.Email, userModel.Id, ActionLog.TWOFA_ENABLE, HelpersApi.GetIp(Request)); return(_userBusiness.UpdateProfile(userModel).ToJson()); } catch (Exception e) { _logger.Error(KeyLogger.TWOFA_ENABLE_UPDATE + e); return(HelpersApi.CreateDataError(e.Message)); } }