Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Bablo-AD/Mentor
Browse files Browse the repository at this point in the history
  • Loading branch information
prasannan-robots committed Jun 16, 2023
2 parents 731e942 + 885e7f9 commit b2c635b
Show file tree
Hide file tree
Showing 22 changed files with 1,082 additions and 245 deletions.
46 changes: 46 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"project_info": {
"project_number": "1045034252917",
"project_id": "anti-distractor",
"storage_bucket": "anti-distractor.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1045034252917:android:a9fa46111b4efa8d7ed63c",
"android_client_info": {
"package_name": "com.example.anti_distractor"
}
},
"oauth_client": [
{
"client_id": "1045034252917-7d1o1b7tmtf9sjeekjad516olbjt507r.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCleJ7fK1h5-1k_4kvy8E4vqh9EwgknFZA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1045034252917-7d1o1b7tmtf9sjeekjad516olbjt507r.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "1045034252917-fomavjanuhv01pfg90jcmnb3g89ktl7e.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.antiDistractor"
}
}
]
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Generated file.
//
// If you wish to remove Flutter's multidex support, delete this entire file.
//
// Modifications to this file should be done in a copy under a different name
// as this file may be regenerated.

package io.flutter.app;

import android.app.Application;
import android.content.Context;
import androidx.annotation.CallSuper;
import androidx.multidex.MultiDex;

/**
* Extension of {@link android.app.Application}, adding multidex support.
*/
public class FlutterMultiDexApplication extends Application {
@Override
@CallSuper
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Binary file added asset/font/SpaceMono-Bold.ttf
Binary file not shown.
Binary file added asset/font/SpaceMono-BoldItalic.ttf
Binary file not shown.
Binary file added asset/font/SpaceMono-Italic.ttf
Binary file not shown.
Binary file added asset/font/SpaceMono-Regular.ttf
Binary file not shown.
34 changes: 34 additions & 0 deletions ios/Runner/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>1045034252917-fomavjanuhv01pfg90jcmnb3g89ktl7e.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.1045034252917-fomavjanuhv01pfg90jcmnb3g89ktl7e</string>
<key>API_KEY</key>
<string>AIzaSyBY_B23S28vyDIQivku69yKkZ47Cu4Vx-M</string>
<key>GCM_SENDER_ID</key>
<string>1045034252917</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.example.antiDistractor</string>
<key>PROJECT_ID</key>
<string>anti-distractor</string>
<key>STORAGE_BUCKET</key>
<string>anti-distractor.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:1045034252917:ios:116fa019fa5091a77ed63c</string>
</dict>
</plist>
7 changes: 7 additions & 0 deletions ios/firebase_app_id_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_generated_by": "FlutterFire CLI",
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
"GOOGLE_APP_ID": "1:1045034252917:ios:116fa019fa5091a77ed63c",
"FIREBASE_PROJECT_ID": "anti-distractor",
"GCM_SENDER_ID": "1045034252917"
}
171 changes: 171 additions & 0 deletions lib/authentication_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'journal_page.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SessionManager {
static const String loggedInKey = 'loggedIn';

static Future<void> saveLoginState(bool isLoggedIn) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool(loggedInKey, isLoggedIn);
}

static Future<bool> getLoginState() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getBool(loggedInKey) ?? false;
}
}

class EmailAuth extends StatefulWidget {
const EmailAuth({Key? key});

@override
_EmailAuthState createState() => _EmailAuthState();
}

class _EmailAuthState extends State<EmailAuth> {
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final FirebaseAuth _auth = FirebaseAuth.instance;

Future<void> _signIn() async {
try {
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
);
// User sign-in successful
User? user = userCredential.user;
if (user != null) {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('userId', user.uid);
await SessionManager.saveLoginState(true);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => JournalPage()),
);
}
} catch (e) {
// Handle sign-in errors
print('Sign-in error: $e');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Sign-in Failed'),
content: const Text('Invalid email or password.'),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}

