Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [MOBC-608] auth ui setting page #320

Merged
merged 11 commits into from
Nov 21, 2023
3 changes: 1 addition & 2 deletions packages/deriv_auth_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- join_return_with_assignment
- library_names
- library_prefixes
# - lines_longer_than_80_chars
- list_remove_unrelated_type
- collection_methods_unrelated_type
- no_adjacent_strings_in_list
- no_duplicate_case_values
- no_leading_underscores_for_local_identifiers
Expand Down
1 change: 1 addition & 0 deletions packages/deriv_auth_ui/lib/deriv_auth_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export 'src/features/login/layouts/deriv_login_layout.dart';
export 'src/features/reset_pass/layouts/deriv_choose_new_pass_layout.dart';
export 'src/features/reset_pass/layouts/deriv_reset_pass_layout.dart';
export 'src/features/reset_pass/layouts/deriv_success_pass_change_layout.dart';
export 'src/features/setting_page/layouts/deriv_setting_layout.dart';
export 'src/features/signup/cubits/deriv_country_selection_cubit.dart';
export 'src/features/signup/layouts/deriv_country_selection_layout.dart';
export 'src/features/signup/layouts/deriv_email_not_received_layout.dart';
Expand Down
11 changes: 11 additions & 0 deletions packages/deriv_auth_ui/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class MessageLookup extends MessageLookupByLibrary {
"informVerificationEmailSent": m1,
"informYourPassHasBeenReset": MessageLookupByLibrary.simpleMessage(
"Your password has been reset"),
"labelApplicationID":
MessageLookupByLibrary.simpleMessage("Application ID"),
"labelCheckEmail":
MessageLookupByLibrary.simpleMessage("Check your email"),
"labelChooseCountry":
Expand All @@ -121,6 +123,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Create a password"),
"labelCreatePassword":
MessageLookupByLibrary.simpleMessage("Create a password"),
"labelDeveloper": MessageLookupByLibrary.simpleMessage("Developer"),
"labelDontHaveAnAccountYet":
MessageLookupByLibrary.simpleMessage("Don’t have an account yet?"),
"labelEmail": MessageLookupByLibrary.simpleMessage("Email"),
Expand All @@ -134,6 +137,7 @@ class MessageLookup extends MessageLookupByLibrary {
"The email address you entered had a mistake or typo (happens to the best of us)."),
"labelEmailIssueWrongEmail": MessageLookupByLibrary.simpleMessage(
"You accidentally gave us another email address (Usually a work or a personal one instead of the one you meant)."),
"labelEndpoint": MessageLookupByLibrary.simpleMessage("Endpoint"),
"labelGotReferralCode":
MessageLookupByLibrary.simpleMessage("Got a referral code?"),
"labelHaveAccount":
Expand Down Expand Up @@ -166,8 +170,15 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("2FA code"),
"labelVerifyYourEmail":
MessageLookupByLibrary.simpleMessage("Verify your email"),
"semanticApplicationID":
MessageLookupByLibrary.simpleMessage("Application ID"),
"semanticEndpoint": MessageLookupByLibrary.simpleMessage("Endpoint"),
"warnCountryNotAvailable": MessageLookupByLibrary.simpleMessage(
"Unfortunately, Deriv is not available in your country."),
"warnInvalidApplicationID":
MessageLookupByLibrary.simpleMessage("invalid application ID"),
"warnInvalidEndpoint":
MessageLookupByLibrary.simpleMessage("invalid endpoint"),
"warnNotAvailableCountries": MessageLookupByLibrary.simpleMessage(
"If you have any questions, contact us via "),
"warnNotAvailableCountriesTitle": m2,
Expand Down
70 changes: 70 additions & 0 deletions packages/deriv_auth_ui/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions packages/deriv_auth_ui/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,12 @@
"informExpiredAccount": "Your account is expired",
"labelCountryConsentBrazil": "I hereby confirm that my request for opening an account with Deriv to trade OTC products issued and offered exclusively outside Brazil was initiated by me. I fully understand that Deriv is not regulated by CVM and by approaching Deriv I intend to set up a relation with a foreign company.",
"informConnectionError": "Connection error. Please try again later.",
"informSwitchAccountError": "Switch account error. Please try again later."
}
"informSwitchAccountError": "Switch account error. Please try again later.",
"labelDeveloper": "Developer",
"labelEndpoint": "Endpoint",
"semanticEndpoint": "Endpoint",
"warnInvalidEndpoint": "invalid endpoint",
"labelApplicationID": "Application ID",
"semanticApplicationID": "Application ID",
"warnInvalidApplicationID": "invalid application ID"
}
36 changes: 36 additions & 0 deletions packages/deriv_auth_ui/lib/src/core/helpers/endpoint_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// Default auth endpoint.
const String defaultAuthEndpoint = 'oauth.deriv.com';

/// Default ws endpoint.
const String defaultEndpoint = 'blue.binaryws.com';

/// Default app id.
const String defaultAppId = '23789';

