init, login register done

This commit is contained in:
2023-02-08 17:06:03 +05:30
commit b20b8ac538
82 changed files with 2749 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import 'dart:developer';
class Debug{
static bool enableLogging = true;
static bool enableResponseLogging = true;
static bool enableErrorLoggin = true;
static bool enableTestLogging = true;
static void LogResponse(Object? response, {Object src= ''}){
if(!enableLogging){return;}
if(!enableResponseLogging) {return;}
print('\x1B[32m$src response\n$response\x1B[0m');
}
static void LogError(Object? msg){
if(!enableLogging){return;}
if(!enableErrorLoggin) {return;}
print('\x1B[31m$msg\x1B[0m');
}
static void Log(Object? msg){
if(!enableLogging) {return;}
print('\x1B[36m$msg\x1B[0m');
}
static void LogTest(Object? msg){
if(!enableLogging){return;}
if(!enableTestLogging) {return;}
print('\x1B[35m$msg\x1B[0m');
}
}

75
lib/Backend/Dialogs.dart Normal file
View File

@@ -0,0 +1,75 @@
import 'package:faucethub/Backend/login_mgr.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../main.dart';
class Dialogs{
static showAlertDialog(BuildContext context, String title, String message) {
// set up the button
Widget okButton = TextButton(
child: Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
backgroundColor: Color(0xFF1F1F1F),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
title: Text(title),
content: Text(message),
actions: [
okButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
static bool showing = false;
static BuildContext? context;
static waiting(){
showing=true;
context=navigatorKey.currentContext;
if(context!=null) {
return showDialog(
context: context!,
barrierDismissible: false,
routeSettings: const RouteSettings(name: "Progress"),
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
backgroundColor: Color(0xaa101010),
title: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SpinKitChasingDots(color: Colors.green),
Expanded(child: Text("Loading",textAlign: TextAlign.center,)),
],
),
);
}
);
}
}
static hide(){
showing=false;
Navigator.of(navigatorKey.currentContext!).popUntil((route){
return route.settings.name!="Progress";
});
}
}

6
lib/Backend/brains.dart Normal file
View File

@@ -0,0 +1,6 @@
class Brain{
static const String API_ENDPOINT = "http://vps.playpoolstudios.com/faucet/api/";
static dynamic UserJson;
}

View File

@@ -0,0 +1,33 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
class GoogleSignInProvider extends ChangeNotifier{
final googleSignIn = GoogleSignIn();
GoogleSignInAccount? _user;
GoogleSignInAuthentication? googleAuth;
GoogleSignInAccount get user => _user!;
Future googleLogin() async{
final googleUser = await googleSignIn.signIn();
if(googleUser==null) return;
_user = googleUser;
googleAuth = await googleUser.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth!.accessToken,
idToken: googleAuth!.idToken
);
print('user login\nusername:${googleUser.displayName}\nemail:${googleUser.email}\nid:${googleAuth!.idToken}');
print(googleAuth!.accessToken!.length);
notifyListeners();
}
Future logout() async{
await googleSignIn.disconnect();
}
}

26
lib/Backend/hoarder.dart Normal file
View File

@@ -0,0 +1,26 @@
import 'dart:convert';
import 'package:faucethub/Backend/DebugHelper.dart';
import 'package:faucethub/Backend/brains.dart';
import 'package:http/http.dart' as http;
class Hoarder{
static List<dynamic> GamesJson = [];
static void GrabInitData() async{
var response = null;
try {
response = (await http.post(Uri.parse('${Brain.API_ENDPOINT}get_games.php')));
Debug.LogError(response.body.toString());
GamesJson=[];
List<String> games = response.body.toString().split("<td>");
games.forEach((game) {
GamesJson.add(jsonDecode(game));
});
} catch (e) {
Debug.LogError("Error while loading games : $e");
}
}
}

View File

@@ -0,0 +1,91 @@
import 'dart:convert';
import 'package:faucethub/Backend/DebugHelper.dart';
import 'package:faucethub/Backend/brains.dart';
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
class LoginManager {
static Future<int> AutoLogin() async{
final prefs = await SharedPreferences.getInstance();
String username = "";
String password= "";
try{
username = prefs.getString("username")!;
password = prefs.getString("password")!;
}catch(e){
}
if(username.length > 3 && password.length >5){
return await Login(username, password);
}
return 1;
}
static Future<int> Register (String username, String password) async{
Debug.Log("Starting registration");
final prefs = await SharedPreferences.getInstance();
var loginResponse = null;
try {
loginResponse = (await http.post(
Uri.parse('${Brain.API_ENDPOINT}register.php'),
body: <String, String>{
"username": username,
"password": password
}));
Debug.LogError(loginResponse.body.toString());
if (loginResponse.body.toLowerCase() == "0") {
prefs.setString("username", username);
prefs.setString("password", password);
return 0;
}else{
return 5;
}
} catch (e) {
Debug.LogError("Error while login $e");
}
return 1;
}
static Future<int> Login (String username, String password) async{
Debug.Log("Logging in");
final prefs = await SharedPreferences.getInstance();
var loginResponse = null;
try {
loginResponse = (await http.post(
Uri.parse('${Brain.API_ENDPOINT}login.php'),
body: <String, String>{
"username": username,
"password": password
}));
Debug.LogError(loginResponse.body.toString());
try{
Brain.UserJson = jsonDecode(loginResponse.body.toString());
Debug.LogResponse(Brain.UserJson);
prefs.setString("username", username);
prefs.setString("password", password);
return 0;
}catch(e){
return 5;
}
} catch (e) {
Debug.LogError("Error while login $e");
}
return 1;
}
}