mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix registration expiration
This commit is contained in:
@@ -43,6 +43,7 @@ import com.kunzisoft.keepass.model.RegisterInfo
|
|||||||
import com.kunzisoft.keepass.model.SearchInfo
|
import com.kunzisoft.keepass.model.SearchInfo
|
||||||
import com.kunzisoft.keepass.settings.AutofillSettingsActivity
|
import com.kunzisoft.keepass.settings.AutofillSettingsActivity
|
||||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||||
|
import org.joda.time.DateTime
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
|
|
||||||
@@ -250,16 +251,16 @@ class KeeAutofillService : AutofillService() {
|
|||||||
&& autofillAllowedFor(parseResult.webDomain, webDomainBlocklist)) {
|
&& autofillAllowedFor(parseResult.webDomain, webDomainBlocklist)) {
|
||||||
Log.d(TAG, "autofill onSaveRequest password")
|
Log.d(TAG, "autofill onSaveRequest password")
|
||||||
|
|
||||||
|
// Build expiration from date or from year and month
|
||||||
if (parseResult.creditCardExpirationValue == null) {
|
var expiration: DateTime? = parseResult.creditCardExpirationValue
|
||||||
if (parseResult.creditCardExpirationMonthValue != 0 && parseResult.creditCardExpirationYearValue != 0) {
|
if (parseResult.creditCardExpirationValue == null
|
||||||
parseResult.creditCardExpirationValue = parseResult.creditCardExpirationMonthValue.toString().padStart(2, '0') + parseResult.creditCardExpirationYearValue.toString()
|
&& parseResult.creditCardExpirationYearValue != 0
|
||||||
}
|
&& parseResult.creditCardExpirationMonthValue != 0) {
|
||||||
|
expiration = DateTime()
|
||||||
|
.withYear(parseResult.creditCardExpirationYearValue)
|
||||||
|
.withMonthOfYear(parseResult.creditCardExpirationMonthValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
val creditCard = CreditCard(parseResult.creditCardHolder, parseResult.creditCardNumber,
|
|
||||||
parseResult.creditCardExpirationValue, parseResult.cardVerificationValue)
|
|
||||||
|
|
||||||
// Show UI to save data
|
// Show UI to save data
|
||||||
val registerInfo = RegisterInfo(
|
val registerInfo = RegisterInfo(
|
||||||
SearchInfo().apply {
|
SearchInfo().apply {
|
||||||
@@ -269,7 +270,12 @@ class KeeAutofillService : AutofillService() {
|
|||||||
},
|
},
|
||||||
parseResult.usernameValue?.textValue?.toString(),
|
parseResult.usernameValue?.textValue?.toString(),
|
||||||
parseResult.passwordValue?.textValue?.toString(),
|
parseResult.passwordValue?.textValue?.toString(),
|
||||||
creditCard)
|
CreditCard(
|
||||||
|
parseResult.creditCardHolder,
|
||||||
|
parseResult.creditCardNumber,
|
||||||
|
expiration,
|
||||||
|
parseResult.cardVerificationValue
|
||||||
|
))
|
||||||
|
|
||||||
// TODO Callback in each activity #765
|
// TODO Callback in each activity #765
|
||||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.view.View
|
|||||||
import android.view.autofill.AutofillId
|
import android.view.autofill.AutofillId
|
||||||
import android.view.autofill.AutofillValue
|
import android.view.autofill.AutofillValue
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@@ -160,7 +161,13 @@ class StructureParser(private val structure: AssistStructure) {
|
|||||||
node.autofillValue?.let { value ->
|
node.autofillValue?.let { value ->
|
||||||
if (value.isText && value.textValue.length == 7) {
|
if (value.isText && value.textValue.length == 7) {
|
||||||
value.textValue.let { date ->
|
value.textValue.let { date ->
|
||||||
result?.creditCardExpirationValue = date.substring(5, 7) + date.substring(2, 4)
|
try {
|
||||||
|
result?.creditCardExpirationValue = DateTime()
|
||||||
|
.withYear(date.substring(2, 4).toInt())
|
||||||
|
.withMonthOfYear(date.substring(5, 7).toInt())
|
||||||
|
} catch(e: Exception) {
|
||||||
|
Log.e(TAG, "Unable to retrieve expiration", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,12 +177,7 @@ class StructureParser(private val structure: AssistStructure) {
|
|||||||
result?.creditCardExpirationDateId = autofillId
|
result?.creditCardExpirationDateId = autofillId
|
||||||
node.autofillValue?.let { value ->
|
node.autofillValue?.let { value ->
|
||||||
if (value.isDate) {
|
if (value.isDate) {
|
||||||
val calendar = Calendar.getInstance()
|
result?.creditCardExpirationValue = DateTime(value.dateValue)
|
||||||
calendar.clear()
|
|
||||||
calendar.timeInMillis = value.dateValue
|
|
||||||
val year = calendar.get(Calendar.YEAR).toString().substring(2,4)
|
|
||||||
val month = calendar.get(Calendar.MONTH).inc().toString().padStart(2, '0')
|
|
||||||
result?.creditCardExpirationValue = month + year
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,7 +491,7 @@ class StructureParser(private val structure: AssistStructure) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// format MMYY
|
// format MMYY
|
||||||
var creditCardExpirationValue: String? = null
|
var creditCardExpirationValue: DateTime? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
if (allowSaveValues)
|
if (allowSaveValues)
|
||||||
field = value
|
field = value
|
||||||
|
|||||||
@@ -2,23 +2,24 @@ package com.kunzisoft.keepass.model
|
|||||||
|
|
||||||
import android.os.Parcel
|
import android.os.Parcel
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
data class CreditCard(val cardholder: String?,
|
data class CreditCard(val cardholder: String?,
|
||||||
val number: String?,
|
val number: String?,
|
||||||
val expiration: String?,
|
val expiration: DateTime?,
|
||||||
val cvv: String?) : Parcelable {
|
val cvv: String?) : Parcelable {
|
||||||
|
|
||||||
constructor(parcel: Parcel) : this(
|
constructor(parcel: Parcel) : this(
|
||||||
parcel.readString(),
|
parcel.readString(),
|
||||||
parcel.readString(),
|
parcel.readString(),
|
||||||
parcel.readString(),
|
parcel.readSerializable() as DateTime?,
|
||||||
parcel.readString()) {
|
parcel.readString()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
parcel.writeString(cardholder)
|
parcel.writeString(cardholder)
|
||||||
parcel.writeString(number)
|
parcel.writeString(number)
|
||||||
parcel.writeString(expiration)
|
parcel.writeSerializable(expiration)
|
||||||
parcel.writeString(cvv)
|
parcel.writeString(cvv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.os.ParcelUuid
|
|||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import com.kunzisoft.keepass.database.element.Attachment
|
import com.kunzisoft.keepass.database.element.Attachment
|
||||||
import com.kunzisoft.keepass.database.element.Database
|
import com.kunzisoft.keepass.database.element.Database
|
||||||
|
import com.kunzisoft.keepass.database.element.DateInstant
|
||||||
import com.kunzisoft.keepass.database.element.Field
|
import com.kunzisoft.keepass.database.element.Field
|
||||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||||
import com.kunzisoft.keepass.database.element.template.TemplateField
|
import com.kunzisoft.keepass.database.element.template.TemplateField
|
||||||
@@ -168,7 +169,7 @@ class EntryInfo : NodeInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (database?.allowEntryCustomFields() == true) {
|
if (database?.allowEntryCustomFields() == true) {
|
||||||
val creditCard: CreditCard? = registerInfo.cc
|
val creditCard: CreditCard? = registerInfo.creditCard
|
||||||
|
|
||||||
creditCard?.let { cc ->
|
creditCard?.let { cc ->
|
||||||
cc.cardholder?.let {
|
cc.cardholder?.let {
|
||||||
@@ -177,7 +178,7 @@ class EntryInfo : NodeInfo {
|
|||||||
}
|
}
|
||||||
cc.expiration?.let {
|
cc.expiration?.let {
|
||||||
expires = true
|
expires = true
|
||||||
// TODO Expiration expiryTime = it
|
expiryTime = DateInstant(cc.expiration.millis)
|
||||||
}
|
}
|
||||||
cc.number?.let {
|
cc.number?.let {
|
||||||
val v = ProtectedString(false, it)
|
val v = ProtectedString(false, it)
|
||||||
|
|||||||
@@ -32,13 +32,6 @@ open class NodeInfo() : Parcelable {
|
|||||||
parcel.writeParcelable(expiryTime, flags)
|
parcel.writeParcelable(expiryTime, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getExpiresStringValue(): String {
|
|
||||||
return if (expires)
|
|
||||||
expiryTime.toString()
|
|
||||||
else
|
|
||||||
""
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun describeContents(): Int {
|
override fun describeContents(): Int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import android.os.Parcelable
|
|||||||
data class RegisterInfo(val searchInfo: SearchInfo,
|
data class RegisterInfo(val searchInfo: SearchInfo,
|
||||||
val username: String?,
|
val username: String?,
|
||||||
val password: String?,
|
val password: String?,
|
||||||
val cc: CreditCard?): Parcelable {
|
val creditCard: CreditCard?): Parcelable {
|
||||||
|
|
||||||
constructor(parcel: Parcel) : this(
|
constructor(parcel: Parcel) : this(
|
||||||
parcel.readParcelable(SearchInfo::class.java.classLoader) ?: SearchInfo(),
|
parcel.readParcelable(SearchInfo::class.java.classLoader) ?: SearchInfo(),
|
||||||
@@ -19,7 +19,7 @@ data class RegisterInfo(val searchInfo: SearchInfo,
|
|||||||
parcel.writeParcelable(searchInfo, flags)
|
parcel.writeParcelable(searchInfo, flags)
|
||||||
parcel.writeString(username)
|
parcel.writeString(username)
|
||||||
parcel.writeString(password)
|
parcel.writeString(password)
|
||||||
parcel.writeParcelable(cc, flags)
|
parcel.writeParcelable(creditCard, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun describeContents(): Int {
|
override fun describeContents(): Int {
|
||||||
|
|||||||
Reference in New Issue
Block a user