Update API scheme for passport errors.

This commit is contained in:
John Preston 2018-04-17 23:42:53 +04:00
parent 22bdf15825
commit 6795ecea61
4 changed files with 66 additions and 32 deletions

View File

@ -995,9 +995,14 @@ inputSecureValue#c0da30f0 flags:# type:SecureValueType data:flags.0?SecureData f
secureValueHash#ed1ecdb0 type:SecureValueType hash:bytes = SecureValueHash; secureValueHash#ed1ecdb0 type:SecureValueType hash:bytes = SecureValueHash;
secureValueErrorData#e8a40bd9 type:SecureValueType data_hash:bytes field:string text:string = SecureValueError;
secureValueErrorFile#7a700873 type:SecureValueType file_hash:bytes text:string = SecureValueError;
secureValueErrorFiles#666220e9 type:SecureValueType file_hash:Vector<bytes> text:string = SecureValueError;
secureValueErrorSelfie#e537ced6 type:SecureValueType file_hash:bytes text:string = SecureValueError;
secureCredentialsEncrypted#33f0ea47 data:bytes hash:bytes secret:bytes = SecureCredentialsEncrypted; secureCredentialsEncrypted#33f0ea47 data:bytes hash:bytes secret:bytes = SecureCredentialsEncrypted;
account.authorizationForm#b9d3d1f0 flags:# selfie_required:flags.1?true required_types:Vector<SecureValueType> values:Vector<SecureValue> users:Vector<User> privacy_policy_url:flags.0?string = account.AuthorizationForm; account.authorizationForm#cb976d53 flags:# selfie_required:flags.1?true required_types:Vector<SecureValueType> values:Vector<SecureValue> errors:Vector<SecureValueError> users:Vector<User> privacy_policy_url:flags.0?string = account.AuthorizationForm;
account.sentEmailCode#811f854f email_pattern:string length:int = account.SentEmailCode; account.sentEmailCode#811f854f email_pattern:string length:int = account.SentEmailCode;
@ -1059,6 +1064,7 @@ account.resetWebAuthorizations#682d2594 = Bool;
account.getSecureValue#73665bc2 types:Vector<SecureValueType> = Vector<SecureValue>; account.getSecureValue#73665bc2 types:Vector<SecureValueType> = Vector<SecureValue>;
account.saveSecureValue#899fe31d value:InputSecureValue secure_secret_id:long = SecureValue; account.saveSecureValue#899fe31d value:InputSecureValue secure_secret_id:long = SecureValue;
account.deleteSecureValue#b880bc4b types:Vector<SecureValueType> = Bool; account.deleteSecureValue#b880bc4b types:Vector<SecureValueType> = Bool;
account.setSecureValueErrors#d0093ce4 user_id:InputUser errors:Vector<SecureValueError> = Bool;
account.getAuthorizationForm#b86ba8e1 bot_id:int scope:string public_key:string = account.AuthorizationForm; account.getAuthorizationForm#b86ba8e1 bot_id:int scope:string public_key:string = account.AuthorizationForm;
account.acceptAuthorization#e7027c94 bot_id:int scope:string public_key:string value_hashes:Vector<SecureValueHash> credentials:SecureCredentialsEncrypted = Bool; account.acceptAuthorization#e7027c94 bot_id:int scope:string public_key:string value_hashes:Vector<SecureValueHash> credentials:SecureCredentialsEncrypted = Bool;
account.sendVerifyPhoneCode#823380b4 flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool = auth.SentCode; account.sendVerifyPhoneCode#823380b4 flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool = auth.SentCode;

View File

@ -495,38 +495,60 @@ void FormController::decryptValues() {
} }
void FormController::fillErrors() { void FormController::fillErrors() {
const auto errors = _request.errors.toUtf8(); const auto find = [&](const MTPSecureValueType &type) -> Value* {
const auto list = DeserializeErrors(bytes::make_span(errors)); const auto converted = ConvertType(type);
for (const auto &error : list) { const auto i = _form.values.find(ConvertType(type));
for (auto &[type, value] : _form.values) { if (i != end(_form.values)) {
if (ValueCredentialsKey(type) != error.type) { return &i->second;
continue; }
} LOG(("API Error: Value not found for error type."));
if (!error.key.has_value()) { return nullptr;
value.scanMissingError = error.text; };
} else if (const auto key = base::get_if<QString>(&error.key)) { const auto scan = [&](Value &value, bytes::const_span hash) -> File* {
value.data.parsed.fields[(*key)].error = error.text; const auto i = ranges::find_if(value.scans, [&](const File &scan) {
} else if (auto hash = base::get_if<QByteArray>(&error.key)) { return !bytes::compare(hash, scan.hash);
const auto check = [&](const File &file) { });
return *hash == QByteArray::fromRawData( if (i != end(value.scans)) {
reinterpret_cast<const char*>(file.hash.data()), return &*i;
file.hash.size()); }
}; LOG(("API Error: File not found for error value."));
for (auto &scan : value.scans) { return nullptr;
if (check(scan)) { };
scan.error = error.text; for (const auto &error : _form.pendingErrors) {
break; switch (error.type()) {
} case mtpc_secureValueErrorData: {
} const auto &data = error.c_secureValueErrorData();
if (value.selfie) { if (const auto value = find(data.vtype)) {
if (check(*value.selfie) || hash->isEmpty()) { const auto key = qs(data.vfield);
value.selfie->error = error.text; value->data.parsed.fields[key].error = qs(data.vtext);
} }
} } break;
} case mtpc_secureValueErrorFile: {
break; const auto &data = error.c_secureValueErrorFile();
const auto hash = bytes::make_span(data.vfile_hash.v);
if (const auto value = find(data.vtype)) {
if (const auto file = scan(*value, hash)) {
file->error = qs(data.vtext);
}
}
} break;
case mtpc_secureValueErrorFiles: {
const auto &data = error.c_secureValueErrorFiles();
if (const auto value = find(data.vtype)) {
value->scanMissingError = qs(data.vtext);
}
} break;
case mtpc_secureValueErrorSelfie: {
const auto &data = error.c_secureValueErrorSelfie();
if (const auto value = find(data.vtype)) {
if (value->selfie) {
value->selfie->error = qs(data.vtext);
} else {
LOG(("API Error: Selfie not found for error value."));
}
}
} break;
} }
} }
} }
@ -1786,6 +1808,7 @@ void FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
_form.values.emplace(type, Value(type)); _form.values.emplace(type, Value(type));
} }
_bot = App::userLoaded(_request.botId); _bot = App::userLoaded(_request.botId);
_form.pendingErrors = data.verrors.v;
} }
void FormController::formFail(const QString &error) { void FormController::formFail(const QString &error) {

View File

@ -170,6 +170,8 @@ struct Form {
std::vector<Value::Type> request; std::vector<Value::Type> request;
bool identitySelfieRequired = false; bool identitySelfieRequired = false;
QString privacyPolicyUrl; QString privacyPolicyUrl;
QVector<MTPSecureValueError> pendingErrors;
}; };
struct PasswordSettings { struct PasswordSettings {

View File

@ -411,6 +411,9 @@ void EditScans::updateScan(ScanInfo &&info) {
_header->show(anim::type::normal); _header->show(anim::type::normal);
_uploadTexts.fire(uploadButtonText()); _uploadTexts.fire(uploadButtonText());
} }
if (_uploadMoreError) {
_uploadMoreError->toggle(!uploadedSomeMore(), anim::type::normal);
}
} }
void EditScans::createSelfieRow(const ScanInfo &info) { void EditScans::createSelfieRow(const ScanInfo &info) {