|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:teso/Pages/PageWidgets/Login/passwordAlter.dart';
|
|
|
|
import 'package:teso/Pages/Sub_Pages/LandingPage/ResetPassword.dart';
|
|
|
|
import 'package:teso/util/consts.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:teso/providers/pageAnimations.dart';
|
|
|
|
import 'newPassword.dart';
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
class ChangePassword extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_ChangePasswordState createState() => _ChangePasswordState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ChangePasswordState extends State<ChangePassword> {
|
|
|
|
TextEditingController oldPassword = new TextEditingController();
|
|
|
|
bool verifyiing = false;
|
|
|
|
bool incorrentpassword = false;
|
|
|
|
|
|
|
|
verify(context) async {
|
|
|
|
setState(() {
|
|
|
|
verifyiing = true;
|
|
|
|
incorrentpassword = false;
|
|
|
|
});
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
Map<String, String> requestHeaders = {
|
|
|
|
'Content-type': 'application/json',
|
|
|
|
'Authorization': prefs.getString('tokensTeso')!
|
|
|
|
};
|
|
|
|
|
|
|
|
var register2 = serverLocation + 'users/verifypassword';
|
|
|
|
var client1 = await http.post(Uri.parse(register2),
|
|
|
|
body: json.encode(oldPassword.text), headers: requestHeaders);
|
|
|
|
|
|
|
|
if (client1.statusCode == 200) {
|
|
|
|
setState(() {
|
|
|
|
verifyiing = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
switch (client1.body) {
|
|
|
|
case "matched":
|
|
|
|
Navigator.pushReplacement(
|
|
|
|
context,
|
|
|
|
PageTransition(
|
|
|
|
type: PageTransitionType.rightToLeft,
|
|
|
|
child: CreateNewPassword(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "mismatched":
|
|
|
|
setState(() {
|
|
|
|
incorrentpassword = true;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tesoDialog(context, client1.body);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void error(context) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext bc) {
|
|
|
|
return AlertDialog(
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text('OK'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
//title: Text("Alert Dialog"),
|
|
|
|
content: Text(
|
|
|
|
"Sorry an error occurred please try again!",
|
|
|
|
style: TextStyle(color: Colors.redAccent[100]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void tesoDialog(context, value) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext bc) {
|
|
|
|
return AlertDialog(
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text('OK'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
//title: Text("Alert Dialog"),
|
|
|
|
content: Text(
|
|
|
|
"Sorry you cannot change for password since you are logged in with your " +
|
|
|
|
value +
|
|
|
|
" account, please change your password on the " +
|
|
|
|
value +
|
|
|
|
" platform",
|
|
|
|
style: TextStyle(color: Colors.redAccent[100]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text("Change Password"),
|
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.close),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
new Container(
|
|
|
|
margin: EdgeInsets.symmetric(vertical: 0.0, horizontal: 20),
|
|
|
|
child: new Center(
|
|
|
|
child: IconButton(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
icon: Icon(Icons.check),
|
|
|
|
onPressed: () => verify(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
height: MediaQuery.of(context).size.height,
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 10.0,
|
|
|
|
),
|
|
|
|
Center(
|
|
|
|
child: changePassword(context, "Current Password", oldPassword),
|
|
|
|
),
|
|
|
|
Visibility(
|
|
|
|
visible: incorrentpassword,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
'The password you entered does not match your current password, if you forgot your current password click on forgot password to continue!!',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.red,
|
|
|
|
// fontWeight: FontWeight.bold,
|
|
|
|
fontFamily: 'OpenSans',
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () => showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => ResetPassword(),
|
|
|
|
),
|
|
|
|
//padding: EdgeInsets.only(left: 20.0),
|
|
|
|
child: Text(
|
|
|
|
'Forgot Password?',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black87,
|
|
|
|
// fontWeight: FontWeight.bold,
|
|
|
|
fontFamily: 'OpenSans',
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Visibility(
|
|
|
|
visible: verifyiing,
|
|
|
|
child: Center(
|
|
|
|
child: CupertinoActivityIndicator(
|
|
|
|
animating: true,
|
|
|
|
radius: 15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|