Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal Account.RegisterData DeserializeRegistrationJsonData(string jsonString)
- {
- var format = "dd/MM/yyyy";
- var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = format, Culture = CultureInfo.InvariantCulture };
- var registrationData = JsonConvert.DeserializeObject<Account.RegisterData>(jsonString, dateTimeConverter);
- if (registrationData == null)
- throw new Exception("Can't deserialize json string, which must contain registration data.");
- return registrationData;
- }
- internal KeyValuePair<bool, DataError> CheckRegisterDataFromWeb(Account.RegisterData registerData)
- {
- // login
- if (registerData.Login == null || registerData.Login == String.Empty)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 0, Message = "No login was provided." });
- if (registerData.Login.Length < 4)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 1, Message = "Username must be at least 4 characters length." });
- if (registerData.Login.Length >= 22)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 2, Message = "Username must be not more, than 22 characters length." });
- if (Char.IsNumber(registerData.Login[0]))
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 3, Message = "Username must start with the character, not a number." });
- // email
- if (registerData.Email == null || registerData.Email == String.Empty)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 4, Message = "No email was provided." });
- if (registerData.Email.IndexOf('@') == -1)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 5, Message = "Email must have a `@` character." });
- if (registerData.Email.IndexOf('.') == -1)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 6, Message = "Email must have a `.` character." });
- if (registerData.Email.Length < 6)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 7, Message = "Emailmust be at least 6 characters length." });
- if (registerData.Email.Length >= 50)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 8, Message = "Email must be not more, than 50 characters length." });
- // password
- if (registerData.Password == null || registerData.Password == String.Empty)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 9, Message = "No password was provided." });
- if (registerData.Password.Length < 8)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 10, Message = "Password must be at least 8 characters length." });
- if (registerData.Password.Length >= 30)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 11, Message = "Password must be not more, than 30 characters length." });
- var specialChars = "!@#$%^&*()".ToCharArray();
- if (registerData.Password.IndexOfAny(specialChars) == -1)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 12, Message = "Password must have at least one special character." });
- // personal info
- if (registerData.PersonalInfo == null)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 13, Message = "No personal info was provided." });
- if (registerData.PersonalInfo.BirthDate == null)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 14, Message = "No birthdate was provided." });
- if (registerData.PersonalInfo.Gender == null)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 15, Message = "No gender was provided." });
- if (registerData.PersonalInfo.Name == null || registerData.PersonalInfo.Name == String.Empty)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 16, Message = "No real name was provided." });
- if (registerData.PersonalInfo.Surname == null || registerData.PersonalInfo.Surname == String.Empty)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 17, Message = "No real surname was provided." });
- if (registerData.PersonalInfo.PhoneNumber == null || registerData.PersonalInfo.PhoneNumber == String.Empty)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 18, Message = "No phone number was provided." });
- if (registerData.PersonalInfo.PhoneNumber.Length < 8)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 19, Message = "Phone number must be at least 8 characters length." });
- if (registerData.PersonalInfo.PhoneNumber.Length >= 40)
- return new KeyValuePair<bool, DataError>(false, new DataError { Id = 20, Message = "Phone number must be not more, than 40 characters length." });
- return new KeyValuePair<bool, DataError>(true, null);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement