Esempio n. 1
0
        public static bool TryParseEmailVerificationString(string value, out Guid userId, out string verificationCode)
        {
            userId           = Guid.Empty;
            verificationCode = string.Empty;

            if (string.IsNullOrWhiteSpace(value))
            {
                return(false);
            }

            value = value.Replace("-", "/").Replace("_", "+");

            string s = Decrypt(value);

            if (string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }

            string[] sections = s.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (sections.Length != 4)
            {
                return(false);
            }

            userId = IDConverter.Decode(sections[1]);

            verificationCode = sections[2];

            return(userId != Guid.Empty && !string.IsNullOrEmpty(verificationCode));
        }
Esempio n. 2
0
        public T ConvertTo <T>() where T : new()
        {
            if (this.Request != null)
            {
                //enforce UserId in the target object before serialization
                switch (this.Mode)
                {
                case AuthenticationMode.UserCookie:
                    if (!this.Request.ContainsKey("UserId"))
                    {
                        this.Request.Add("UserId", IDConverter.Encode(this.UserId));
                    }
                    else
                    {
                        this.Request["UserId"] = IDConverter.Encode(this.UserId);
                    }
                    break;

                case AuthenticationMode.API:
                    if (this.Request.ContainsKey("UserId"))
                    {
                        this.UserId = IDConverter.Decode(this.Request["UserId"].ToString());
                    }
                    break;
                }

                return(this.Request.ToObject <T>());
            }

            return(new T());
        }
Esempio n. 3
0
        public static string BuildEmailVerificationString(Guid userId, string verificationCode)
        {
            var s = string.Join("|",
                                DateTime.UtcNow.Ticks,
                                IDConverter.Encode(userId),
                                verificationCode,
                                DateTime.UtcNow.AddYears(-20).Ticks);

            s = Encrypt(s);

            return(s.Replace("/", "-").Replace("+", "_"));
        }
Esempio n. 4
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) =>
 reader.TokenType == JsonToken.Null
                         ? null
                         : reader.TokenType != JsonToken.String
                                 ? null
                                 : (object)IDConverter.Decode(reader.Value.ToString());
Esempio n. 5
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => writer.WriteValue(IDConverter.Encode((Guid)value));
Esempio n. 6
0
 public static Guid Decode(this string id) => IDConverter.Decode(id);
Esempio n. 7
0
 public static string Encode(this Guid id) => IDConverter.Encode(id);