/// Parses an [endpoint] argument and generates a url that points to QA servers
/// if [endpoint] starts with `qa` or a url that points to production servers if
/// [endpoint] contains `derivws` or `binaryws` and [isAuthUrl] is `true`.
///
/// [endpoint] argument is required.
/// [isAuthUrl] is optional and has a default value of `false`.
String? generateEndpointUrl({
required String? endpoint,
bool isAuthUrl = false,
}) {
if (endpoint == null) {
return null;
}

final RegExp qaRegExp = RegExp('^(qa[0-9]+)\$', caseSensitive: false);
final RegExp derivRegExp =
RegExp('(binary|deriv)ws\.(com|app)\$', caseSensitive: false);

if (isAuthUrl && derivRegExp.hasMatch(endpoint)) {
// Since Deriv app is under Deriv.app, the oauth url should be always `oauth.deriv.com`.
return defaultAuthEndpoint;
} else if (qaRegExp.hasMatch(endpoint)) {
return '$endpoint.deriv.dev';
}

return endpoint;
}
94 changes: 94 additions & 0 deletions packages/deriv_auth_ui/lib/src/core/helpers/regex_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/// Valid Email Regex.
RegExp validEmailRegex =
ahrar-deriv marked this conversation as resolved.
Show resolved Hide resolved
RegExp(r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$');

/// Valid Password Regex.
RegExp validPasswordRegex =
RegExp(r'^(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])[ -~]{8,25}$');

/// Valid Password with uppercase.
RegExp validPasswordWithUppercaseRegex = RegExp(r'^(?=.*[a-z])(?=.*[A-Z]).*$');

/// Valid Password with numbers.
RegExp validPasswordWithNumberRegex = RegExp(r'^(?=.*[0-9]).*$');

/// Valid Password with symbols.
RegExp validPasswordWithSymbols = RegExp(r'^(?=.*[@#$%^&+!=]).*$');

/// Valid Password length Regex.
RegExp validPasswordLengthRegex = RegExp(r'^.{8,25}$');

/// Valid Password length for login.
RegExp validLoginPasswordLengthRegex = RegExp(r'^.{6,25}$');

/// Check if [str] input contains only a-z letters and 0-9 numbers
bool hasOnlySmallLettersAndNumberInput(String str) =>
RegExp('^[a-z0-9.]+\$').hasMatch(str);

/// Check if [string] input contains only 0-9 numbers
bool hasOnlyNumberInput(String string) => RegExp('^[0-9]+\$').hasMatch(string);

/// Gets double value from the provided [string] and returns it as a string.
String getNumFromString(String string) {
final RegExp doubleRegex =
RegExp(r'-?(?:\d*\.)?\d+(.*?:[eE][+-]?\d+)?', multiLine: true);

return doubleRegex
.allMatches(string)
.map<dynamic>((dynamic value) => value.group(0))
.toString();
}

/// Returns current account broker
String? getAccountBrokerCode(String loginId) {
final RegExp regex = RegExp('[A-Za-z]+|\\d+');
final RegExpMatch? match = regex.firstMatch(loginId);
return match?.group(0);
}

/// Check if the provided value matches the criteria of first name.
final RegExp firstNameRegexp =
RegExp(r"^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$", unicode: true);

/// Check if the provided value matches the criteria of family name.
final RegExp lastNameRegexp =
RegExp(r"^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$", unicode: true);

/// Check if the provided value matches the criteria of birthday.
final RegExp dateOfBirthRegexp =
RegExp(r'^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$', unicode: true);

/// Check if the provided value matches the criteria of first line of address.
final RegExp firstLineOfAddressRegexp =
RegExp(r"^([a-zA-Z0-9’'.,:;()@#-]+\s)*[a-zA-Z0-9''.,:;()@#-]{0,70}$");

/// Check if the provided value matches the criteria of second line of address.
final RegExp secondLineOfAddressRegexp =
RegExp(r"^([a-zA-Z0-9’'.,:;()@#-]+\s)*[a-zA-Z0-9''.,:;()@#-]{0,70}$");

/// Check if the provided value matches the criteria of town or city name.
final RegExp townOrCityRegexp =
RegExp(r"^\p{L}[\p{L}\s'.-]{0,99}$", unicode: true);

/// Check if the provided value matches the criteria of postal or zipcode.
final RegExp postalOrZipcodeRegexp =
RegExp(r'^[a-zA-Z0-9\s-]{0,20}$', unicode: true);

/// Matches phone numbers with the following characteristics:
///
/// - Phone number can start with up to 3 occurrences of '-', '.', ',', '\s' (whitespace),
/// '+', '(', ')'.
/// - The remaining part should consist of 9 to 35 occurrences of a digit (\d) followed
/// by up to 3 occurrences of the characters mentioned above.
/// - The phone number should not contain any other characters outside the specified set.
///
/// See <https://wikijs.deriv.cloud/en/squad/deriv-go/misc/phone-validation>
/// for the specification of phone validation used across Backend, Web, and Mobile.
final RegExp validPhoneNumberRegex =
RegExp(r'^[-.,\s+()]{0,3}(?:\d[-.,\s+()]{0,3}){9,35}$');

/// Matches any sequence of characters that does not contain digits.
final RegExp nonDigitSequenceRegex = RegExp(r'\D+');

/// Matches any sequence of repeated digits.
final RegExp repeatedNumberRegex = RegExp(r'^(.)\1*$');
Loading