|
1 | 1 | #include "Validator.hpp" |
2 | 2 |
|
3 | | -bool Validator::isValidEmail(const std::string& email) { |
| 3 | +bool Validator::isValidEmail(const std::string &email) { |
4 | 4 | const std::regex pattern(R"(([^@\s]+)@([^\s@]+)\.([^\s@]+))"); |
5 | 5 | return std::regex_match(email, pattern); |
6 | 6 | } |
7 | 7 |
|
8 | | -bool Validator::isValidPhone(const std::string& phone) { |
| 8 | +bool Validator::isValidPhone(const std::string &phone) { |
9 | 9 | const std::regex pattern(R"(^\+\d{1,15}$)"); |
10 | 10 | return std::regex_match(phone, pattern); |
11 | 11 | } |
12 | 12 |
|
13 | | -void Validator::validateAccountParams(const std::string& email, const std::string& password, const std::string& userId) { |
| 13 | +void Validator::validateAccountParams(const std::string &email, |
| 14 | + const std::string &password, |
| 15 | + const std::string &userId) { |
14 | 16 | if (!isValidEmail(email)) { |
15 | 17 | throw std::invalid_argument("Invalid email format."); |
16 | 18 | } |
17 | 19 | if (password.length() < 8) { |
18 | | - throw std::invalid_argument("Password must be at least 8 characters long."); |
| 20 | + throw std::invalid_argument( |
| 21 | + "Password must be at least 8 characters long."); |
19 | 22 | } |
20 | 23 | if (userId.empty()) { |
21 | 24 | throw std::invalid_argument("User ID cannot be empty."); |
22 | 25 | } |
23 | 26 | } |
24 | 27 |
|
25 | | -void Validator::validateAccountParams(const std::string& email, const std::string& password) { |
| 28 | +void Validator::validateAccountParams(const std::string &email, |
| 29 | + const std::string &password) { |
26 | 30 | if (!isValidEmail(email)) { |
27 | 31 | throw std::invalid_argument("Invalid email format."); |
28 | 32 | } |
29 | 33 | if (password.length() < 8) { |
30 | | - throw std::invalid_argument("Password must be at least 8 characters long."); |
| 34 | + throw std::invalid_argument( |
| 35 | + "Password must be at least 8 characters long."); |
31 | 36 | } |
32 | 37 | } |
33 | 38 |
|
34 | | -void Validator::validateDatabaseParams(const std::string& databaseId, const std::string& name){ |
| 39 | +void Validator::validateDatabaseParams(const std::string &databaseId, |
| 40 | + const std::string &name) { |
35 | 41 | std::regex databaseIdPattern("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"); |
36 | | - |
| 42 | + |
37 | 43 | if (!std::regex_match(databaseId, databaseIdPattern)) { |
38 | | - throw std::invalid_argument("Invalid databaseId. Must start with an alphanumeric character and can contain only alphanumeric characters, periods, hyphens, and underscores, with a max length of 36 characters."); |
| 44 | + throw std::invalid_argument( |
| 45 | + "Invalid databaseId. Must start with an alphanumeric character and " |
| 46 | + "can contain only alphanumeric characters, periods, hyphens, and " |
| 47 | + "underscores, with a max length of 36 characters."); |
39 | 48 | } |
40 | 49 |
|
41 | 50 | if (name.length() > 128) { |
42 | | - throw std::invalid_argument("Invalid name. Must be 128 characters or less."); |
| 51 | + throw std::invalid_argument( |
| 52 | + "Invalid name. Must be 128 characters or less."); |
43 | 53 | } |
44 | 54 | } |
45 | 55 |
|
46 | | - |
47 | | -void Validator::validateStorageParams(const std::string& bucketId, const std::string& name){ |
| 56 | +void Validator::validateStorageParams(const std::string &bucketId, |
| 57 | + const std::string &name) { |
48 | 58 | std::regex bucketIdPattern("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"); |
49 | 59 |
|
50 | 60 | if (!std::regex_match(bucketId, bucketIdPattern)) { |
51 | | - throw std::invalid_argument("Invalid bucketId. Must start with an alphanumeric character and can contain only alphanumeric characters, periods, hyphens, and underscores, with a max length of 36 characters."); |
| 61 | + throw std::invalid_argument( |
| 62 | + "Invalid bucketId. Must start with an alphanumeric character and " |
| 63 | + "can contain only alphanumeric characters, periods, hyphens, and " |
| 64 | + "underscores, with a max length of 36 characters."); |
52 | 65 | } |
53 | 66 |
|
54 | 67 | if (name.empty()) { |
55 | 68 | throw std::invalid_argument("Bucket Name is required field."); |
56 | 69 | } |
57 | 70 | } |
58 | 71 |
|
59 | | -void Validator::validateStorageParams(const std::string& bucketId){ |
| 72 | +void Validator::validateStorageParams(const std::string &bucketId) { |
60 | 73 | std::regex bucketIdPattern("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$"); |
61 | 74 |
|
62 | 75 | if (!std::regex_match(bucketId, bucketIdPattern)) { |
63 | | - throw std::invalid_argument("Invalid bucketId. Must start with an alphanumeric character and can contain only alphanumeric characters, periods, hyphens, and underscores, with a max length of 36 characters."); |
| 76 | + throw std::invalid_argument( |
| 77 | + "Invalid bucketId. Must start with an alphanumeric character and " |
| 78 | + "can contain only alphanumeric characters, periods, hyphens, and " |
| 79 | + "underscores, with a max length of 36 characters."); |
64 | 80 | } |
65 | | - |
66 | 81 | } |
0 commit comments