forgot password, otp & change password api added.
parent
924ed53989
commit
d3fe9c4a02
@ -1,8 +1,27 @@
|
||||
import 'package:tangheem/classes/consts.dart';
|
||||
import 'package:tangheem/models/general_response_model.dart';
|
||||
import 'api_client.dart';
|
||||
|
||||
class UserApiClient {
|
||||
static final UserApiClient _instance = UserApiClient._internal();
|
||||
UserApiClient._internal();
|
||||
factory UserApiClient() => _instance;
|
||||
|
||||
Future<GeneralResponseModel> forgotPassword(String _email) async {
|
||||
String url = "${ApiConsts.user}ForgotPassword";
|
||||
var postParams = {"email": _email};
|
||||
return await ApiClient().postJsonForObject((json) => GeneralResponseModel.fromJson(json), url, postParams);
|
||||
}
|
||||
|
||||
Future<GeneralResponseModel> verifyOTP(String _email, int _otp) async {
|
||||
String url = "${ApiConsts.user}OTPVerification";
|
||||
var postParams = {"email": _email, "opt": _otp};
|
||||
return await ApiClient().postJsonForObject((json) => GeneralResponseModel.fromJson(json), url, postParams);
|
||||
}
|
||||
|
||||
Future<GeneralResponseModel> updatePassword(String _email, int _otp, String _password) async {
|
||||
String url = "${ApiConsts.user}UpdatePassword";
|
||||
var postParams = {"email": _email, "opt": _otp, "newPassword": _password, "confirmPassword": _password};
|
||||
return await ApiClient().postJsonForObject((json) => GeneralResponseModel.fromJson(json), url, postParams);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
class GeneralResponseModel {
|
||||
int statusCode;
|
||||
String message;
|
||||
Null result;
|
||||
|
||||
GeneralResponseModel({this.statusCode, this.message, this.result});
|
||||
|
||||
GeneralResponseModel.fromJson(Map<String, dynamic> json) {
|
||||
statusCode = json['statusCode'];
|
||||
message = json['message'];
|
||||
result = json['result'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['statusCode'] = this.statusCode;
|
||||
data['message'] = this.message;
|
||||
data['result'] = this.result;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:tangheem/api/user_api_client.dart';
|
||||
import 'package:tangheem/classes/colors.dart';
|
||||
import 'package:tangheem/classes/utils.dart';
|
||||
import 'package:tangheem/widgets/common_textfield_widget.dart';
|
||||
import 'package:tangheem/widgets/otp_widget.dart';
|
||||
|
||||
class ChangePasswordDialog extends StatefulWidget {
|
||||
final Function(String) onPassword;
|
||||
ChangePasswordDialog({Key key, this.onPassword}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ChangePasswordDialogState createState() {
|
||||
return _ChangePasswordDialogState();
|
||||
}
|
||||
}
|
||||
|
||||
class _ChangePasswordDialogState extends State<ChangePasswordDialog> {
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
final TextEditingController _confirmPasswordController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
insetPadding: EdgeInsets.symmetric(horizontal: 60.0, vertical: 24.0),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.transparent,
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorConsts.primaryBlue,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(vertical: 32, horizontal: 16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"تغيير كلمة المرور",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.white, fontSize: 22),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
CommonTextFieldWidget(hint: "الايميل المسجل", controller: _passwordController, prefixIcon: "assets/icons/password.svg"),
|
||||
SizedBox(height: 8),
|
||||
CommonTextFieldWidget(hint: "تأكيد كلمة المرور", controller: _confirmPasswordController, prefixIcon: "assets/icons/password.svg"),
|
||||
SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 40,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (_passwordController.text.length < 1) {
|
||||
Utils.showToast("Password is empty.");
|
||||
return;
|
||||
}
|
||||
if (_confirmPasswordController.text.length < 1) {
|
||||
Utils.showToast("Confirm password is empty.");
|
||||
return;
|
||||
}
|
||||
if (_passwordController.text != _confirmPasswordController.text) {
|
||||
Utils.showToast("Password incorrect");
|
||||
return;
|
||||
}
|
||||
widget.onPassword(_passwordController.text);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
primary: Colors.white,
|
||||
padding: EdgeInsets.all(2),
|
||||
backgroundColor: ColorConsts.secondaryPink,
|
||||
textStyle: TextStyle(fontSize: 14, fontFamily: "DroidKufi"),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6.0),
|
||||
),
|
||||
),
|
||||
child: Text("تحديث"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue