Merge Loginpage to master #9

Merged
maen0574 merged 13 commits from LoginPage into master 2022-05-17 10:19:58 +02:00
8 changed files with 261 additions and 110 deletions
Showing only changes of commit 3e28e9022a - Show all commits

View File

@ -392,7 +392,7 @@
"languageVersion": "2.16" "languageVersion": "2.16"
} }
], ],
"generated": "2022-05-06T11:52:10.005704Z", "generated": "2022-05-10T10:03:49.292538Z",
"generator": "pub", "generator": "pub",
"generatorVersion": "2.16.2" "generatorVersion": "2.16.2"
} }

View File

@ -3,7 +3,7 @@
# #
# For more info see: https://dart.dev/go/dot-packages-deprecation # For more info see: https://dart.dev/go/dot-packages-deprecation
# #
# Generated by pub on 2022-05-06 13:52:09.986249. # Generated by pub on 2022-05-10 12:03:49.275584.
archive:file:///C:/Users/morte/OneDrive/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/archive-3.3.0/lib/ archive:file:///C:/Users/morte/OneDrive/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/archive-3.3.0/lib/
args:file:///C:/Users/morte/OneDrive/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/args-2.3.0/lib/ args:file:///C:/Users/morte/OneDrive/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/args-2.3.0/lib/
async:file:///C:/Users/morte/OneDrive/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.8.2/lib/ async:file:///C:/Users/morte/OneDrive/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.8.2/lib/

View File

@ -4741,6 +4741,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
clock clock
fake_async fake_async
material_color_utilities material_color_utilities
quiver
Apache License Apache License
@ -6730,6 +6731,11 @@ flutter_lints
flutter_plugin_android_lifecycle flutter_plugin_android_lifecycle
google_maps_flutter google_maps_flutter
google_maps_flutter_platform_interface google_maps_flutter_platform_interface
google_sign_in
google_sign_in_android
google_sign_in_ios
google_sign_in_platform_interface
google_sign_in_web
path_provider path_provider
path_provider_android path_provider_android
path_provider_ios path_provider_ios
@ -6815,6 +6821,55 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
--------------------------------------------------------------------------------
flutter_signin_button
Copyright (C) 2018, Zayn Jarvis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------------------
font_awesome_flutter
MIT License
Copyright (c) 2017 Brian Egan
Font Awesome Icons by @fontawesome - https://fontawesome.com
License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
freetype2 freetype2

View File

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'BottomNavPage.dart'; import 'BottomNavPage.dart';
import 'signInPage.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);
@ -15,6 +17,7 @@ class _HomePageState extends State<HomePage> {
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) {
print(globals.LOGGED_IN_USER.userID);
return Scaffold( return Scaffold(
backgroundColor: pinkBackgroundColor, backgroundColor: pinkBackgroundColor,
body: SafeArea( body: SafeArea(
@ -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,18 @@ 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),
@ -110,8 +125,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) => SignInPage()), //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),
),
])
), ),
); );
} }

5
lib/globals.dart Normal file
View File

@ -0,0 +1,5 @@
import 'user.dart';
import 'HomePage.dart';
import 'main.dart';
user LOGGED_IN_USER = user(0, "", "");

View File

@ -2,8 +2,11 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'Map.dart'; import 'Map.dart';
import 'HomePage.dart'; import 'HomePage.dart';
import 'user.dart';
import 'globals.dart';
void main() => runApp(MyApp()); void main() => runApp(MyApp());
@ -15,7 +18,7 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue, primarySwatch: Colors.blue,
), ),
title: 'Flutter Google Maps Demo', title: 'Flutter Google Maps Demo',
home: HomePage(), home: const HomePage(),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
); );
} }

View File

@ -1,11 +1,11 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'mysql.dart'; import 'mysql.dart';
import 'HomePage.dart'; import 'HomePage.dart';
import 'main.dart'; import 'main.dart';
import 'user.dart';
import 'package:flutter_applicationdemo/globals.dart';
class SignInPage extends StatefulWidget{ class SignInPage extends StatefulWidget{
@override @override
@ -14,22 +14,20 @@ class SignInPage extends StatefulWidget{
class _SignInPageState extends State<SignInPage> { class _SignInPageState extends State<SignInPage> {
var db = mysql(); var db = mysql();
int loggedId = 0; int loggedInID = 0;
late user loggedInUser;
TextEditingController emailController = TextEditingController(); TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController(); TextEditingController passwordController = TextEditingController();
Future<void> loginVerification(String email, String password) async{ Future<void> loginVerification(String email, String password) async{
bool isValid = false;
await db.getConnection().then((conn) async { await db.getConnection().then((conn) async {
String sql = "select id from maen0574.user where email = '$email' and password = '$password'"; String sql = "select id, email, password from maen0574.user where email = '$email' and password = '$password'";
await conn.query(sql).then((results){ await conn.query(sql).then((results){
for(var row in results){ for(var row in results){
setState(() { setState(() {
}); });
loggedId = row[0]; loggedInUser = new user(row[0], row[1], row[2]);
isValid = true; loggedInID = loggedInUser.getID();
//break;
} }
}); });
}); });
@ -37,6 +35,7 @@ class _SignInPageState extends State<SignInPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Login"), title: Text("Login"),
@ -81,12 +80,14 @@ class _SignInPageState extends State<SignInPage> {
), ),
onPressed: () async { onPressed: () async {
await loginVerification(emailController.text, passwordController.text); await loginVerification(emailController.text, passwordController.text);
if(loggedId != 0){ if(loggedInID != 0){
LOGGED_IN_USER = loggedInUser;
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to account-page. MaterialPageRoute(builder: (context) => HomePage()), //Replace Container() with call to account-page.
); );
} }
//print(loggedInUser.email + " " + loggedInUser.userID.toString());
}, },
child: Text('Sign In'), child: Text('Sign In'),
), ),

18
lib/user.dart Normal file
View 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;
}
}