ManageAccountPage #42
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -50,7 +50,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>flutter_assets/kernel_blob.bin</key>
|
<key>flutter_assets/kernel_blob.bin</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -233,11 +233,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
|
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -50,7 +50,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>flutter_assets/kernel_blob.bin</key>
|
<key>flutter_assets/kernel_blob.bin</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -233,11 +233,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
|
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -110,7 +110,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/App</key>
|
<key>Frameworks/App.framework/App</key>
|
||||||
<data>
|
<data>
|
||||||
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
|
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/Info.plist</key>
|
<key>Frameworks/App.framework/Info.plist</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -118,7 +118,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
|
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
|
||||||
<data>
|
<data>
|
||||||
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
|
pP6USMWMbghZPjDH6FAVHt8BAk0=
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -162,7 +162,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
|
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -2366,11 +2366,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
|
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
LjljhR4TWwp5U1vd0v5XKsdz2IeRqWff/Yq/eOS10Do=
|
rkg29yoOxWUVcJyneYU0vcBEmiYn8ahyPsHYChISY7E=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Frameworks/App.framework/Info.plist</key>
|
<key>Frameworks/App.framework/Info.plist</key>
|
||||||
|
@ -2388,11 +2388,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
|
pP6USMWMbghZPjDH6FAVHt8BAk0=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
G/hs7sYm9JJHOze8KiZhJ5XrHfoig2iuJwyK/VZo5Nw=
|
OHnqJaQ8cB0suS70rfyG0W5R8jBfrbhFiX5BN+QypnU=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
||||||
|
@ -2509,11 +2509,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
|
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
|
|
Binary file not shown.
|
@ -50,7 +50,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>flutter_assets/kernel_blob.bin</key>
|
<key>flutter_assets/kernel_blob.bin</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -233,11 +233,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
|
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -110,7 +110,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/App</key>
|
<key>Frameworks/App.framework/App</key>
|
||||||
<data>
|
<data>
|
||||||
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
|
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/Info.plist</key>
|
<key>Frameworks/App.framework/Info.plist</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -118,7 +118,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
|
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
|
||||||
<data>
|
<data>
|
||||||
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
|
pP6USMWMbghZPjDH6FAVHt8BAk0=
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -162,7 +162,7 @@
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
|
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
<data>
|
<data>
|
||||||
|
@ -2366,11 +2366,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
|
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
LjljhR4TWwp5U1vd0v5XKsdz2IeRqWff/Yq/eOS10Do=
|
rkg29yoOxWUVcJyneYU0vcBEmiYn8ahyPsHYChISY7E=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Frameworks/App.framework/Info.plist</key>
|
<key>Frameworks/App.framework/Info.plist</key>
|
||||||
|
@ -2388,11 +2388,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
|
pP6USMWMbghZPjDH6FAVHt8BAk0=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
G/hs7sYm9JJHOze8KiZhJ5XrHfoig2iuJwyK/VZo5Nw=
|
OHnqJaQ8cB0suS70rfyG0W5R8jBfrbhFiX5BN+QypnU=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
|
||||||
|
@ -2509,11 +2509,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>hash</key>
|
<key>hash</key>
|
||||||
<data>
|
<data>
|
||||||
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
|
f44g3XGtbY22u5zIiH+q1OsNXUU=
|
||||||
</data>
|
</data>
|
||||||
<key>hash2</key>
|
<key>hash2</key>
|
||||||
<data>
|
<data>
|
||||||
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
|
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
|
||||||
</data>
|
</data>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
|
||||||
|
|
|
@ -105,7 +105,7 @@ class _HomePageState extends State<HomePage> {
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context, //SignInPage()
|
context, //SignInPage()
|
||||||
MaterialPageRoute(builder: (context) => SignInPage()), //Replace Container() with call to Map-page.
|
MaterialPageRoute(builder: (context) =>SignInPage()), //Replace Container() with call to Map-page.
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Text('Sign in',
|
child: Text('Sign in',
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_applicationdemo/reusables/InputField.dart';
|
import 'package:flutter_applicationdemo/reusables/InputField.dart';
|
||||||
|
|
||||||
import 'package:flutter_applicationdemo/mysql.dart';
|
import 'package:flutter_applicationdemo/mysql.dart';
|
||||||
import 'UpdatePassword.dart';
|
import 'HomePage.dart';
|
||||||
|
|
||||||
class ManageAccountPage extends StatefulWidget {
|
class ManageAccountPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -13,10 +13,11 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
||||||
var db = mysql();
|
var db = mysql();
|
||||||
TextEditingController userNameController = TextEditingController();
|
TextEditingController userNameController = TextEditingController();
|
||||||
TextEditingController emailController = TextEditingController();
|
TextEditingController emailController = TextEditingController();
|
||||||
|
TextEditingController passwordController = TextEditingController();
|
||||||
|
|
||||||
Widget _buildNameFiled() {
|
Widget _buildNameFiled() {
|
||||||
return InputField(
|
return InputField(
|
||||||
text: "UserName",
|
text: "new UserName",
|
||||||
isPassword: false,
|
isPassword: false,
|
||||||
icon: const Icon(Icons.person),
|
icon: const Icon(Icons.person),
|
||||||
controller: userNameController
|
controller: userNameController
|
||||||
|
@ -25,7 +26,7 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
||||||
|
|
||||||
Widget _buildEmailFiled() {
|
Widget _buildEmailFiled() {
|
||||||
return InputField(
|
return InputField(
|
||||||
text: "Email",
|
text: "current Email",
|
||||||
isPassword: false,
|
isPassword: false,
|
||||||
icon: const Icon(Icons.email),
|
icon: const Icon(Icons.email),
|
||||||
controller: emailController
|
controller: emailController
|
||||||
|
@ -33,17 +34,11 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPasswordFiled() {
|
Widget _buildPasswordFiled() {
|
||||||
return ElevatedButton(
|
return InputField(
|
||||||
onPressed: () {
|
text: "new Password",
|
||||||
Navigator.push(
|
isPassword: true,
|
||||||
context,
|
icon: const Icon(Icons.lock),
|
||||||
MaterialPageRoute(builder: (context) => UpdatePassword()), //Replace Container() with call to Map-page.
|
controller: passwordController
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text('Update password'),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
primary: const Color.fromARGB(255, 190, 146, 160)
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +46,7 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('ManageAccountPage'),
|
//title: const Text('ManageAccountPage'),
|
||||||
backgroundColor: const Color.fromARGB(255, 190, 146, 160),
|
backgroundColor: const Color.fromARGB(255, 190, 146, 160),
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Container(
|
||||||
|
@ -60,19 +55,21 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const Text('Change user data' ,style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25)),
|
const Text('Update user data' ,style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25)),
|
||||||
const SizedBox(height: 50),
|
const SizedBox(height: 50),
|
||||||
_buildNameFiled(),
|
|
||||||
_buildEmailFiled(),
|
_buildEmailFiled(),
|
||||||
|
_buildNameFiled(),
|
||||||
_buildPasswordFiled(),
|
_buildPasswordFiled(),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
UserInput userInput = UserInput(isValid: false, errorMessage: "");
|
UserInput userInput = UserInput(isValid: false, errorMessage: "");
|
||||||
await verifyUserInput(userNameController.text, emailController.text, userInput);
|
await verifyUserInput(userNameController.text, emailController.text,passwordController.text, userInput);
|
||||||
if(userInput.isValid) {
|
if(userInput.isValid) {
|
||||||
//update user data...
|
await updateUserInSQL(emailController.text, userNameController.text, passwordController.text);
|
||||||
print(userNameController.text);
|
Navigator.push(
|
||||||
print(emailController.text);
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => HomePage()),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
createUserError(userInput.errorMessage);
|
createUserError(userInput.errorMessage);
|
||||||
}
|
}
|
||||||
|
@ -89,17 +86,35 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyUserInput(String userName, String email,userInput) {
|
Future<void> verifyUserInput(String userName, String email , String password,userInput) async {
|
||||||
if (email!= '' && (email.contains("'") || !email.contains("@") || email.length < 5)) {
|
var result = false;
|
||||||
|
await db.getConnection().then((conn) async {
|
||||||
|
String sql = "SELECT email from maen0574.user where email = '$email';";
|
||||||
|
var results = await conn.query(sql);
|
||||||
|
|
||||||
|
if(results.toString() == "()") {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result == true) {
|
||||||
|
userInput.errorMessage = "email incorrect!";
|
||||||
|
return;
|
||||||
|
} else if (email.contains("'") || !email.contains("@") || email.length < 5) {
|
||||||
userInput.errorMessage = "Incorrect email format";
|
userInput.errorMessage = "Incorrect email format";
|
||||||
return;
|
return;
|
||||||
} else if (userName != '' && (userName.contains("'") || userName.length < 6)) {
|
} else if (userName.contains("'") || userName.length < 6) {
|
||||||
userInput.errorMessage =
|
userInput.errorMessage =
|
||||||
"Incorrect username. \nCharacters limited to a-z, A-Z, 0-9.";
|
"Incorrect username. \nCharacters limited to a-z, A-Z, 0-9.";
|
||||||
return;
|
return;
|
||||||
} else {
|
} else if (password.contains("'") || password.length < 6) {
|
||||||
|
userInput.errorMessage =
|
||||||
|
"Incorrect password. \nPassword can't contain ' and needs to be atleast 6 characters long";
|
||||||
|
return;
|
||||||
|
}else {
|
||||||
userInput.isValid = true;
|
userInput.isValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void createUserError(String stringContext) {
|
void createUserError(String stringContext) {
|
||||||
|
@ -118,11 +133,11 @@ void createUserError(String stringContext) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateUserInSQL(String email, String username) async {
|
Future<void> updateUserInSQL(String email, String username, String password) async {
|
||||||
await db.getConnection().then((conn) async {
|
await db.getConnection().then((conn) async {
|
||||||
|
String sql = "UPDATE maen0574.user set password = '$password', username = '$username' where email = '$email';";
|
||||||
|
await conn.query(sql);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,125 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_applicationdemo/Form.dart';
|
|
||||||
import 'package:flutter_applicationdemo/reusables/InputField.dart';
|
|
||||||
import 'package:flutter_applicationdemo/mysql.dart';
|
|
||||||
import 'package:flutter_applicationdemo/login/User.dart';
|
|
||||||
|
|
||||||
class UpdatePassword extends StatefulWidget {
|
|
||||||
@override
|
|
||||||
State<UpdatePassword> createState() => UpdatePasswordState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class UpdatePasswordState extends State<UpdatePassword> {
|
|
||||||
var db = mysql();
|
|
||||||
TextEditingController passwordController = TextEditingController();
|
|
||||||
TextEditingController currentPasswordController = TextEditingController();
|
|
||||||
|
|
||||||
Widget _currentPasswordFiled() {
|
|
||||||
return InputField(
|
|
||||||
text: "Current Password",
|
|
||||||
isPassword: true,
|
|
||||||
icon: const Icon(Icons.lock),
|
|
||||||
controller: currentPasswordController
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildPasswordFiled() {
|
|
||||||
return InputField(
|
|
||||||
text: "new Password",
|
|
||||||
isPassword: true,
|
|
||||||
icon: const Icon(Icons.lock),
|
|
||||||
controller: passwordController
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('Update Password'),
|
|
||||||
backgroundColor: const Color.fromARGB(255, 190, 146, 160),
|
|
||||||
),
|
|
||||||
body: Container(
|
|
||||||
margin: EdgeInsets.all(24),
|
|
||||||
child: Form(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
_currentPasswordFiled(),
|
|
||||||
_buildPasswordFiled(),
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () async {
|
|
||||||
UserInput userInput = UserInput(isValid: false, errorMessage: "");
|
|
||||||
await verifyUserInput(currentPasswordController.text, passwordController.text, userInput);
|
|
||||||
if(userInput.isValid) {
|
|
||||||
//update user data...
|
|
||||||
print(currentPasswordController.text);
|
|
||||||
print(passwordController.text);
|
|
||||||
} else {
|
|
||||||
createUserError(userInput.errorMessage);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: const Text('Update'),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
primary: const Color.fromARGB(255, 190, 146, 160)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> verifyUserInput(String currentPassword, String newPassword, userInput) async {
|
|
||||||
userInput.isValid = false;
|
|
||||||
await db.getConnection().then((conn) async {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
if (newPassword.contains("'") || newPassword.length < 6) {
|
|
||||||
userInput.errorMessage =
|
|
||||||
"Incorrect password. \nPassword can't contain ' and needs to be atleast 6 characters long";
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
userInput.isValid = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> updateUserInSQL(String password) async {
|
|
||||||
await db.getConnection().then((conn) async {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void createUserError(String stringContext) {
|
|
||||||
showDialog<String>(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) => AlertDialog(
|
|
||||||
title: const Text("Couldn't update user data"),
|
|
||||||
content: Text(stringContext),
|
|
||||||
actions: <Widget>[
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context, 'OK'),
|
|
||||||
child: const Text('OK'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class UserInput {
|
|
||||||
bool isValid;
|
|
||||||
String errorMessage;
|
|
||||||
UserInput({required this.isValid, required this.errorMessage});
|
|
||||||
bool getIsValid() {
|
|
||||||
return isValid;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user