Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login authetication #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions FrontEnd/sportsapp/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'kotlin-android'
id "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
...
}

android {
compileSdkVersion flutter.compileSdkVersion
Expand All @@ -47,7 +51,7 @@ android {
applicationId "com.example.sportsapp"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand All @@ -68,4 +72,7 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:30.3.2')
implementation 'com.google.firebase:firebase-analytics'
}

1 change: 1 addition & 0 deletions FrontEnd/sportsapp/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
}

Expand Down
2 changes: 1 addition & 1 deletion FrontEnd/sportsapp/lib/Signup.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'dart:ui';
import 'package:sportsapp/main.dart';
import 'package:sportsapp/main.dart' as m;
import 'package:flutter/services.dart';
import 'package:country_picker/country_picker.dart';
import 'package:intl_phone_field/intl_phone_field.dart';
Expand Down
111 changes: 63 additions & 48 deletions FrontEnd/sportsapp/lib/login.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:sportsapp/Login.dart';
import 'dart:ui';
Expand Down Expand Up @@ -51,15 +52,27 @@ class MyApp extends StatelessWidget {
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
_MyStatefulWidgetState createstate() => _MyStatefulWidgetState();

@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
TextEditingController nameController = TextEditingController();
TextEditingController passwordController = TextEditingController();

Future signIn() async {
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: nameController.text.trim(),
password: passwordController.text.trim());
} on FirebaseAuthException catch (e) {
print(e);
}
}

@override
Widget build(BuildContext context) {
return Padding(
Expand All @@ -82,7 +95,7 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
controller: nameController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'User Name',
labelText: 'E-mail',
),
),
),
Expand Down Expand Up @@ -113,54 +126,56 @@ class _MyStatefulWidgetState extends State<MyStatefulWidget> {
height: 20,
),
Container(
height: 50,
width: 100,
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
height: 50,
width: 100,
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)),
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40)),
),
child: const Text(
'Login',
style: TextStyle(fontSize: 16),
),
onPressed: () {
print(nameController.text);
print(passwordController.text);
},
)),
SizedBox(
height: 20,
),
Row(
children: <Widget>[
const Text('Does not have account?'),
TextButton(
child: const Text(
'Sign in',
style: TextStyle(fontSize: 18, color: Colors.blue),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignupPage(),
),
);
//signup screen
},
)
],
mainAxisAlignment: MainAxisAlignment.center,
),
child: const Text(
'Login',
style: TextStyle(fontSize: 16),
),
onPressed: () {
signIn();
},
),
)
],
));
// ignore: dead_code
Row(
children: <Widget>[
const SizedBox(
height: 20,
),
const Text('Does not have account?'),
TextButton(
child: const Text(
'Sign in',
style: TextStyle(fontSize: 18, color: Colors.blue),
),
onPressed: () {
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: nameController.text, password: passwordController.text);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SignupPage(),
),
);
//signup screen
},
)
],
mainAxisAlignment: MainAxisAlignment.center,
);
;
}
}

/// Signup screen
17 changes: 15 additions & 2 deletions FrontEnd/sportsapp/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/*Made by Charu Gupta*/
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:sportsapp/secondpage.dart';

// function to start app building
void main() => runApp(MaterialApp(
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(backgroundColor: Color.fromRGBO(1, 9, 12, 255)),
title: 'Page Navigation',
home: FirstPage(),
));
);
}
}

class FirstPage extends StatelessWidget {
@override
Expand Down
103 changes: 58 additions & 45 deletions FrontEnd/sportsapp/lib/secondpage.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:ui';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:sportsapp/landing.dart';
import 'package:country_list_pick/country_list_pick.dart';
import 'package:country_picker/country_picker.dart';
Expand All @@ -7,20 +8,31 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:intl_phone_field/intl_phone_field.dart';
import 'package:sportsapp/Signup.dart';
import 'package:sportsapp/main.dart';
import 'package:sportsapp/login.dart';
import 'package:sportsapp/main.dart' as m;
import 'package:sportsapp/login.dart' as l;

class secondpage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Welcome To The World of Sports !'),
centerTitle: true,
leading: Container(child: Image.asset('assets/images/open.png')),
),
body: Center(
child: Column(
appBar: AppBar(
title: const Text('Welcome To The World of Sports !'),
centerTitle: true,
leading: Container(child: Image.asset('assets/images/open.png')),
),
body: StreamBuilder<User?>(
stream: FirebaseAuth.instance.authStateChanges(),
builder: ((context, snapshot) {
if (snapshot.hasData) {
return Landing();
} else {
return l.MyStatefulWidget();
}
}),
),
);
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
Expand All @@ -30,41 +42,42 @@ class secondpage extends StatelessWidget {
fit: BoxFit.cover,
),
),
Container(
margin: const EdgeInsets.only(top: 40),
width: 200,
height: 40,
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
child: ElevatedButton(
child: const Text('SignUp'),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => SignupPage()));
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
)),
),
),
Container(
margin: const EdgeInsets.only(top: 20),
width: 200,
height: 40,
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
child: ElevatedButton(
child: const Text('LogIn'),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => MyApp()));
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
)),
),
),
],
)));
]),
);
Container(
margin: const EdgeInsets.only(top: 40),
width: 200,
height: 40,
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
child: ElevatedButton(
child: const Text('SignUp'),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => SignupPage()));
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
)),
),
);
Container(
margin: const EdgeInsets.only(top: 20),
width: 200,
height: 40,
padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
child: ElevatedButton(
child: const Text('LogIn'),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => m.MyApp()));
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
)),
),
);
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import FlutterMacOS
import Foundation

import cloud_firestore
import firebase_auth
import firebase_core

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin"))
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
}
Loading