LoginPage #60

Merged
maen0574 merged 6 commits from LoginPage into master 2022-06-01 22:50:13 +02:00
8 changed files with 92 additions and 82 deletions
Showing only changes of commit 1e74a80ae1 - Show all commits

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_applicationdemo/BottomNavPage.dart';
import 'package:flutter_applicationdemo/login/EncryptData.dart'; import 'package:flutter_applicationdemo/login/EncryptData.dart';
import 'package:flutter_applicationdemo/reusables/InputField.dart'; import 'package:flutter_applicationdemo/reusables/InputField.dart';
import 'package:flutter_applicationdemo/globals.dart' as globals;
import 'package:flutter_applicationdemo/mysql.dart'; import 'package:flutter_applicationdemo/mysql.dart';
import 'HomePage.dart'; import 'HomePage.dart';
@ -12,37 +13,28 @@ class ManageAccountPage extends StatefulWidget {
class ManageAccountPageState extends State<ManageAccountPage> { class ManageAccountPageState extends State<ManageAccountPage> {
var db = mysql(); var db = mysql();
TextEditingController userNameController = TextEditingController(); TextEditingController previousPasswordController = TextEditingController();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController(); TextEditingController passwordController = TextEditingController();
TextEditingController confirmPasswordController = TextEditingController();
UserInput userInput = UserInput(isValid: false, errorMessage: ""); UserInput userInput = UserInput(isValid: false, errorMessage: "");
Widget _buildNameFiled() { Widget _buildPasswordFiled(TextEditingController controller) {
return InputField( return InputField(
text: "new UserName", text: "New password",
isPassword: false,
icon: const Icon(Icons.person),
controller: userNameController
);
}
Widget _buildEmailFiled() {
return InputField(
text: "current Email",
isPassword: false,
icon: const Icon(Icons.email),
controller: emailController
);
}
Widget _buildPasswordFiled() {
return InputField(
text: "new Password",
isPassword: true, isPassword: true,
icon: const Icon(Icons.lock), icon: const Icon(Icons.lock),
controller: passwordController controller: controller
); );
} }
Widget _buildOldPasswordFiled() {
return InputField(
text: "Previous password",
isPassword: true,
icon: const Icon(Icons.lock),
controller: previousPasswordController
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -59,23 +51,23 @@ class ManageAccountPageState extends State<ManageAccountPage> {
children: <Widget>[ children: <Widget>[
const Text('Update 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),
_buildEmailFiled(), _buildOldPasswordFiled(),
_buildNameFiled(), _buildPasswordFiled(passwordController),
_buildPasswordFiled(), _buildPasswordFiled(confirmPasswordController),
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: () async {
await verifyUserInput(userNameController.text, emailController.text,passwordController.text, userInput); await verifyUserInput(previousPasswordController.text, passwordController.text, confirmPasswordController.text);
if(userInput.isValid) { if(userInput.isValid) {
await updateUserInSQL(emailController.text, userNameController.text, passwordController.text); await updateUserInSQL(previousPasswordController.text, confirmPasswordController.text);
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => HomePage()), MaterialPageRoute(builder: (context) => BottomNavPage()),
); );
} else { } else {
createUserError(userInput.errorMessage); createUserError(userInput.errorMessage);
} }
}, },
child: const Text('Update'), child: const Text('Change password'),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 190, 146, 160) primary: const Color.fromARGB(255, 190, 146, 160)
), ),
@ -87,55 +79,34 @@ class ManageAccountPageState extends State<ManageAccountPage> {
); );
} }
Future<void> verifyUserInput(String userName, String email , String password,userInput) async { Future<void> verifyUserInput(String previous, String newPassword , String confirmedPassword) async {
var result = false; String result = userInputResult(previous, newPassword, confirmedPassword);
await db.getConnection().then((conn) async { if(result.isNotEmpty){
String sql = "SELECT email from maen0574.user where email = '$email';"; userInput = UserInput(isValid: false, errorMessage: result);
var results = await conn.query(sql);
if(results.toString() == "()") {
result = true;
}
});
if (result == true) {
userInput.errorMessage = "email incorrect!";
return; return;
} else if (email.contains("'") || !email.contains("@") || email.length < 5) { }else{
userInput.errorMessage = "Incorrect email format"; userInput = UserInput(isValid: true, errorMessage: "");
return;
} else if (userName.contains("'") || userName.length < 6) {
userInput.errorMessage =
"Incorrect username. \nCharacters limited to a-z, A-Z, 0-9.";
return;
} 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;
} }
} }
String userInputResult(String userName, String email , String password) { String userInputResult(String previousPassword, String newPassword, String confirmedPassword) {
String message = userInput.errorMessage; String message = userInput.errorMessage;
if (email.contains("'") || !email.contains("@") || email.length < 5) { if (previousPassword.contains("'") ){
message = "Incorrect email format"; message = "Incorrect previous password";
return message; return message;
} else if (userName.contains("'") || userName.length < 6) { } else if (newPassword.contains("'") || newPassword.length < 6) {
message = message =
"Incorrect username. \nCharacters limited to a-z, A-Z, 0-9."; "Incorrect new password. \nCharacters limited to a-z, A-Z, 0-9 and needs to be atleast 6 characters long";
return message; return message;
} else if (password.contains("'") || password.length < 6) { } else if (confirmedPassword.contains("'") || confirmedPassword.length < 6) {
message = message =
"Incorrect password. \nPassword can't contain ' and needs to be atleast 6 characters long"; "Incorrect confirmed password. \nPassword can't contain ' and needs to be atleast 6 characters long";
return message; return message;
} else { } else {
return ""; return "";
} }
} }
@ -155,12 +126,29 @@ void createUserError(String stringContext) {
); );
} }
Future<void> updateUserInSQL(String email, String username, String password) async { Future<void> updateUserInSQL(String previousPassword, String newPassword) async {
password = EncryptData.encryptAES(password); previousPassword = EncryptData.encryptAES(previousPassword);
newPassword = EncryptData.encryptAES(newPassword);
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';"; String sql =
await conn.query(sql); "Select id from maen0574.user where id = ${globals.LOGGED_IN_USER.userID} and password = '$previousPassword'";
userInput = UserInput(isValid: false, errorMessage: "Incorrect previous password");
await conn.query(sql).then((results) {
for (var row in results) {
setState(() {});
userInput = UserInput(isValid: true, errorMessage: "");
}
}); });
});
if(!userInput.isValid){
createUserError(userInput.errorMessage);
return;
}
await db.getConnection().then((conn) async {
String sql =
"UPDATE maen0574.user SET password = $newPassword WHERE id = ${globals.LOGGED_IN_USER.userID}";
conn.query(sql);
});
} }
} }

View File

@ -389,6 +389,7 @@ class MapState extends State<Map> {
void addMarkersInRange() { void addMarkersInRange() {
for(int i = 0; i< globals.VENUES.length; i++){ for(int i = 0; i< globals.VENUES.length; i++){
print(globals.VENUES[i].venueName + " " + globals.VENUES[i].venueID.toString());
if(!globals.VENUES[i].isShownOnMap && (globals.VENUES[i].position.longitude - _currentCameraPosition.target.longitude < 0.02 && globals.VENUES[i].position.latitude - _currentCameraPosition.target.latitude < 0.02)){ if(!globals.VENUES[i].isShownOnMap && (globals.VENUES[i].position.longitude - _currentCameraPosition.target.longitude < 0.02 && globals.VENUES[i].position.latitude - _currentCameraPosition.target.latitude < 0.02)){
Marker marker = Marker( Marker marker = Marker(
markerId: MarkerId(globals.VENUES[i].venueID.toString()), markerId: MarkerId(globals.VENUES[i].venueID.toString()),

View File

@ -272,7 +272,7 @@ class _SettingsPageState extends State<SettingsPage> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => BottomNavPage()), builder: (context) => ManageAccountPage()),
); );
}, },
child: Container( child: Container(
@ -282,7 +282,7 @@ class _SettingsPageState extends State<SettingsPage> {
width: 175, width: 175,
child: const Center( child: const Center(
child: Text( child: Text(
'Manage account', 'Change password',
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
fontWeight: FontWeight. bold, fontWeight: FontWeight. bold,

View File

@ -2,6 +2,9 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_applicationdemo/ShadowDetector.dart'; import 'package:flutter_applicationdemo/ShadowDetector.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_applicationdemo/globals.dart' as globals;
import 'mysql.dart';
class Venue { class Venue {
int venueID; int venueID;
@ -104,6 +107,25 @@ class Venue {
'coordinates: ' + 'coordinates: ' +
position.toString(); position.toString();
} }
void likeVenue() {
globals.LOGGED_IN_USER.likedVenuesList.add(this);
var db = mysql();
db.getConnection().then((conn) {
String sql =
"INSERT INTO maen0574.userFavorites (user_id, venue_id) VALUES (${globals.LOGGED_IN_USER.userID}, $venueID);";
conn.query(sql);
});
}
void unlikeVenue(){
globals.LOGGED_IN_USER.likedVenuesList.remove(this);
var db = mysql();
db.getConnection().then((conn) {
String sql =
"DELETE FROM maen0574.userFavorites WHERE user_id = '${globals.LOGGED_IN_USER.userID}' and venue_id = $venueID;";
conn.query(sql);
});
}
} }
class OutdoorSeatingArea { class OutdoorSeatingArea {

View File

@ -140,7 +140,6 @@ class _CreateAccountPageState extends State<CreateAccountPage> {
String sql = String sql =
"INSERT INTO maen0574.user (id, email, password, username) VALUES (null, '$email', '$password', '$username');"; "INSERT INTO maen0574.user (id, email, password, username) VALUES (null, '$email', '$password', '$username');";
await conn.query(sql); await conn.query(sql);
sql = sql =
"Select id, email, username from maen0574.user where email = '$email'"; "Select id, email, username from maen0574.user where email = '$email'";
await conn.query(sql).then((results) { await conn.query(sql).then((results) {

View File

@ -24,8 +24,8 @@ import 'globals.dart' as globals;
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(); await Firebase.initializeApp();
await loadAllVenues(); //await loadAllVenues();
await fetchWeather(); //await fetchWeather();
await loadAllVenuesSQL(); await loadAllVenuesSQL();
runApp(MyApp()); runApp(MyApp());
@ -77,7 +77,7 @@ Future loadAllVenues() async {
// var sd = ShadowDetector(); // var sd = ShadowDetector();
// await sd.evaluateShadowsForAllVenues(seventyFiveVenues); // await sd.evaluateShadowsForAllVenues(seventyFiveVenues);
} else { } else {
throw const HttpException("Problem fetching the venue data"); //throw const HttpException("Problem fetching the venue data");
} }
} }

View File

@ -143,7 +143,7 @@ class _VenuePageState extends State<VenuePage> {
return Column( return Column(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.all(4.0), padding: EdgeInsets.all(4.0),
child: child:
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
Column( Column(
@ -193,7 +193,7 @@ class _AboutTheSpotTableState extends State<AboutTheSpotTable> {
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
)))), )))),
const DataColumn(label: Text('', style: TextStyle())), DataColumn(label: Text('', style: TextStyle())),
], ],
rows: [ rows: [
DataRow(cells: [ DataRow(cells: [
@ -245,7 +245,7 @@ class LikeVenueButton extends StatelessWidget {
return alreadyLiked? Expanded( return alreadyLiked? Expanded(
child: TextButton.icon( child: TextButton.icon(
onPressed: () { onPressed: () {
globals.LOGGED_IN_USER.likedVenuesList.remove(venue); venue.unlikeVenue();
(context as Element).reassemble(); (context as Element).reassemble();
}, },
icon: const Icon( icon: const Icon(
@ -260,7 +260,7 @@ class LikeVenueButton extends StatelessWidget {
) : globals.LOGGED_IN_USER.userID != 0 ? Expanded( ) : globals.LOGGED_IN_USER.userID != 0 ? Expanded(
child: TextButton.icon( child: TextButton.icon(
onPressed: () { onPressed: () {
globals.LOGGED_IN_USER.likedVenuesList.add(venue); venue.likeVenue();
(context as Element).reassemble(); (context as Element).reassemble();
}, },
icon: const Icon( icon: const Icon(