D1APP-111 reset password
This commit is contained in:
parent
d7eff24d29
commit
71a5bda8c9
|
|
@ -10,6 +10,7 @@ import 'package:didvan/utils/action_sheet.dart';
|
|||
|
||||
class UserProvider extends CoreProvier {
|
||||
late User user;
|
||||
bool isAuthenticated = false;
|
||||
|
||||
static final List<MapEntry> _radarMarkQueue = [];
|
||||
static final List<MapEntry> _newsMarkQueue = [];
|
||||
|
|
@ -24,6 +25,7 @@ class UserProvider extends CoreProvier {
|
|||
}
|
||||
|
||||
Future<void> getUserInfo() async {
|
||||
isAuthenticated = true;
|
||||
final RequestService service = RequestService(RequestHelper.userInfo);
|
||||
await service.httpGet();
|
||||
if (service.isSuccess) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class RequestHelper {
|
|||
static const String _baseDirectUrl = _baseUserUrl + '/direct';
|
||||
|
||||
static const String confirmUsername = _baseUserUrl + '/confirmUsername';
|
||||
static const String changePassword = _baseUserUrl + '/changePassword';
|
||||
static const String login = _baseUserUrl + '/login';
|
||||
static const String directs = _baseUserUrl + '/direct';
|
||||
static const String userInfo = _baseUserUrl + '/info';
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class AuthenticationState extends CoreProvier {
|
|||
int _currentPageIndex = 0;
|
||||
String username = '';
|
||||
String password = '';
|
||||
String _verificationCode = '';
|
||||
|
||||
set currentPageIndex(int value) {
|
||||
_currentPageIndex = value;
|
||||
|
|
@ -58,28 +59,62 @@ class AuthenticationState extends CoreProvier {
|
|||
}
|
||||
|
||||
Future<void> sendOtpToken() async {
|
||||
final service = RequestService(RequestHelper.otp + '?username=$username');
|
||||
final service = RequestService(
|
||||
RequestHelper.otp + '?username=$username',
|
||||
useAutherization: false,
|
||||
);
|
||||
await service.httpGet();
|
||||
}
|
||||
|
||||
Future<bool> verifyOtpToken(String token) async {
|
||||
appState = AppState.isolatedBusy;
|
||||
|
||||
final service = RequestService(RequestHelper.otp, body: {
|
||||
'code': token,
|
||||
'username': username,
|
||||
});
|
||||
final service = RequestService(
|
||||
RequestHelper.otp,
|
||||
body: {
|
||||
'code': token,
|
||||
'username': username,
|
||||
},
|
||||
useAutherization: false,
|
||||
);
|
||||
await service.post();
|
||||
appState = AppState.idle;
|
||||
if (service.isSuccess) {
|
||||
_verificationCode = token;
|
||||
currentPageIndex++;
|
||||
return true;
|
||||
}
|
||||
ActionSheetUtils.showAlert(AlertData(
|
||||
message: service.isSuccess
|
||||
? service.result['message']
|
||||
: 'کد وارد شده صحیح نمیباشد',
|
||||
));
|
||||
ActionSheetUtils.showAlert(
|
||||
AlertData(
|
||||
message: service.isSuccess
|
||||
? service.result['message']
|
||||
: 'کد وارد شده صحیح نمیباشد',
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> resetPassword(String password) async {
|
||||
appState = AppState.isolatedBusy;
|
||||
final service = RequestService(
|
||||
RequestHelper.changePassword,
|
||||
body: {
|
||||
'code': _verificationCode,
|
||||
'username': username,
|
||||
'password': password,
|
||||
},
|
||||
useAutherization: false,
|
||||
);
|
||||
await service.put();
|
||||
if (service.isSuccess) {
|
||||
ActionSheetUtils.showAlert(
|
||||
AlertData(
|
||||
message: 'کلمه عبور با موفقیت تغییر کرد',
|
||||
aLertType: ALertType.success,
|
||||
),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
ActionSheetUtils.showAlert(AlertData(message: service.errorMessage));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,75 @@
|
|||
import 'package:didvan/providers/user_provider.dart';
|
||||
import 'package:didvan/routes/routes.dart';
|
||||
import 'package:didvan/views/authentication/authentication_state.dart';
|
||||
import 'package:didvan/views/authentication/widgets/authentication_layout.dart';
|
||||
import 'package:didvan/views/widgets/didvan/button.dart';
|
||||
import 'package:didvan/views/widgets/didvan/text_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ResetPassword extends StatelessWidget {
|
||||
class ResetPassword extends StatefulWidget {
|
||||
const ResetPassword({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ResetPassword> createState() => _ResetPasswordState();
|
||||
}
|
||||
|
||||
class _ResetPasswordState extends State<ResetPassword> {
|
||||
String _password = '';
|
||||
String _passwordConfirmation = '';
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AuthenticationLayout(
|
||||
children: [
|
||||
DidvanTextField(
|
||||
title: 'کلمه عبور جدید',
|
||||
onChanged: (value) {},
|
||||
hintText: 'کلمه عبور جدید',
|
||||
obsecureText: true,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
DidvanTextField(
|
||||
title: 'کلمه عبور جدید',
|
||||
onChanged: (value) {},
|
||||
hintText: 'کلمه عبور جدید',
|
||||
obsecureText: true,
|
||||
),
|
||||
const Spacer(),
|
||||
DidvanButton(
|
||||
onPressed: () {},
|
||||
title: 'تغییر رمز عبور',
|
||||
),
|
||||
const SizedBox(
|
||||
height: 48,
|
||||
),
|
||||
],
|
||||
return Form(
|
||||
key: _formKey,
|
||||
child: AuthenticationLayout(
|
||||
children: [
|
||||
DidvanTextField(
|
||||
title: 'کلمه عبور جدید',
|
||||
onChanged: (value) => _password = value,
|
||||
validator: (value) => value.length < 8
|
||||
? 'کلمه عبور نمیتواند کمتر از 8 کاراکتر داشته باشد'
|
||||
: null,
|
||||
hintText: 'کلمه عبور جدید',
|
||||
obsecureText: true,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
DidvanTextField(
|
||||
title: 'تکرار کلمه عبور جدید',
|
||||
onChanged: (value) => _passwordConfirmation = value,
|
||||
validator: (value) => _passwordConfirmation != _password
|
||||
? 'تکرار کلمه عبور با کلمه عبور یکسان نیست'
|
||||
: null,
|
||||
hintText: 'تکرار کلمه عبور جدید',
|
||||
obsecureText: true,
|
||||
),
|
||||
const Spacer(),
|
||||
DidvanButton(
|
||||
onPressed: () async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
final result = await context
|
||||
.read<AuthenticationState>()
|
||||
.resetPassword(_password);
|
||||
if (result && context.read<UserProvider>().isAuthenticated) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.authenticaion,
|
||||
arguments: false,
|
||||
);
|
||||
},
|
||||
title: 'تغییر رمز عبور',
|
||||
),
|
||||
const SizedBox(
|
||||
height: 48,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,14 +124,18 @@ class _VerificationState extends State<Verification> {
|
|||
_timer?.cancel();
|
||||
_isResendButtonEnabled = false;
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
setState(() {
|
||||
_secondsRemaining -= 1;
|
||||
if (_secondsRemaining == 0) {
|
||||
_isResendButtonEnabled = true;
|
||||
_secondsRemaining = 129;
|
||||
_timer?.cancel();
|
||||
}
|
||||
});
|
||||
try {
|
||||
setState(() {
|
||||
_secondsRemaining -= 1;
|
||||
if (_secondsRemaining == 0) {
|
||||
_isResendButtonEnabled = true;
|
||||
_secondsRemaining = 129;
|
||||
_timer?.cancel();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
_timer?.cancel();
|
||||
}
|
||||
});
|
||||
setState(() {});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue