Merge Loginpage to master #9
File diff suppressed because one or more lines are too long
1
.gitignore
vendored
1
.gitignore
vendored
@@ -135,6 +135,7 @@ $RECYCLE.BIN/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
.flutter-plugins
|
.flutter-plugins
|
||||||
|
.flutter-plugins-dependencies
|
||||||
.fseventsd
|
.fseventsd
|
||||||
.fuse_hidden*
|
.fuse_hidden*
|
||||||
.gradle
|
.gradle
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'BottomNavPage.dart';
|
import 'BottomNavPage.dart';
|
||||||
import 'package:flutter_applicationdemo/LoginPage.dart';
|
import 'package:flutter_applicationdemo/CreateAccountPage.dart';
|
||||||
|
import 'signInPage.dart';
|
||||||
|
import 'user.dart';
|
||||||
|
import 'globals.dart' as globals;
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class HomePage extends StatefulWidget {
|
||||||
const HomePage({Key? key}) : super(key: key);
|
const HomePage({Key? key}) : super(key: key);
|
||||||
@@ -54,7 +57,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
padding: EdgeInsets.fromLTRB(80, 100, 80, 80),
|
padding: EdgeInsets.fromLTRB(80, 40, 80, 80),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
fixedSize: const Size(200, 200),
|
fixedSize: const Size(200, 200),
|
||||||
@@ -85,6 +88,19 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
globals.LOGGED_IN_USER.userID == 0 ?
|
||||||
|
buildLoginAndCreateUserButton() : buildLogOutButton()
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Container buildLoginAndCreateUserButton() {
|
||||||
|
return Container(
|
||||||
|
child: Column(
|
||||||
|
children: <Widget> [
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
fixedSize: const Size(200, 50),
|
fixedSize: const Size(200, 50),
|
||||||
@@ -94,7 +110,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => LoginPage()), //Replace Container() with call to Map-page.
|
MaterialPageRoute(builder: (context) => SignInPage()), //Replace Container() with call to Map-page.
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('Sign in',
|
child: const Text('Sign in',
|
||||||
@@ -110,8 +126,62 @@ class _HomePageState extends State<HomePage> {
|
|||||||
])
|
])
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]),
|
Padding(padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5)),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
fixedSize: const Size(200, 50),
|
||||||
|
primary: buttonColor,
|
||||||
|
elevation: 100,
|
||||||
),
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => LoginPage()), //Replace Container() with call to Map-page.
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Create account',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: Colors.white,
|
||||||
|
shadows: <Shadow> [
|
||||||
|
Shadow(
|
||||||
|
offset: Offset(2, 2),
|
||||||
|
blurRadius: 10.0,
|
||||||
|
color: Color.fromARGB(255, 0, 0, 0),
|
||||||
|
),
|
||||||
|
])
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ElevatedButton buildLogOutButton() {
|
||||||
|
return ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
fixedSize: const Size(200, 50),
|
||||||
|
primary: buttonColor,
|
||||||
|
elevation: 100,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
globals.LOGGED_IN_USER = user(0, "", "");
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to Map-page.
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: const Text('Log out',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: Colors.white,
|
||||||
|
shadows: <Shadow> [
|
||||||
|
Shadow(
|
||||||
|
offset: Offset(2, 2),
|
||||||
|
blurRadius: 10.0,
|
||||||
|
color: Color.fromARGB(255, 0, 0, 0),
|
||||||
|
),
|
||||||
|
])
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +1,23 @@
|
|||||||
// ignore_for_file: prefer_const_constructors
|
|
||||||
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
import 'package:flutter_applicationdemo/BottomNavPage.dart';
|
||||||
import 'package:flutter_applicationdemo/GoogleSignInProvider.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';
|
|
||||||
|
|
||||||
class LoginPage extends StatefulWidget {
|
import 'package:flutter_applicationdemo/HomePage.dart';
|
||||||
_LoginPageState createState() => _LoginPageState();
|
|
||||||
|
class createUserPage extends StatefulWidget {
|
||||||
|
_createUserPageState createState() => _createUserPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _LoginPageState extends State<LoginPage> {
|
class _createUserPageState extends State<createUserPage> {
|
||||||
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
Color pinkBackgroundColor = const Color.fromARGB(255, 240, 229, 229);
|
||||||
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
Color textColor = const Color.fromARGB(255, 79, 98, 114);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
Size size = MediaQuery.of(context).size;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: pinkBackgroundColor,
|
backgroundColor: pinkBackgroundColor,
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: createLoginPageContent(),
|
child: Column(
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builds all the components of the page
|
|
||||||
Column createLoginPageContent() {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@@ -44,38 +31,16 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
createEmailField(),
|
createEmailField(),
|
||||||
createPasswordField(),
|
createPasswordField(),
|
||||||
createCreateAccountButton(),
|
createCreateAccountButton(),
|
||||||
Text("or"),
|
|
||||||
createGoogleButton(),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 100),
|
padding: EdgeInsets.only(top: 100),
|
||||||
child: createContinueWithoutLoggingInButton(),
|
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) =>
|
|
||||||
LoginPage()), //Replace Container() with call to Map-page.
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) =>
|
|
||||||
HomePage()), //Replace Container() with call to Map-page.
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Text createTitleText() {
|
Text createTitleText() {
|
||||||
return Text(
|
return Text(
|
||||||
@@ -160,7 +125,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} // _LoginPageState
|
} // _LoginPageState
|
||||||
|
|
||||||
class InputField extends StatelessWidget {
|
class InputField extends StatelessWidget {
|
||||||
final Icon icon;
|
final Icon icon;
|
||||||
final String text;
|
final String text;
|
||||||
5
lib/globals.dart
Normal file
5
lib/globals.dart
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import 'user.dart';
|
||||||
|
import 'HomePage.dart';
|
||||||
|
import 'main.dart';
|
||||||
|
|
||||||
|
user LOGGED_IN_USER = user(0, "", "");
|
||||||
@@ -5,10 +5,13 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter_applicationdemo/GoogleSignInProvider.dart';
|
import 'package:flutter_applicationdemo/GoogleSignInProvider.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'Map.dart';
|
import 'Map.dart';
|
||||||
import 'HomePage.dart';
|
import 'HomePage.dart';
|
||||||
|
import 'user.dart';
|
||||||
|
import 'globals.dart';
|
||||||
|
|
||||||
void main() async{
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp();
|
await Firebase.initializeApp();
|
||||||
|
|
||||||
|
|||||||
21
lib/mysql.dart
Normal file
21
lib/mysql.dart
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:mysql1/mysql1.dart';
|
||||||
|
|
||||||
|
class mysql{
|
||||||
|
static String host = 'mysql.dsv.su.se', user = 'maen0574', password = 'iT0aeth8ofib', db = 'maen0574';
|
||||||
|
|
||||||
|
static int port = 3306;
|
||||||
|
|
||||||
|
mysql();
|
||||||
|
|
||||||
|
Future<MySqlConnection> getConnection() async{
|
||||||
|
var settings = ConnectionSettings(
|
||||||
|
host: host,
|
||||||
|
port: port,
|
||||||
|
user: user,
|
||||||
|
password: password,
|
||||||
|
db: db
|
||||||
|
);
|
||||||
|
return await MySqlConnection.connect(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
167
lib/signInPage.dart
Normal file
167
lib/signInPage.dart
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
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, 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(
|
||||||
|
//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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
lib/user.dart
Normal file
18
lib/user.dart
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class user{
|
||||||
|
late int userID;
|
||||||
|
late String username;
|
||||||
|
late String email;
|
||||||
|
|
||||||
|
user(int userID, String username, String email){
|
||||||
|
this.userID = userID;
|
||||||
|
this.username = username;
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
user emptyUser(){
|
||||||
|
return user(0, "", "");
|
||||||
|
}
|
||||||
|
int getID(){
|
||||||
|
return userID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,6 +49,7 @@ dependencies:
|
|||||||
firebase_auth: ^1.1.4
|
firebase_auth: ^1.1.4
|
||||||
google_sign_in: ^5.0.3
|
google_sign_in: ^5.0.3
|
||||||
get: ^4.6.1
|
get: ^4.6.1
|
||||||
|
mysql1: ^0.19.0
|
||||||
|
|
||||||
flutter_native_splash:
|
flutter_native_splash:
|
||||||
background_image: assets/images/outdoor.png
|
background_image: assets/images/outdoor.png
|
||||||
|
|||||||
Reference in New Issue
Block a user