shas6395 #24
|
@ -1,292 +0,0 @@
|
|||
// ignore_for_file: prefer_const_constructors
|
||||
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
||||
import 'package:flutter_applicationdemo/GoogleSignInProvider.dart';
|
||||
import 'package:flutter_applicationdemo/mysql.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:flutter_applicationdemo/HomePage.dart';
|
||||
import 'package:flutter_signin_button/flutter_signin_button.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'GoogleSignInProvider.dart';
|
||||
import 'signInPage.dart';
|
||||
import 'globals.dart';
|
||||
import 'user.dart';
|
||||
|
||||
class CreateAccountPage extends StatefulWidget {
|
||||
_CreateAccountPageState createState() => _CreateAccountPageState();
|
||||
}
|
||||
|
||||
class _CreateAccountPageState extends State<CreateAccountPage> {
|
||||
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
||||
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
TextEditingController userNameController = TextEditingController();
|
||||
var db = mysql();
|
||||
late user loggedInUser;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: createLoginPageContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Builds all the components of the page
|
||||
Column createLoginPageContent() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
createBackButton(),
|
||||
createTitleText(),
|
||||
Text(
|
||||
"Create Log in:",
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
createUsernameField(),
|
||||
createEmailField(),
|
||||
createPasswordField(),
|
||||
createCreateAccountButton(),
|
||||
Text("or"),
|
||||
createGoogleButton(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 100),
|
||||
child: createContinueWithoutLoggingInButton(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
SignInButton createGoogleButton() {
|
||||
return SignInButton(Buttons.Google, onPressed: () async {
|
||||
final provider =
|
||||
Provider.of<GoogleSignInProvider>(context, listen: false);
|
||||
await provider.logIn();
|
||||
if (provider.user == null) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
CreateAccountPage()), //Replace Container() with call to Map-page.
|
||||
);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
HomePage()), //Replace Container() with call to Map-page.
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Text createTitleText() {
|
||||
return Text(
|
||||
'Sun Chasers',
|
||||
style: TextStyle(
|
||||
fontSize: 50,
|
||||
color: textColor,
|
||||
fontFamily: 'Sacramento',
|
||||
shadows: const <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2, 2),
|
||||
blurRadius: 10.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputField createUsernameField() {
|
||||
return InputField(
|
||||
text: "Username:", isPassword: false, icon: Icon(Icons.person), controller: userNameController);
|
||||
}
|
||||
|
||||
InputField createEmailField() {
|
||||
return InputField(
|
||||
text: "Email:", isPassword: false, icon: Icon(Icons.email), controller: emailController);
|
||||
}
|
||||
|
||||
InputField createPasswordField() {
|
||||
return InputField(
|
||||
text: "Password:", isPassword: true, icon: Icon(Icons.lock), controller: passwordController);
|
||||
}
|
||||
|
||||
Padding createBackButton() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: 20, left: 10),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back),
|
||||
iconSize: 40,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ElevatedButton createCreateAccountButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () async{
|
||||
UserInput userInput = UserInput(isValid: false, errorMessage: "");
|
||||
await verifyUserInput(emailController.text, userNameController.text, passwordController.text, userInput);
|
||||
if(userInput.isValid){
|
||||
await createUserInSQL(emailController.text, userNameController.text, passwordController.text);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
}else{
|
||||
createUserError(userInput.errorMessage);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"Create Account",
|
||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ElevatedButton createContinueWithoutLoggingInButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => BottomNavPage()),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
"Continue without logging in",
|
||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createUserInSQL(String email, String username, String password) async{
|
||||
await db.getConnection().then((conn) async{
|
||||
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){
|
||||
for(var row in results){
|
||||
setState(() {
|
||||
});
|
||||
loggedInUser = new user(row[0], row[1], row[2]);
|
||||
LOGGED_IN_USER.userID = loggedInUser.userID;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
Future<void> verifyUserInput(String email, String username, String password, userInput) async {
|
||||
userInput.isValid = false;
|
||||
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;
|
||||
}
|
||||
await db.getConnection().then((conn) async{
|
||||
String sql = "SELECT email from maen0574.user where email = '$email';";
|
||||
var results = await conn.query(sql);
|
||||
userInput.isValid = true;
|
||||
for(var row in results){
|
||||
userInput.isValid = false;
|
||||
userInput.errorMessage = "email already registererd";
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
void createUserError(String stringContext) {
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text("Couldn't create user"),
|
||||
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;
|
||||
}
|
||||
} // _LoginPageState
|
||||
|
||||
class InputField extends StatelessWidget {
|
||||
final Icon icon;
|
||||
final String text;
|
||||
final bool isPassword;
|
||||
final TextEditingController controller;
|
||||
const InputField({
|
||||
Key? key,
|
||||
required this.text,
|
||||
required this.isPassword,
|
||||
required this.icon,
|
||||
required this.controller
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 60),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
width: size.width * 0.7,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: TextField(
|
||||
obscureText: isPassword,
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: text,
|
||||
icon: icon,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'BottomNavPage.dart';
|
||||
import 'package:flutter_applicationdemo/login/CreateAccountPage.dart';
|
||||
import 'package:flutter_applicationdemo/CreateAccountPage.dart';
|
||||
import 'Venue.dart';
|
||||
import 'globals.dart';
|
||||
import 'login/signInPage.dart';
|
||||
import '../login/user.dart';
|
||||
import 'mysql.dart';
|
||||
import 'signInPage.dart';
|
||||
import 'user.dart';
|
||||
|
@ -189,6 +192,4 @@ class _HomePageState extends State<HomePage> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@ import 'package:firebase_auth/firebase_auth.dart';
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
||||
import 'package:flutter_applicationdemo/GoogleSignInProvider.dart';
|
||||
import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
import 'ManageAccountPage.dart';
|
||||
import 'GoogleSignInProvider.dart';
|
||||
import 'login/GoogleSignInProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
// Standard color of app
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
||||
|
||||
import 'package:flutter_applicationdemo/HomePage.dart';
|
||||
|
||||
class createUserPage extends StatefulWidget {
|
||||
_createUserPageState createState() => _createUserPageState();
|
||||
}
|
||||
|
||||
class _createUserPageState extends State<createUserPage> {
|
||||
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
||||
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
createBackButton(),
|
||||
createTitleText(),
|
||||
Text(
|
||||
"Create Log in:",
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
createUsernameField(),
|
||||
createEmailField(),
|
||||
createPasswordField(),
|
||||
createCreateAccountButton(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 100),
|
||||
child: createContinueWithoutLoggingInButton(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Text createTitleText() {
|
||||
return Text(
|
||||
'Sun Chasers',
|
||||
style: TextStyle(
|
||||
fontSize: 50,
|
||||
color: textColor,
|
||||
fontFamily: 'Sacramento',
|
||||
shadows: const <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2, 2),
|
||||
blurRadius: 10.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputField createUsernameField() {
|
||||
return InputField(
|
||||
text: "Username:", isPassword: false, icon: Icon(Icons.person));
|
||||
}
|
||||
|
||||
InputField createEmailField() {
|
||||
return InputField(
|
||||
text: "Email:", isPassword: false, icon: Icon(Icons.email));
|
||||
}
|
||||
|
||||
InputField createPasswordField() {
|
||||
return InputField(
|
||||
text: "Password:", isPassword: true, icon: Icon(Icons.lock));
|
||||
}
|
||||
|
||||
Padding createBackButton() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: 20, left: 10),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back),
|
||||
iconSize: 40,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ElevatedButton createCreateAccountButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () {},
|
||||
child: Text(
|
||||
"Create Account",
|
||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ElevatedButton createContinueWithoutLoggingInButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => BottomNavPage()),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
"Continue without logging in",
|
||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
} // _LoginPageState
|
||||
class InputField extends StatelessWidget {
|
||||
final Icon icon;
|
||||
final String text;
|
||||
final bool isPassword;
|
||||
const InputField({
|
||||
Key? key,
|
||||
required this.text,
|
||||
required this.isPassword,
|
||||
required this.icon,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 60),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
width: size.width * 0.7,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: TextField(
|
||||
obscureText: isPassword,
|
||||
decoration: InputDecoration(
|
||||
hintText: text,
|
||||
icon: icon,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import 'Venue.dart';
|
||||
import 'user.dart';
|
||||
import '../login/user.dart';
|
||||
import 'HomePage.dart';
|
||||
import 'main.dart';
|
||||
|
||||
|
|
212
lib/login/CreateAccountPage.dart
Normal file
212
lib/login/CreateAccountPage.dart
Normal file
|
@ -0,0 +1,212 @@
|
|||
// ignore_for_file: prefer_const_constructors
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
||||
|
||||
import 'package:flutter_applicationdemo/mysql.dart';
|
||||
|
||||
import 'package:flutter_applicationdemo/HomePage.dart';
|
||||
import '../globals.dart';
|
||||
import '../reusables/InputField.dart';
|
||||
import 'user.dart';
|
||||
import '../reusables/returnButton.dart';
|
||||
|
||||
class CreateAccountPage extends StatefulWidget {
|
||||
_CreateAccountPageState createState() => _CreateAccountPageState();
|
||||
}
|
||||
|
||||
class _CreateAccountPageState extends State<CreateAccountPage> {
|
||||
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
||||
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
TextEditingController userNameController = TextEditingController();
|
||||
var db = mysql();
|
||||
late user loggedInUser;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
leading: ReturnButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: createLoginPageContent(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Builds all the components of the page
|
||||
Column createLoginPageContent() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
createTitleText(),
|
||||
Text(
|
||||
"Create Log in:",
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
createUsernameField(),
|
||||
createEmailField(),
|
||||
createPasswordField(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: createCreateAccountButton(),
|
||||
),
|
||||
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Text createTitleText() {
|
||||
return Text(
|
||||
'Sun Chasers',
|
||||
style: TextStyle(
|
||||
fontSize: 50,
|
||||
color: textColor,
|
||||
fontFamily: 'Sacramento',
|
||||
shadows: const <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2, 2),
|
||||
blurRadius: 10.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputField createUsernameField() {
|
||||
return InputField(
|
||||
text: "Username:",
|
||||
isPassword: false,
|
||||
icon: Icon(Icons.person),
|
||||
controller: userNameController);
|
||||
}
|
||||
|
||||
InputField createEmailField() {
|
||||
return InputField(
|
||||
text: "Email:",
|
||||
isPassword: false,
|
||||
icon: Icon(Icons.email),
|
||||
controller: emailController);
|
||||
}
|
||||
|
||||
InputField createPasswordField() {
|
||||
return InputField(
|
||||
text: "Password:",
|
||||
isPassword: true,
|
||||
icon: Icon(Icons.lock),
|
||||
controller: passwordController);
|
||||
}
|
||||
|
||||
ElevatedButton createCreateAccountButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () async {
|
||||
UserInput userInput = UserInput(isValid: false, errorMessage: "");
|
||||
await verifyUserInput(emailController.text, userNameController.text,
|
||||
passwordController.text, userInput);
|
||||
if (userInput.isValid) {
|
||||
await createUserInSQL(emailController.text, userNameController.text,
|
||||
passwordController.text);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
} else {
|
||||
createUserError(userInput.errorMessage);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"Create Account",
|
||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400),
|
||||
),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createUserInSQL(
|
||||
String email, String username, String password) async {
|
||||
await db.getConnection().then((conn) async {
|
||||
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) {
|
||||
for (var row in results) {
|
||||
setState(() {});
|
||||
loggedInUser = new user(row[0], row[1], row[2]);
|
||||
LOGGED_IN_USER.userID = loggedInUser.userID;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> verifyUserInput(
|
||||
String email, String username, String password, userInput) async {
|
||||
userInput.isValid = false;
|
||||
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;
|
||||
}
|
||||
await db.getConnection().then((conn) async {
|
||||
String sql = "SELECT email from maen0574.user where email = '$email';";
|
||||
var results = await conn.query(sql);
|
||||
userInput.isValid = true;
|
||||
for (var row in results) {
|
||||
userInput.isValid = false;
|
||||
userInput.errorMessage = "email already registererd";
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
void createUserError(String stringContext) {
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text("Couldn't create user"),
|
||||
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;
|
||||
}
|
||||
} // _LoginPageState
|
||||
|
||||
|
198
lib/login/signInPage.dart
Normal file
198
lib/login/signInPage.dart
Normal file
|
@ -0,0 +1,198 @@
|
|||
import 'dart:io';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../mysql.dart';
|
||||
import '../HomePage.dart';
|
||||
import '../main.dart';
|
||||
import 'user.dart';
|
||||
import 'package:flutter_applicationdemo/globals.dart';
|
||||
import '../reusables/InputField.dart';
|
||||
import '../reusables/returnButton.dart';
|
||||
import 'package:flutter_signin_button/flutter_signin_button.dart';
|
||||
import 'GoogleSignInProvider.dart';
|
||||
import 'CreateAccountPage.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SignInPage extends StatefulWidget {
|
||||
@override
|
||||
State<SignInPage> createState() => _SignInPageState();
|
||||
}
|
||||
|
||||
class _SignInPageState extends State<SignInPage> {
|
||||
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
||||
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
||||
var db = mysql();
|
||||
int loggedInID = 0;
|
||||
late user loggedInUser;
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
|
||||
Future<void> loginVerification(String email, String password) async {
|
||||
await db.getConnection().then((conn) async {
|
||||
String sql =
|
||||
"select id, email, password from maen0574.user where email = '$email' and password = '$password'";
|
||||
await conn.query(sql).then((results) {
|
||||
for (var row in results) {
|
||||
setState(() {});
|
||||
loggedInUser = new user(row[0], row[1], row[2]);
|
||||
loggedInID = loggedInUser.getID();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
leading: ReturnButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
//resizeToAvoidBottomPadding: false,
|
||||
resizeToAvoidBottomInset: false,
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
createTitleText(),
|
||||
const Text(
|
||||
'Sign in',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
),
|
||||
createEmailField(),
|
||||
createPasswordField(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10.0),
|
||||
child: createSignInButton(),
|
||||
),
|
||||
const Text("or"),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10.0),
|
||||
child: createGoogleButton(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
|
||||
void loginError() {
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Login failed'),
|
||||
content: const Text('Email or password incorrect'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, 'OK'),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Text createTitleText() {
|
||||
return Text(
|
||||
'Sun Chasers',
|
||||
style: TextStyle(
|
||||
fontSize: 50,
|
||||
color: textColor,
|
||||
fontFamily: 'Sacramento',
|
||||
shadows: const <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2, 2),
|
||||
blurRadius: 10.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
InputField createEmailField() {
|
||||
return InputField(
|
||||
text: "Email:",
|
||||
isPassword: false,
|
||||
icon: Icon(Icons.email),
|
||||
controller: emailController);
|
||||
}
|
||||
|
||||
InputField createPasswordField() {
|
||||
return InputField(
|
||||
text: "Password:",
|
||||
isPassword: true,
|
||||
icon: Icon(Icons.lock),
|
||||
controller: passwordController);
|
||||
}
|
||||
|
||||
ElevatedButton createSignInButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (emailController.text.contains("'") ||
|
||||
passwordController.text.contains("'")) {
|
||||
loginError();
|
||||
return;
|
||||
}
|
||||
await loginVerification(emailController.text, passwordController.text);
|
||||
if (loggedInID != 0) {
|
||||
LOGGED_IN_USER = loggedInUser;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
HomePage()), //Replace Container() with call to account-page.
|
||||
);
|
||||
} else {
|
||||
loginError();
|
||||
}
|
||||
//print(loggedInUser.email + " " + loggedInUser.userID.toString());
|
||||
},
|
||||
child: const Text(
|
||||
"Sign in",
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontWeight: FontWeight.w400, fontSize: 15),
|
||||
),
|
||||
style: ButtonStyle(
|
||||
backgroundColor: MaterialStateProperty.all(Colors.white),
|
||||
fixedSize: MaterialStateProperty.all(Size.fromHeight(40.0)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
SignInButton createGoogleButton() {
|
||||
return SignInButton(Buttons.Google, onPressed: () async {
|
||||
final provider =
|
||||
Provider.of<GoogleSignInProvider>(context, listen: false);
|
||||
await provider.logIn();
|
||||
if (provider.user == null) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
CreateAccountPage()), //Replace Container() with call to Map-page.
|
||||
);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
HomePage()), //Replace Container() with call to Map-page.
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter_applicationdemo/GoogleSignInProvider.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:flutter_applicationdemo/login/GoogleSignInProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'Map.dart';
|
||||
|
@ -12,6 +13,7 @@ import 'HomePage.dart';
|
|||
import 'Venue.dart';
|
||||
import 'mysql.dart';
|
||||
import 'user.dart';
|
||||
import 'login/user.dart';
|
||||
import 'globals.dart';
|
||||
|
||||
void main() async {
|
||||
|
|
40
lib/reusables/InputField.dart
Normal file
40
lib/reusables/InputField.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
import 'package:flutter/material.dart';
|
||||
// This class creates an input field for the login- and register-pages
|
||||
class InputField extends StatelessWidget {
|
||||
final Icon icon; // The icon
|
||||
final String text; // The text to be displayed inside the input field
|
||||
final bool isPassword; // Set to true if you want the input text to be hidden
|
||||
final TextEditingController controller;
|
||||
const InputField(
|
||||
{Key? key,
|
||||
required this.text,
|
||||
required this.isPassword,
|
||||
required this.icon,
|
||||
required this.controller})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 60),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
width: size.width * 0.7,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: TextField(
|
||||
obscureText: isPassword,
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: text,
|
||||
icon: icon,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
29
lib/reusables/returnButton.dart
Normal file
29
lib/reusables/returnButton.dart
Normal file
|
@ -0,0 +1,29 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_applicationdemo/HomePage.dart';
|
||||
|
||||
class ReturnButton extends StatelessWidget {
|
||||
final onPressed;
|
||||
ReturnButton({
|
||||
required this.onPressed,
|
||||
Key? key,})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: IconButton(
|
||||
onPressed: onPressed,
|
||||
icon: const Icon(
|
||||
Icons.arrow_back,
|
||||
color: Colors.black,
|
||||
),
|
||||
iconSize: 40,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
import 'dart:io';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'mysql.dart';
|
||||
import 'HomePage.dart';
|
||||
import 'main.dart';
|
||||
import 'user.dart';
|
||||
import 'package:flutter_applicationdemo/globals.dart';
|
||||
|
||||
class SignInPage extends StatefulWidget{
|
||||
@override
|
||||
State<SignInPage> createState() => _SignInPageState();
|
||||
}
|
||||
|
||||
class _SignInPageState extends State<SignInPage> {
|
||||
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
||||
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
||||
var db = mysql();
|
||||
int loggedInID = 0;
|
||||
late user loggedInUser;
|
||||
TextEditingController emailController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
|
||||
Future<void> loginVerification(String email, String password) async{
|
||||
await db.getConnection().then((conn) async {
|
||||
String sql = "select id, username, email from maen0574.user where email = '$email' and password = '$password'";
|
||||
await conn.query(sql).then((results){
|
||||
for(var row in results){
|
||||
setState(() {
|
||||
});
|
||||
loggedInUser = new user(row[0], row[1], row[2]);
|
||||
loggedInID = loggedInUser.getID();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
return Scaffold(
|
||||
//resizeToAvoidBottomPadding: false,
|
||||
resizeToAvoidBottomInset: false,
|
||||
backgroundColor: pinkBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
//mainAxisAlignment: MainAxisAlignment.center,
|
||||
//crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
createBackButton(),
|
||||
createTitleText(),
|
||||
const Text(
|
||||
'Login',
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: TextField(
|
||||
controller: emailController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'email',
|
||||
hintText: 'Enter your email',
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: TextField(
|
||||
controller: passwordController,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Password',
|
||||
hintText: 'Enter Password',
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
fixedSize: const Size(100, 50),
|
||||
primary: const Color.fromARGB(204, 172, 123, 132),
|
||||
elevation: 100,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: new BorderRadius.circular(400.0),
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
if(emailController.text.contains("'") || passwordController.text.contains("'")){
|
||||
loginError();
|
||||
return;
|
||||
}
|
||||
await loginVerification(emailController.text, passwordController.text);
|
||||
if(loggedInID != 0){
|
||||
LOGGED_IN_USER = loggedInUser;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to account-page.
|
||||
);
|
||||
}else{
|
||||
loginError();
|
||||
}
|
||||
//print(loggedInUser.email + " " + loggedInUser.userID.toString());
|
||||
},
|
||||
child: Text('Sign In'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
|
||||
void loginError() {
|
||||
showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Login failed'),
|
||||
content: const Text('Email or password incorrect'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, 'OK'),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Padding createBackButton() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20, left: 10),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomePage()),
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.arrow_back),
|
||||
iconSize: 40,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Text createTitleText() {
|
||||
return Text(
|
||||
'Sun Chasers',
|
||||
style: TextStyle(
|
||||
fontSize: 50,
|
||||
color: textColor,
|
||||
fontFamily: 'Sacramento',
|
||||
shadows: const <Shadow>[
|
||||
Shadow(
|
||||
offset: Offset(2, 2),
|
||||
blurRadius: 10.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
14
pubspec.lock
14
pubspec.lock
|
@ -14,7 +14,7 @@ packages:
|
|||
name: args
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
version: "2.3.1"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -91,7 +91,7 @@ packages:
|
|||
name: ffi
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
version: "1.2.1"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -260,7 +260,7 @@ packages:
|
|||
name: google_api_headers
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0+1"
|
||||
version: "1.3.0"
|
||||
google_fonts:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -316,14 +316,14 @@ packages:
|
|||
name: google_sign_in_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
version: "2.1.3"
|
||||
google_sign_in_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_sign_in_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.10.1+1"
|
||||
version: "0.10.1+2"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -512,7 +512,7 @@ packages:
|
|||
name: path_provider_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
version: "2.0.4"
|
||||
path_provider_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -685,7 +685,7 @@ packages:
|
|||
name: yaml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
version: "3.1.1"
|
||||
sdks:
|
||||
dart: ">=2.16.2 <3.0.0"
|
||||
flutter: ">=2.10.0-0"
|
||||
|
|
Loading…
Reference in New Issue
Block a user