Ejemplo n.º 1
0
 public PassportFormField(PassportAuthorizationForm form, PassportSuitableElement requiredType, List <PassportSuitableElement> documentTypes, bool documentOnly)
 {
     AuthorizationForm = form;
     RequiredType      = requiredType;
     DocumentTypes     = documentTypes;
     IsDocumentOnly    = documentOnly;
 }
Ejemplo n.º 2
0
        private string ConvertRequest(PassportAuthorizationForm form, int botId)
        {
            if (form == null)
            {
                return(Strings.Resources.PassportSelfRequest);
            }

            var user = ViewModel.CacheService.GetUser(botId);

            if (user == null)
            {
                return(null);
            }

            return(String.Format(Strings.Resources.PassportRequest, user.GetFullName()));
        }
Ejemplo n.º 3
0
        private FormattedText ConvertPolicy(PassportAuthorizationForm form, int botId)
        {
            if (form == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(form.PrivacyPolicyUrl))
            {
                return(new FormattedText(Strings.Resources.PassportNoPolicy, new TextEntity[0]));
            }

            var user = ViewModel.CacheService.GetUser(botId);

            if (user == null)
            {
                return(null);
            }

            var text  = string.Format(Strings.Resources.PassportPolicy, form.PrivacyPolicyUrl, user.Username);
            var first = text.IndexOf('*');
            var last  = text.LastIndexOf('*');

            if (first != -1 && last != -1)
            {
                var builder = new StringBuilder(text);
                builder.Remove(last, 1);
                builder.Remove(first, 1);

                text = builder.ToString();

                return(new FormattedText(text, new[] { new TextEntity {
                                                           Offset = first, Length = last - first - 1, Type = new TextEntityTypeTextUrl(form.PrivacyPolicyUrl)
                                                       } }));
            }

            return(new FormattedText(text, new TextEntity[0]));
        }
Ejemplo n.º 4
0
        //private Dictionary<string, string> GenerateErrorsMap(PassportAuthorizationForm form)
        //{
        //    try
        //    {
        //        var errors = form.Errors.OrderBy(x => x.Source, new ErrorSourceComparator()).ToList();
        //        for (int a = 0, size = errors.Count; a < size; a++)
        //        {
        //            var secureValueError = errors[a];
        //            String key;
        //            String description;
        //            String target;

        //            String field = null;
        //            byte[] file_hash = null;

        //            if (secureValueError.Source is PassportElementErrorSourceFrontSide)
        //            {
        //                TLRPC.TL_secureValueErrorFrontSide secureValueErrorFrontSide = (TLRPC.TL_secureValueErrorFrontSide)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                file_hash = secureValueErrorFrontSide.file_hash;
        //                target = "front";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceReverseSide)
        //            {
        //                TLRPC.TL_secureValueErrorReverseSide secureValueErrorReverseSide = (TLRPC.TL_secureValueErrorReverseSide)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                file_hash = secureValueErrorReverseSide.file_hash;
        //                target = "reverse";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceSelfie)
        //            {
        //                TLRPC.TL_secureValueErrorSelfie secureValueErrorSelfie = (TLRPC.TL_secureValueErrorSelfie)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                file_hash = secureValueErrorSelfie.file_hash;
        //                target = "selfie";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceTranslationFile)
        //            {
        //                TLRPC.TL_secureValueErrorTranslationFile secureValueErrorTranslationFile = (TLRPC.TL_secureValueErrorTranslationFile)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                file_hash = secureValueErrorTranslationFile.file_hash;
        //                target = "translation";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceTranslationFiles)
        //            {
        //                TLRPC.TL_secureValueErrorTranslationFiles secureValueErrorTranslationFiles = (TLRPC.TL_secureValueErrorTranslationFiles)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                target = "translation";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceFile)
        //            {
        //                TLRPC.TL_secureValueErrorFile secureValueErrorFile = (TLRPC.TL_secureValueErrorFile)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                file_hash = secureValueErrorFile.file_hash;
        //                target = "files";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceFiles)
        //            {
        //                TLRPC.TL_secureValueErrorFiles secureValueErrorFiles = (TLRPC.TL_secureValueErrorFiles)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                target = "files";
        //            }
        //            else if (secureValueError is TLRPC.TL_secureValueError)
        //            {
        //                TLRPC.TL_secureValueError secureValueErrorAll = (TLRPC.TL_secureValueError)secureValueError;
        //                key = getNameForType(secureValueError.Type);
        //                description = secureValueError.Message;
        //                file_hash = secureValueErrorAll.hash;
        //                target = "error_all";
        //            }
        //            else if (secureValueError.Source is PassportElementErrorSourceDataField)
        //            {
        //                TLRPC.TL_secureValueErrorData secureValueErrorData = (TLRPC.TL_secureValueErrorData)secureValueError;
        //                boolean found = false;
        //                for (int b = 0; b < form.values.size(); b++)
        //                {
        //                    TLRPC.TL_secureValue value = form.values.get(b);
        //                    if (value.data != null && Arrays.equals(value.data.data_hash, secureValueErrorData.data_hash))
        //                    {
        //                        found = true;
        //                        break;
        //                    }
        //                }
        //                if (!found)
        //                {
        //                    continue;
        //                }
        //                key = getNameForType(secureValueErrorData.type);
        //                description = secureValueErrorData.text;
        //                field = secureValueErrorData.field;
        //                file_hash = secureValueErrorData.data_hash;
        //                target = "data";
        //            }
        //            else
        //            {
        //                continue;
        //            }
        //            HashMap<String, String> vals = errorsMap.get(key);
        //            if (vals == null)
        //            {
        //                vals = new HashMap<>();
        //                errorsMap.put(key, vals);
        //                mainErrorsMap.put(key, description);
        //            }
        //            String hash;
        //            if (file_hash != null)
        //            {
        //                hash = Base64.encodeToString(file_hash, Base64.NO_WRAP);
        //            }
        //            else
        //            {
        //                hash = "";
        //            }
        //            if ("data".Equals(target))
        //            {
        //                if (field != null)
        //                {
        //                    vals.put(field, description);
        //                }
        //            }
        //            else if ("files".Equals(target))
        //            {
        //                if (file_hash != null)
        //                {
        //                    vals.put("files" + hash, description);
        //                }
        //                else
        //                {
        //                    vals.put("files_all", description);
        //                }
        //            }
        //            else if ("selfie".Equals(target))
        //            {
        //                vals.put("selfie" + hash, description);
        //            }
        //            else if ("translation".Equals(target))
        //            {
        //                if (file_hash != null)
        //                {
        //                    vals.put("translation" + hash, description);
        //                }
        //                else
        //                {
        //                    vals.put("translation_all", description);
        //                }
        //            }
        //            else if ("front".Equals(target))
        //            {
        //                vals.put("front" + hash, description);
        //            }
        //            else if ("reverse".Equals(target))
        //            {
        //                vals.put("reverse" + hash, description);
        //            }
        //            else if ("error_all".Equals(target))
        //            {
        //                vals.put("error_all", description);
        //            }
        //        }
        //    }
        //    catch (Exception ignore)
        //    {

        //    }
        //}

        private void addField(PassportAuthorizationForm form, PassportSuitableElement requiredType, List <PassportSuitableElement> documentTypes, bool documentOnly, bool last)
        {
            Items.Add(new PassportFormField(form, requiredType, documentTypes, documentOnly));
        }