Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.34 KB | None | 0 0
  1. internal Account.RegisterData DeserializeRegistrationJsonData(string jsonString)
  2.         {
  3.             var format = "dd/MM/yyyy";
  4.             var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = format, Culture = CultureInfo.InvariantCulture };
  5.             var registrationData = JsonConvert.DeserializeObject<Account.RegisterData>(jsonString, dateTimeConverter);
  6.  
  7.             if (registrationData == null)
  8.                 throw new Exception("Can't deserialize json string, which must contain registration data.");
  9.  
  10.             return registrationData;
  11.         }
  12.  
  13.         internal KeyValuePair<bool, DataError> CheckRegisterDataFromWeb(Account.RegisterData registerData)
  14.         {
  15.             // login
  16.             if (registerData.Login == null || registerData.Login == String.Empty)
  17.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 0, Message = "No login was provided." });
  18.  
  19.             if (registerData.Login.Length < 4)
  20.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 1, Message = "Username must be at least 4 characters length." });
  21.  
  22.             if (registerData.Login.Length >= 22)
  23.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 2, Message = "Username must be not more, than 22 characters length." });
  24.  
  25.             if (Char.IsNumber(registerData.Login[0]))
  26.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 3, Message = "Username must start with the character, not a number." });
  27.  
  28.             // email
  29.             if (registerData.Email == null || registerData.Email == String.Empty)
  30.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 4, Message = "No email was provided." });
  31.  
  32.             if (registerData.Email.IndexOf('@') == -1)
  33.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 5, Message = "Email must have a `@` character." });
  34.  
  35.             if (registerData.Email.IndexOf('.') == -1)
  36.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 6, Message = "Email must have a `.` character." });
  37.  
  38.             if (registerData.Email.Length < 6)
  39.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 7, Message = "Emailmust be at least 6 characters length." });
  40.  
  41.             if (registerData.Email.Length >= 50)
  42.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 8, Message = "Email must be not more, than 50 characters length." });
  43.  
  44.             // password
  45.             if (registerData.Password == null || registerData.Password == String.Empty)
  46.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 9, Message = "No password was provided." });
  47.  
  48.             if (registerData.Password.Length < 8)
  49.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 10, Message = "Password must be at least 8 characters length." });
  50.  
  51.             if (registerData.Password.Length >= 30)
  52.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 11, Message = "Password must be not more, than 30 characters length." });
  53.  
  54.             var specialChars = "!@#$%^&*()".ToCharArray();
  55.             if (registerData.Password.IndexOfAny(specialChars) == -1)
  56.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 12, Message = "Password must have at least one special character." });
  57.  
  58.             // personal info
  59.             if (registerData.PersonalInfo == null)
  60.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 13, Message = "No personal info was provided." });
  61.  
  62.             if (registerData.PersonalInfo.BirthDate == null)
  63.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 14, Message = "No birthdate was provided." });
  64.  
  65.             if (registerData.PersonalInfo.Gender == null)
  66.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 15, Message = "No gender was provided." });
  67.  
  68.             if (registerData.PersonalInfo.Name == null || registerData.PersonalInfo.Name == String.Empty)
  69.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 16, Message = "No real name was provided." });
  70.  
  71.             if (registerData.PersonalInfo.Surname == null || registerData.PersonalInfo.Surname == String.Empty)
  72.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 17, Message = "No real surname was provided." });
  73.  
  74.             if (registerData.PersonalInfo.PhoneNumber == null || registerData.PersonalInfo.PhoneNumber == String.Empty)
  75.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 18, Message = "No phone number was provided." });
  76.  
  77.             if (registerData.PersonalInfo.PhoneNumber.Length < 8)
  78.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 19, Message = "Phone number must be at least 8 characters length." });
  79.  
  80.             if (registerData.PersonalInfo.PhoneNumber.Length >= 40)
  81.                 return new KeyValuePair<bool, DataError>(false, new DataError { Id = 20, Message = "Phone number must be not more, than 40 characters length." });
  82.  
  83.             return new KeyValuePair<bool, DataError>(true, null);
  84.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement