LoginPage #60
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
||||
import 'package:flutter_applicationdemo/login/EncryptData.dart';
|
||||
import 'package:flutter_applicationdemo/reusables/InputField.dart';
|
||||
|
||||
import 'package:flutter_applicationdemo/globals.dart' as globals;
|
||||
import 'package:flutter_applicationdemo/mysql.dart';
|
||||
import 'HomePage.dart';
|
||||
|
||||
|
@ -12,35 +13,26 @@ class ManageAccountPage extends StatefulWidget {
|
|||
|
||||
class ManageAccountPageState extends State<ManageAccountPage> {
|
||||
var db = mysql();
|
||||
TextEditingController userNameController = TextEditingController();
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController previousPasswordController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
TextEditingController confirmPasswordController = TextEditingController();
|
||||
|
||||
UserInput userInput = UserInput(isValid: false, errorMessage: "");
|
||||
|
||||
Widget _buildNameFiled() {
|
||||
Widget _buildPasswordFiled(TextEditingController controller) {
|
||||
return InputField(
|
||||
text: "new UserName",
|
||||
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",
|
||||
text: "New password",
|
||||
isPassword: true,
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -59,23 +51,23 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
|||
children: <Widget>[
|
||||
const Text('Update user data' ,style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25)),
|
||||
const SizedBox(height: 50),
|
||||
_buildEmailFiled(),
|
||||
_buildNameFiled(),
|
||||
_buildPasswordFiled(),
|
||||
_buildOldPasswordFiled(),
|
||||
_buildPasswordFiled(passwordController),
|
||||
_buildPasswordFiled(confirmPasswordController),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await verifyUserInput(userNameController.text, emailController.text,passwordController.text, userInput);
|
||||
await verifyUserInput(previousPasswordController.text, passwordController.text, confirmPasswordController.text);
|
||||
if(userInput.isValid) {
|
||||
await updateUserInSQL(emailController.text, userNameController.text, passwordController.text);
|
||||
await updateUserInSQL(previousPasswordController.text, confirmPasswordController.text);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
MaterialPageRoute(builder: (context) => BottomNavPage()),
|
||||
);
|
||||
} else {
|
||||
createUserError(userInput.errorMessage);
|
||||
}
|
||||
},
|
||||
child: const Text('Update'),
|
||||
child: const Text('Change password'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: const Color.fromARGB(255, 190, 146, 160)
|
||||
),
|
||||
|
@ -87,51 +79,30 @@ class ManageAccountPageState extends State<ManageAccountPage> {
|
|||
);
|
||||
}
|
||||
|
||||
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;
|
||||
Future<void> verifyUserInput(String previous, String newPassword , String confirmedPassword) async {
|
||||
String result = userInputResult(previous, newPassword, confirmedPassword);
|
||||
if(result.isNotEmpty){
|
||||
userInput = UserInput(isValid: false, errorMessage: result);
|
||||
return;
|
||||
}else{
|
||||
userInput = UserInput(isValid: true, errorMessage: "");
|
||||
}
|
||||
});
|
||||
|
||||
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.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;
|
||||
|
||||
if (email.contains("'") || !email.contains("@") || email.length < 5) {
|
||||
message = "Incorrect email format";
|
||||
if (previousPassword.contains("'") ){
|
||||
message = "Incorrect previous password";
|
||||
return message;
|
||||
} else if (userName.contains("'") || userName.length < 6) {
|
||||
} else if (newPassword.contains("'") || newPassword.length < 6) {
|
||||
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;
|
||||
} else if (password.contains("'") || password.length < 6) {
|
||||
} else if (confirmedPassword.contains("'") || confirmedPassword.length < 6) {
|
||||
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;
|
||||
} else {
|
||||
return "";
|
||||
|
@ -155,11 +126,28 @@ void createUserError(String stringContext) {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> updateUserInSQL(String email, String username, String password) async {
|
||||
password = EncryptData.encryptAES(password);
|
||||
Future<void> updateUserInSQL(String previousPassword, String newPassword) async {
|
||||
previousPassword = EncryptData.encryptAES(previousPassword);
|
||||
newPassword = EncryptData.encryptAES(newPassword);
|
||||
await db.getConnection().then((conn) async {
|
||||
String sql = "UPDATE maen0574.user set password = '$password', username = '$username' where email = '$email';";
|
||||
await conn.query(sql);
|
||||
String 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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -389,6 +389,7 @@ class MapState extends State<Map> {
|
|||
|
||||
void addMarkersInRange() {
|
||||
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)){
|
||||
Marker marker = Marker(
|
||||
markerId: MarkerId(globals.VENUES[i].venueID.toString()),
|
||||
|
|
|
@ -272,7 +272,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BottomNavPage()),
|
||||
builder: (context) => ManageAccountPage()),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
|
@ -282,7 +282,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||
width: 175,
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'Manage account',
|
||||
'Change password',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight. bold,
|
||||
|
|
|
@ -2,6 +2,9 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/ShadowDetector.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:flutter_applicationdemo/globals.dart' as globals;
|
||||
|
||||
import 'mysql.dart';
|
||||
|
||||
class Venue {
|
||||
int venueID;
|
||||
|
@ -104,6 +107,25 @@ class Venue {
|
|||
'coordinates: ' +
|
||||
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 {
|
||||
|
|
|
@ -140,7 +140,6 @@ class _CreateAccountPageState extends State<CreateAccountPage> {
|
|||
String sql =
|
||||
"INSERT INTO maen0574.user (id, email, password, username) VALUES (null, '$email', '$password', '$username');";
|
||||
await conn.query(sql);
|
||||
|
||||
sql =
|
||||
"Select id, email, username from maen0574.user where email = '$email'";
|
||||
await conn.query(sql).then((results) {
|
||||
|
|
|
@ -24,8 +24,8 @@ import 'globals.dart' as globals;
|
|||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
await loadAllVenues();
|
||||
await fetchWeather();
|
||||
//await loadAllVenues();
|
||||
//await fetchWeather();
|
||||
await loadAllVenuesSQL();
|
||||
|
||||
runApp(MyApp());
|
||||
|
@ -77,7 +77,7 @@ Future loadAllVenues() async {
|
|||
// var sd = ShadowDetector();
|
||||
// await sd.evaluateShadowsForAllVenues(seventyFiveVenues);
|
||||
} else {
|
||||
throw const HttpException("Problem fetching the venue data");
|
||||
//throw const HttpException("Problem fetching the venue data");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ class _VenuePageState extends State<VenuePage> {
|
|||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
padding: EdgeInsets.all(4.0),
|
||||
child:
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
|
||||
Column(
|
||||
|
@ -193,7 +193,7 @@ class _AboutTheSpotTableState extends State<AboutTheSpotTable> {
|
|||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
)))),
|
||||
const DataColumn(label: Text('', style: TextStyle())),
|
||||
DataColumn(label: Text('', style: TextStyle())),
|
||||
],
|
||||
rows: [
|
||||
DataRow(cells: [
|
||||
|
@ -245,7 +245,7 @@ class LikeVenueButton extends StatelessWidget {
|
|||
return alreadyLiked? Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
globals.LOGGED_IN_USER.likedVenuesList.remove(venue);
|
||||
venue.unlikeVenue();
|
||||
(context as Element).reassemble();
|
||||
},
|
||||
icon: const Icon(
|
||||
|
@ -260,7 +260,7 @@ class LikeVenueButton extends StatelessWidget {
|
|||
) : globals.LOGGED_IN_USER.userID != 0 ? Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
globals.LOGGED_IN_USER.likedVenuesList.add(venue);
|
||||
venue.likeVenue();
|
||||
(context as Element).reassemble();
|
||||
},
|
||||
icon: const Icon(
|
||||
|
|
Loading…
Reference in New Issue
Block a user