Future<void> _signUp() async {
try {
UserCredential userCredential =
await _auth.createUserWithEmailAndPassword(
email: _emailController.text.trim(),
password: _passwordController.text.trim(),
);
// User account creation successful
User? user = userCredential.user;
if (user != null) {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('userId', user.uid);
await SessionManager.saveLoginState(true);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => JournalPage()),
);
}
} catch (e) {
// Handle sign-up errors
print('Sign-up error: $e');
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Sign-up Failed'),
content: const Text('Please try again.'),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Mentor/Authentication',
style: TextStyle(color: Color.fromARGB(255, 50, 204, 102)),
),
backgroundColor: Colors.black,
),
backgroundColor: Colors.black,
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: _emailController,
style: TextStyle(color: Color.fromARGB(255, 50, 204, 102)),
decoration: const InputDecoration(
filled: true,
fillColor: Color.fromARGB(255, 19, 19, 19),
labelText: 'Email',
labelStyle:
TextStyle(color: Color.fromARGB(255, 50, 204, 102)),
),
),
const SizedBox(height: 8.0),
TextField(
controller: _passwordController,
style: TextStyle(color: Color.fromARGB(255, 50, 204, 102)),
decoration: const InputDecoration(
filled: true,
fillColor: Color.fromARGB(255, 19, 19, 19),
labelText: 'Password',
labelStyle:
TextStyle(color: Color.fromARGB(255, 50, 204, 102)),
),
obscureText: true,
),
const SizedBox(height: 16.0),
ElevatedButton(
child: const Text('Sign In'),
onPressed: _signIn,
),
const SizedBox(height: 8.0),
ElevatedButton(
child: const Text('Sign Up'),
onPressed: _signUp,
),
],
),
),
),
);
}
}
83 changes: 83 additions & 0 deletions lib/firebase_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// File generated by FlutterFire CLI.
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;

/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
return macos;
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}

static const FirebaseOptions web = FirebaseOptions(
apiKey: 'AIzaSyA1mydVpAfFJwWQcF1iD3MZYGOWx-UZoMk',
appId: '1:1045034252917:web:68919d5f34c551857ed63c',
messagingSenderId: '1045034252917',
projectId: 'anti-distractor',
authDomain: 'anti-distractor.firebaseapp.com',
storageBucket: 'anti-distractor.appspot.com',
measurementId: 'G-8SX4SF8ZEP',
);

static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyCleJ7fK1h5-1k_4kvy8E4vqh9EwgknFZA',
appId: '1:1045034252917:android:a9fa46111b4efa8d7ed63c',
messagingSenderId: '1045034252917',
projectId: 'anti-distractor',
storageBucket: 'anti-distractor.appspot.com',
);

static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyBY_B23S28vyDIQivku69yKkZ47Cu4Vx-M',
appId: '1:1045034252917:ios:116fa019fa5091a77ed63c',
messagingSenderId: '1045034252917',
projectId: 'anti-distractor',
storageBucket: 'anti-distractor.appspot.com',
iosClientId: '1045034252917-fomavjanuhv01pfg90jcmnb3g89ktl7e.apps.googleusercontent.com',
iosBundleId: 'com.example.antiDistractor',
);

static const FirebaseOptions macos = FirebaseOptions(
apiKey: 'AIzaSyBY_B23S28vyDIQivku69yKkZ47Cu4Vx-M',
appId: '1:1045034252917:ios:d7b9b558a76d1d567ed63c',
messagingSenderId: '1045034252917',
projectId: 'anti-distractor',
storageBucket: 'anti-distractor.appspot.com',
iosClientId: '1045034252917-uo5ihvjdctjaggjfas2o5d3a6eu2grqt.apps.googleusercontent.com',
iosBundleId: 'com.example.antiDistractor.RunnerTests',
);
}
Loading

0 comments on commit b2c635b

Please sign in to comment.