feat: registration using invitation codes in UI
This commit is contained in:
parent
2e7033791a
commit
e85a3bebb8
@ -3,6 +3,8 @@ class ApiConstants {
|
|||||||
|
|
||||||
// Auth endpoints
|
// Auth endpoints
|
||||||
static const String loginEndpoint = '/login';
|
static const String loginEndpoint = '/login';
|
||||||
|
static const String registerEndpoint = '/register';
|
||||||
|
static const String checkInvitationEndpoint = '/checkInvitation';
|
||||||
|
|
||||||
// User endpoints
|
// User endpoints
|
||||||
static const String getUserEndpoint = '/getUser';
|
static const String getUserEndpoint = '/getUser';
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import 'screens/edit_profile_screen.dart';
|
|||||||
import 'services/auth_service.dart';
|
import 'services/auth_service.dart';
|
||||||
import 'services/user_service.dart';
|
import 'services/user_service.dart';
|
||||||
import 'services/app_lifecycle_service.dart';
|
import 'services/app_lifecycle_service.dart';
|
||||||
|
import 'services/http_service.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@ -260,10 +262,14 @@ class SignInPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _SignInPageState extends State<SignInPage> {
|
class _SignInPageState extends State<SignInPage> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _emailController = TextEditingController();
|
final _phoneController = TextEditingController();
|
||||||
final _passwordController = TextEditingController();
|
final _passwordController = TextEditingController();
|
||||||
|
final _invitationCodeController = TextEditingController();
|
||||||
|
final _countryCodeController = TextEditingController(text: '+966');
|
||||||
bool _isPasswordVisible = false;
|
bool _isPasswordVisible = false;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
bool _isRegistering = false;
|
||||||
|
int _registrationStep = 1; // 1 = invitation code, 2 = phone & password
|
||||||
|
|
||||||
void _showHelpBottomSheet() {
|
void _showHelpBottomSheet() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
@ -297,7 +303,7 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 16),
|
SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
'For account creation or password reset, please contact ERP Management Group from your Aramco email address.',
|
'Registration is by invitation only. If you don\'t have an invitation code, please contact COD/DPSD.',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
@ -331,10 +337,51 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _checkInvitationCode() async {
|
||||||
|
if (_invitationCodeController.text.trim().isEmpty) {
|
||||||
|
_showErrorAlert('Please enter your invitation code');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
final response = await HttpService.post('/checkInvitation', {
|
||||||
|
'code': _invitationCodeController.text.trim().toUpperCase(),
|
||||||
|
});
|
||||||
|
|
||||||
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data['status'] == true &&
|
||||||
|
data['data'] != null &&
|
||||||
|
data['data']['valid'] == true) {
|
||||||
|
// Invitation code is valid, move to step 2
|
||||||
|
setState(() {
|
||||||
|
_registrationStep = 2;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_showErrorAlert(data['message'] ?? 'Invalid invitation code');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
_showErrorAlert('Network error. Please try again.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_emailController.dispose();
|
_phoneController.dispose();
|
||||||
_passwordController.dispose();
|
_passwordController.dispose();
|
||||||
|
_invitationCodeController.dispose();
|
||||||
|
_countryCodeController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,8 +391,10 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final phoneNumber =
|
||||||
|
_countryCodeController.text.trim() + _phoneController.text.trim();
|
||||||
final result = await AuthService.login(
|
final result = await AuthService.login(
|
||||||
_emailController.text.trim(),
|
phoneNumber,
|
||||||
_passwordController.text,
|
_passwordController.text,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -386,11 +435,83 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleRegister() async {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
final phoneNumber =
|
||||||
|
_countryCodeController.text.trim() + _phoneController.text.trim();
|
||||||
|
|
||||||
|
final response = await HttpService.post('/register', {
|
||||||
|
'code': _invitationCodeController.text.trim().toUpperCase(),
|
||||||
|
'phoneNumber': phoneNumber,
|
||||||
|
'password': _passwordController.text,
|
||||||
|
});
|
||||||
|
|
||||||
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data['status'] == true && data['data'] != null) {
|
||||||
|
// Registration successful, save token and navigate
|
||||||
|
final token = data['data']['token'];
|
||||||
|
if (token != null) {
|
||||||
|
await AuthService.saveToken(token);
|
||||||
|
|
||||||
|
final userResult = await UserService.getCurrentUser(
|
||||||
|
forceRefresh: true,
|
||||||
|
);
|
||||||
|
if (userResult['success'] == true) {
|
||||||
|
final userData = userResult['data'];
|
||||||
|
|
||||||
|
// Check if user needs onboarding (activated = false)
|
||||||
|
if (userData['activated'] == false) {
|
||||||
|
Navigator.of(context).pushReplacement(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => EditProfileScreen(
|
||||||
|
userData: userData,
|
||||||
|
isOnboarding: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
AppLifecycleService.startAllPolling();
|
||||||
|
Navigator.of(context).pushReplacement(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => NotificationPermissionScreen(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_showErrorAlert(
|
||||||
|
'Registration successful but failed to load user data',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_showErrorAlert('Registration successful but no token received');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_showErrorAlert(data['message'] ?? 'Registration failed');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
_showErrorAlert('Network error. Please try again.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _showErrorAlert(String message) {
|
void _showErrorAlert(String message) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: Text('Login Failed'),
|
title: Text(_isRegistering ? 'Registration' : 'Login Failed'),
|
||||||
content: Text(message),
|
content: Text(message),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
@ -430,7 +551,7 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
icon: Icon(Icons.arrow_back, color: Colors.white),
|
icon: Icon(Icons.arrow_back, color: Colors.white),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'Sign In',
|
_isRegistering ? 'Register' : 'Sign In',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
@ -482,7 +603,9 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
|
|
||||||
// Welcome text
|
// Welcome text
|
||||||
Text(
|
Text(
|
||||||
'Welcome Back!',
|
_isRegistering
|
||||||
|
? 'Create Account'
|
||||||
|
: 'Welcome Back!',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -494,7 +617,9 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
'Sign in to socialize with your colleagues\nand transform your social life!',
|
_isRegistering
|
||||||
|
? 'Join with an invitation code to connect\nwith your colleagues!'
|
||||||
|
: 'Sign in to socialize with your colleagues\nand transform your social life!',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
@ -504,13 +629,15 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
|
|
||||||
SizedBox(height: 40),
|
SizedBox(height: 40),
|
||||||
|
|
||||||
// Email field
|
// Registration Step 1: Invitation Code
|
||||||
|
if (_isRegistering && _registrationStep == 1) ...[
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _invitationCodeController,
|
||||||
keyboardType: TextInputType.emailAddress,
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: 'Email',
|
labelText: 'Invitation Code',
|
||||||
prefixIcon: Icon(Icons.email_outlined),
|
prefixIcon: Icon(
|
||||||
|
Icons.confirmation_number_outlined,
|
||||||
|
),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
),
|
),
|
||||||
@ -520,21 +647,107 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
color: Color(0xFF6A4C93),
|
color: Color(0xFF6A4C93),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
helperText:
|
||||||
|
'6-character code with letters and numbers',
|
||||||
),
|
),
|
||||||
|
maxLength: 6,
|
||||||
|
textCapitalization:
|
||||||
|
TextCapitalization.characters,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return 'Please enter your email';
|
return 'Please enter your invitation code';
|
||||||
}
|
}
|
||||||
if (!value.contains('@')) {
|
if (value.length != 6) {
|
||||||
return 'Please enter a valid email';
|
return 'Invitation code must be 6 characters';
|
||||||
|
}
|
||||||
|
if (!RegExp(
|
||||||
|
r'^[A-Z0-9]{6}$',
|
||||||
|
).hasMatch(value)) {
|
||||||
|
return 'Code must contain only letters and numbers';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
// Login or Registration Step 2: Phone & Password
|
||||||
|
if (!_isRegistering || _registrationStep == 2) ...[
|
||||||
|
// Phone number field with country code input
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _countryCodeController,
|
||||||
|
keyboardType: TextInputType.phone,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Code',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
12,
|
||||||
|
),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: Color(0xFF6A4C93),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'Required';
|
||||||
|
}
|
||||||
|
if (!value.startsWith('+')) {
|
||||||
|
return 'Must start with +';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _phoneController,
|
||||||
|
keyboardType: TextInputType.phone,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Phone Number',
|
||||||
|
prefixIcon: Icon(Icons.phone_outlined),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
12,
|
||||||
|
),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: Color(0xFF6A4C93),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
validator: (value) {
|
||||||
|
if (value == null || value.isEmpty) {
|
||||||
|
return 'Please enter your phone number';
|
||||||
|
}
|
||||||
|
if (value.length < 8) {
|
||||||
|
return 'Please enter a valid phone number';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
|
// Password field (only for login or registration step 2)
|
||||||
|
if (!_isRegistering || _registrationStep == 2) ...[
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
|
|
||||||
// Password field
|
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
obscureText: !_isPasswordVisible,
|
obscureText: !_isPasswordVisible,
|
||||||
@ -549,7 +762,8 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isPasswordVisible = !_isPasswordVisible;
|
_isPasswordVisible =
|
||||||
|
!_isPasswordVisible;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -573,10 +787,12 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
|
||||||
SizedBox(height: 12),
|
SizedBox(height: 12),
|
||||||
|
|
||||||
// Forgot password
|
// Forgot password (only show for login)
|
||||||
|
if (!_isRegistering)
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
@ -593,11 +809,21 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
|
|
||||||
SizedBox(height: 30),
|
SizedBox(height: 30),
|
||||||
|
|
||||||
// Sign in button
|
// Action button based on current state
|
||||||
Container(
|
Container(
|
||||||
height: 56,
|
height: 56,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: _isLoading ? null : _handleSignIn,
|
onPressed: _isLoading
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
if (!_isRegistering) {
|
||||||
|
_handleSignIn();
|
||||||
|
} else if (_registrationStep == 1) {
|
||||||
|
_checkInvitationCode();
|
||||||
|
} else {
|
||||||
|
_handleRegister();
|
||||||
|
}
|
||||||
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Color(0xFF6A4C93),
|
backgroundColor: Color(0xFF6A4C93),
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
@ -614,7 +840,11 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
'Sign In',
|
!_isRegistering
|
||||||
|
? 'Sign In'
|
||||||
|
: (_registrationStep == 1
|
||||||
|
? 'Continue'
|
||||||
|
: 'Register'),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
@ -623,20 +853,65 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Back button for registration step 2
|
||||||
|
if (_isRegistering && _registrationStep == 2) ...[
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Container(
|
||||||
|
height: 56,
|
||||||
|
child: OutlinedButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_registrationStep = 1;
|
||||||
|
_phoneController.clear();
|
||||||
|
_passwordController.clear();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
side: BorderSide(color: Color(0xFF6A4C93)),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'Back to Invitation Code',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Color(0xFF6A4C93),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
|
|
||||||
// Contact link for new accounts
|
// Toggle between login and registration (only show on step 1)
|
||||||
|
if (!_isRegistering || _registrationStep == 1)
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"Don't have an account? ",
|
_isRegistering
|
||||||
|
? 'Already have an account? '
|
||||||
|
: "Don't have an account? ",
|
||||||
style: TextStyle(color: Colors.grey[600]),
|
style: TextStyle(color: Colors.grey[600]),
|
||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: _showHelpBottomSheet,
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_isRegistering = !_isRegistering;
|
||||||
|
_registrationStep = 1;
|
||||||
|
// Clear form when switching modes
|
||||||
|
_phoneController.clear();
|
||||||
|
_passwordController.clear();
|
||||||
|
_invitationCodeController.clear();
|
||||||
|
});
|
||||||
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Contact Support',
|
_isRegistering
|
||||||
|
? 'Sign In'
|
||||||
|
: 'Register Now!',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Color(0xFF6A4C93),
|
color: Color(0xFF6A4C93),
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
@ -646,6 +921,19 @@ class _SignInPageState extends State<SignInPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
if (_isRegistering) ...[
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Registration is only by invitation.\nIf you don\'t have an invite, contact COD/DPSD.',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
height: 1.3,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
SizedBox(height: 40),
|
SizedBox(height: 40),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -21,7 +21,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final TextEditingController _displayNameController = TextEditingController();
|
final TextEditingController _displayNameController = TextEditingController();
|
||||||
final TextEditingController _usernameController = TextEditingController();
|
final TextEditingController _usernameController = TextEditingController();
|
||||||
final TextEditingController _emailController = TextEditingController();
|
final TextEditingController _phoneController = TextEditingController();
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -33,7 +33,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
void _initializeFields() {
|
void _initializeFields() {
|
||||||
if (widget.userData != null) {
|
if (widget.userData != null) {
|
||||||
_displayNameController.text = widget.userData!['displayName'] ?? '';
|
_displayNameController.text = widget.userData!['displayName'] ?? '';
|
||||||
_emailController.text = widget.userData!['email'] ?? '';
|
_phoneController.text = widget.userData!['phoneNumber'] ?? '';
|
||||||
if (!widget.isOnboarding) {
|
if (!widget.isOnboarding) {
|
||||||
_usernameController.text = widget.userData!['username'] ?? '';
|
_usernameController.text = widget.userData!['username'] ?? '';
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
_displayNameController.dispose();
|
_displayNameController.dispose();
|
||||||
_usernameController.dispose();
|
_usernameController.dispose();
|
||||||
_emailController.dispose();
|
_phoneController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,11 +299,11 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _phoneController,
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Email address',
|
hintText: 'Phone number',
|
||||||
prefixIcon: Icon(Icons.email, color: Colors.grey[400]),
|
prefixIcon: Icon(Icons.phone, color: Colors.grey[400]),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(color: Colors.grey[300]!),
|
borderSide: BorderSide(color: Colors.grey[300]!),
|
||||||
@ -328,7 +328,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'Email cannot be changed',
|
'Phone number cannot be changed',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class AuthService {
|
|||||||
static const String _userDataKey = 'user_data';
|
static const String _userDataKey = 'user_data';
|
||||||
|
|
||||||
static Future<Map<String, dynamic>> login(
|
static Future<Map<String, dynamic>> login(
|
||||||
String emailOrUsername,
|
String phoneNumberOrUsername,
|
||||||
String password,
|
String password,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
@ -20,7 +20,7 @@ class AuthService {
|
|||||||
Uri.parse('${ApiConstants.baseUrl}${ApiConstants.loginEndpoint}'),
|
Uri.parse('${ApiConstants.baseUrl}${ApiConstants.loginEndpoint}'),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: jsonEncode({
|
body: jsonEncode({
|
||||||
'emailOrUsername': emailOrUsername,
|
'phoneNumberOrUsername': phoneNumberOrUsername,
|
||||||
'password': password,
|
'password': password,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -57,6 +57,10 @@ class AuthService {
|
|||||||
return await _storage.read(key: _tokenKey);
|
return await _storage.read(key: _tokenKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<void> saveToken(String token) async {
|
||||||
|
await _storage.write(key: _tokenKey, value: token);
|
||||||
|
}
|
||||||
|
|
||||||
static Future<bool> isLoggedIn() async {
|
static Future<bool> isLoggedIn() async {
|
||||||
final token = await getToken();
|
final token = await getToken();
|
||||||
return token != null && token.isNotEmpty;
|
return token != null && token.isNotEmpty;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user