smal button enable for domin match
This commit is contained in:
parent
f4e28d2629
commit
653316dfa1
@ -59,6 +59,8 @@ class _loginState extends State<login> {
|
|||||||
int? _resendToken;
|
int? _resendToken;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
bool _isLoadingSAML = false;
|
bool _isLoadingSAML = false;
|
||||||
|
bool _isSsoButtonEnabled = false;
|
||||||
|
List<String> _samlDomains = [];
|
||||||
bool isEmailFieldVisible = false;
|
bool isEmailFieldVisible = false;
|
||||||
bool _obscurePassword = true;
|
bool _obscurePassword = true;
|
||||||
bool _resetObscurePassword = true;
|
bool _resetObscurePassword = true;
|
||||||
@ -100,10 +102,17 @@ class _loginState extends State<login> {
|
|||||||
decoration: TextDecoration.underline,
|
decoration: TextDecoration.underline,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static const String _appSignature =
|
||||||
|
'nhance-2025-signature-T8f6gV9k5fK2wf5V5c4vId3b0J8z6cAm2x8Y';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
countryController.text = "+91";
|
countryController.text = "+91";
|
||||||
|
emailMobileController.addListener(_updateSsoButtonEnabledState);
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_fetchSamlDomainsList();
|
||||||
|
});
|
||||||
_privacyPolicyTap.onTap = () {
|
_privacyPolicyTap.onTap = () {
|
||||||
if (mounted) context.go('/privacypolicy');
|
if (mounted) context.go('/privacypolicy');
|
||||||
};
|
};
|
||||||
@ -171,11 +180,71 @@ class _loginState extends State<login> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
emailMobileController.removeListener(_updateSsoButtonEnabledState);
|
||||||
_privacyPolicyTap.dispose();
|
_privacyPolicyTap.dispose();
|
||||||
_termsOfUseTap.dispose();
|
_termsOfUseTap.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _fetchSamlDomainsList() async {
|
||||||
|
try {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('${Environment.apiUrlEnrollment}getSamlDomainsList'),
|
||||||
|
headers: {'APP-SIGNATURE': _appSignature},
|
||||||
|
);
|
||||||
|
if (!mounted) return;
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
logDebug('getSamlDomainsList failed: ${response.statusCode}');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final body = json.decode(response.body);
|
||||||
|
if (body is! Map<String, dynamic>) return;
|
||||||
|
if (body['status']?.toString() != 'success') {
|
||||||
|
logDebug('getSamlDomainsList: ${body['message']}');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final domains = _parseSamlDomainsFromResponse(body);
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_samlDomains = domains;
|
||||||
|
});
|
||||||
|
_updateSsoButtonEnabledState();
|
||||||
|
} catch (e) {
|
||||||
|
logDebug('getSamlDomainsList error: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// API: `{ "data": ["travelspends.com", "azurevenbainfotech.onmicrosoft.com"] }`
|
||||||
|
List<String> _parseSamlDomainsFromResponse(Map<String, dynamic> body) {
|
||||||
|
final data = body['data'];
|
||||||
|
if (data is! List) return [];
|
||||||
|
return data
|
||||||
|
.whereType<String>()
|
||||||
|
.map((d) => d.trim().toLowerCase())
|
||||||
|
.where((d) => d.isNotEmpty)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
String? _emailDomainFromInput(String input) {
|
||||||
|
final trimmed = input.trim();
|
||||||
|
if (!_isValidEmailForSso(trimmed)) return null;
|
||||||
|
return trimmed.split('@').last.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _emailDomainMatchesSamlList(String input) {
|
||||||
|
final domain = _emailDomainFromInput(input);
|
||||||
|
if (domain == null || _samlDomains.isEmpty) return false;
|
||||||
|
return _samlDomains.contains(domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updateSsoButtonEnabledState() {
|
||||||
|
final enabled =
|
||||||
|
_emailDomainMatchesSamlList(emailMobileController.text);
|
||||||
|
if (enabled == _isSsoButtonEnabled) return;
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _isSsoButtonEnabled = enabled);
|
||||||
|
}
|
||||||
|
|
||||||
void validatePassword(String password) {
|
void validatePassword(String password) {
|
||||||
setState(() {
|
setState(() {
|
||||||
hasMinLength = password.length >= 8;
|
hasMinLength = password.length >= 8;
|
||||||
@ -1817,18 +1886,27 @@ class _loginState extends State<login> {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 45,
|
height: 45,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: _handleSsoLoginButtonTap,
|
onPressed: _isSsoButtonEnabled &&
|
||||||
|
!_isLoadingSAML
|
||||||
|
? _handleSsoLoginButtonTap
|
||||||
|
: null,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
foregroundColor: Colors.black,
|
foregroundColor: Colors.black,
|
||||||
|
disabledBackgroundColor:
|
||||||
|
const Color(0xFFF5F5F5),
|
||||||
|
disabledForegroundColor:
|
||||||
|
Colors.black38,
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 24,
|
horizontal: 24,
|
||||||
vertical: 5,
|
vertical: 5,
|
||||||
),
|
),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(18),
|
borderRadius: BorderRadius.circular(18),
|
||||||
side: const BorderSide(
|
side: BorderSide(
|
||||||
color: Colors.black,
|
color: _isSsoButtonEnabled
|
||||||
|
? Colors.black
|
||||||
|
: Colors.black26,
|
||||||
width: 0.5,
|
width: 0.5,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user