ManageAccountPage #42

Merged
maze6343 merged 20 commits from ManageAccountPage into master 2022-05-25 22:16:46 +02:00
17 changed files with 73 additions and 183 deletions
Showing only changes of commit b5de86173e - Show all commits

File diff suppressed because one or more lines are too long

View File

@ -50,7 +50,7 @@
</data>
<key>flutter_assets/kernel_blob.bin</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
@ -233,11 +233,11 @@
<dict>
<key>hash</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>hash2</key>
<data>
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
</data>
</dict>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>

View File

@ -50,7 +50,7 @@
</data>
<key>flutter_assets/kernel_blob.bin</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
@ -233,11 +233,11 @@
<dict>
<key>hash</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>hash2</key>
<data>
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
</data>
</dict>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>

View File

@ -110,7 +110,7 @@
</data>
<key>Frameworks/App.framework/App</key>
<data>
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
</data>
<key>Frameworks/App.framework/Info.plist</key>
<data>
@ -118,7 +118,7 @@
</data>
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
<data>
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
pP6USMWMbghZPjDH6FAVHt8BAk0=
</data>
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
<data>
@ -162,7 +162,7 @@
</data>
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
@ -2366,11 +2366,11 @@
<dict>
<key>hash</key>
<data>
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
</data>
<key>hash2</key>
<data>
LjljhR4TWwp5U1vd0v5XKsdz2IeRqWff/Yq/eOS10Do=
rkg29yoOxWUVcJyneYU0vcBEmiYn8ahyPsHYChISY7E=
</data>
</dict>
<key>Frameworks/App.framework/Info.plist</key>
@ -2388,11 +2388,11 @@
<dict>
<key>hash</key>
<data>
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
pP6USMWMbghZPjDH6FAVHt8BAk0=
</data>
<key>hash2</key>
<data>
G/hs7sYm9JJHOze8KiZhJ5XrHfoig2iuJwyK/VZo5Nw=
OHnqJaQ8cB0suS70rfyG0W5R8jBfrbhFiX5BN+QypnU=
</data>
</dict>
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
@ -2509,11 +2509,11 @@
<dict>
<key>hash</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>hash2</key>
<data>
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
</data>
</dict>
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>

View File

@ -50,7 +50,7 @@
</data>
<key>flutter_assets/kernel_blob.bin</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
@ -233,11 +233,11 @@
<dict>
<key>hash</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>hash2</key>
<data>
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
</data>
</dict>
<key>flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>

View File

@ -110,7 +110,7 @@
</data>
<key>Frameworks/App.framework/App</key>
<data>
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
</data>
<key>Frameworks/App.framework/Info.plist</key>
<data>
@ -118,7 +118,7 @@
</data>
<key>Frameworks/App.framework/_CodeSignature/CodeResources</key>
<data>
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
pP6USMWMbghZPjDH6FAVHt8BAk0=
</data>
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
<data>
@ -162,7 +162,7 @@
</data>
<key>Frameworks/App.framework/flutter_assets/kernel_blob.bin</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>
<data>
@ -2366,11 +2366,11 @@
<dict>
<key>hash</key>
<data>
Hrp+3lXoQX1UhHY5S3K1iH4t5ZM=
GQu8ce+/d5wb1mB5tbDmVH3X9ng=
</data>
<key>hash2</key>
<data>
LjljhR4TWwp5U1vd0v5XKsdz2IeRqWff/Yq/eOS10Do=
rkg29yoOxWUVcJyneYU0vcBEmiYn8ahyPsHYChISY7E=
</data>
</dict>
<key>Frameworks/App.framework/Info.plist</key>
@ -2388,11 +2388,11 @@
<dict>
<key>hash</key>
<data>
I2RvlTXB8M/P/E1q0Iok/w4FEvI=
pP6USMWMbghZPjDH6FAVHt8BAk0=
</data>
<key>hash2</key>
<data>
G/hs7sYm9JJHOze8KiZhJ5XrHfoig2iuJwyK/VZo5Nw=
OHnqJaQ8cB0suS70rfyG0W5R8jBfrbhFiX5BN+QypnU=
</data>
</dict>
<key>Frameworks/App.framework/flutter_assets/AssetManifest.json</key>
@ -2509,11 +2509,11 @@
<dict>
<key>hash</key>
<data>
GJLNBMtVbFJeMdRS4+gMkd2BPpI=
f44g3XGtbY22u5zIiH+q1OsNXUU=
</data>
<key>hash2</key>
<data>
hsYA3eg+UkH1zL2HkZqKO81oZ3m4AtLyawDShJxds0A=
1VR65Dn8a70tzXX3exRysSkAwaSnyv424i77ROPZlJo=
</data>
</dict>
<key>Frameworks/App.framework/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf</key>

View File

@ -105,7 +105,7 @@ class _HomePageState extends State<HomePage> {
onPressed: () {
Navigator.push(
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',

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_applicationdemo/reusables/InputField.dart';
import 'package:flutter_applicationdemo/mysql.dart';
import 'UpdatePassword.dart';
import 'HomePage.dart';
class ManageAccountPage extends StatefulWidget {
@override
@ -13,10 +13,11 @@ class ManageAccountPageState extends State<ManageAccountPage> {
var db = mysql();
TextEditingController userNameController = TextEditingController();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
Widget _buildNameFiled() {
return InputField(
text: "UserName",
text: "new UserName",
isPassword: false,
icon: const Icon(Icons.person),
controller: userNameController
@ -25,7 +26,7 @@ class ManageAccountPageState extends State<ManageAccountPage> {
Widget _buildEmailFiled() {
return InputField(
text: "Email",
text: "current Email",
isPassword: false,
icon: const Icon(Icons.email),
controller: emailController
@ -33,17 +34,11 @@ class ManageAccountPageState extends State<ManageAccountPage> {
}
Widget _buildPasswordFiled() {
return ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => UpdatePassword()), //Replace Container() with call to Map-page.
);
},
child: const Text('Update password'),
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 190, 146, 160)
),
return InputField(
text: "new Password",
isPassword: true,
icon: const Icon(Icons.lock),
controller: passwordController
);
}
@ -51,7 +46,7 @@ class ManageAccountPageState extends State<ManageAccountPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ManageAccountPage'),
//title: const Text('ManageAccountPage'),
backgroundColor: const Color.fromARGB(255, 190, 146, 160),
),
body: Container(
@ -60,19 +55,21 @@ class ManageAccountPageState extends State<ManageAccountPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
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),
_buildNameFiled(),
_buildEmailFiled(),
_buildNameFiled(),
_buildPasswordFiled(),
ElevatedButton(
onPressed: () async {
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) {
//update user data...
print(userNameController.text);
print(emailController.text);
await updateUserInSQL(emailController.text, userNameController.text, passwordController.text);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
} else {
createUserError(userInput.errorMessage);
}
@ -89,17 +86,35 @@ class ManageAccountPageState extends State<ManageAccountPage> {
);
}
verifyUserInput(String userName, String email,userInput) {
if (email!= '' && (email.contains("'") || !email.contains("@") || email.length < 5)) {
Future<void> verifyUserInput(String userName, String email , String password,userInput) async {
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";
return;
} else if (userName != '' && (userName.contains("'") || userName.length < 6)) {
} else if (userName.contains("'") || userName.length < 6) {
userInput.errorMessage =
"Incorrect username. \nCharacters limited to a-z, A-Z, 0-9.";
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;
}
}
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 {
});
String sql = "UPDATE maen0574.user set password = '$password', username = '$username' where email = '$email';";
await conn.query(sql);
});
}
}

View File

@ -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;
}
}