Skip to content

Commit

Permalink
Basic registration integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodepapaya committed Feb 11, 2021
1 parent b1f3b83 commit b01864a
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 61 deletions.
72 changes: 49 additions & 23 deletions lib/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ class Globals {
static String _appName;
static String _packageName;
static String _version;
static String _buildNumber;
static int _buildNumber;

static String _model;
static String _brand;
static String _fingerprint;
static String _id;
static String _type;
static String _androidId;
static String _device;
static String _tags;
static int _sdk;
static bool _isPhysicalDevice;

static Future<void> initialize() async {
Expand All @@ -40,7 +40,7 @@ class Globals {
_appName = _packageInfo.appName;
_packageName = _packageInfo.packageName;
_version = _packageInfo.version;
_buildNumber = _packageInfo.buildNumber;
_buildNumber = int.parse(_packageInfo.buildNumber);

_model = _androidInfo.model;
_isPhysicalDevice = _androidInfo.isPhysicalDevice;
Expand All @@ -50,26 +50,52 @@ class Globals {
_androidId = _androidInfo.androidId;
_device = _androidInfo.device;
_tags = _androidInfo.tags;
_sdk = _androidInfo.version.sdkInt;
}

FlutterSecureStorage get secureStorage => _secureStorage;

String get wifiBSSID => _wifiBSSID;
String get wifiIP => _wifiIP;
String get wifiName => _wifiName;

String get appName => _appName;
String get packageName => _packageName;
String get version => _version;
String get buildNumber => _buildNumber;

String get model => _model;
String get brand => _brand;
String get fingerprint => _fingerprint;
String get id => _id;
String get type => _type;
String get androidId => _androidId;
String get device => _device;
String get tags => _tags;
bool get isPhysicalDevice => _isPhysicalDevice;
static FlutterSecureStorage get secureStorage => _secureStorage;

/// The unique access point of the WLAN
static String get wifiBSSID => _wifiBSSID;

/// Local IP of the device connecetd to WLAN
static String get wifiIP => _wifiIP;

/// Also known as SSID, the display name of the WLAN network
static String get wifiName => _wifiName;

/// The display name of the application. FASE.
static String get appName => _appName;

/// The unique package name of the application. in.ac.iiitvadodara.fase
static String get packageName => _packageName;

/// The version string of the application. eg v1.0.5
static String get version => _version;

/// The build number of the application tied to the [_version]. Must be a natural number
static int get buildNumber => _buildNumber;

/// The model of the android device. eg Zenfone
static String get model => _model;

/// Manufacturer brand of the application. eg ASUS, Google
static String get brand => _brand;

/// Combination of many fields like brand, model, tags, etc
static String get fingerprint => _fingerprint;
static String get type => _type;

/// Unique device ID of the application
static String get androidId => _androidId;
static String get device => _device;

/// Wheather user release tags of build tags
static String get tags => _tags;

/// The Android SDK version the application is running on
static int get sdk => _sdk;

/// Wheather of not the application is running on a real device or emulator
static bool get isPhysicalDevice => _isPhysicalDevice;
}
7 changes: 4 additions & 3 deletions lib/string_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class StringResources {
//static const String name = "";
static const String methodChannel = 'in.ac.iiitvadodara.fase/rooted';
static const String serverKey = "server-key";
static const String emailDomain = "@iiitvadodara.ac.in";

/* Display Text */

Expand All @@ -27,12 +28,12 @@ class StringResources {
static const String permissionRestrictedBody =
"Location access has been restricted on this device. Please enable location access.";

static const String emailDomain = "@iiitvadodara.ac.in";
static const String signOut = "Sign Out";
static const String signIn = "Sign In";
static const String useIIITV = "Use your Institute email ID to login";
//static const String name = "";
//static const String name = "";

static const String register = "Register";
static const String registerPrompt = "You are not registered with the server";
//static const String name = "";
//static const String name = "";
//static const String name = "";
Expand Down
73 changes: 56 additions & 17 deletions lib/ui/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:fase/globals.dart';
import 'package:fase/models/registration_data.dart';
import 'package:fase/models/student_data.dart';
import 'package:fase/string_resource.dart';
import 'package:fase/utils/api.dart';
import 'package:fase/utils/location_permission.dart';
import 'package:fase/utils/startup_check.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class HomePage extends StatefulWidget {
@override
Expand All @@ -15,12 +18,6 @@ class _HomePageState extends State<HomePage> {
void initState() {
super.initState();
LocationPermission(context).requestPermisson();
// Globals().secureStorage.containsKey(key: StringResources.serverKey);
// CourseApi().getCourses();
// RegistrationAPi().postRegistration();
// RegistrationAPi().getRegistration();
// AttendanceAPi().getAttendance();
// AttendanceAPi().postAttendance();
}

@override
Expand All @@ -29,19 +26,61 @@ class _HomePageState extends State<HomePage> {
appBar: AppBar(
title: Text(StringResources.fase),
),
// body: Center(
// child: ,
// ),
body: Center(
child: FutureBuilder<bool>(
future:
Globals.secureStorage.containsKey(key: StringResources.serverKey),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.hasData) {
if (snapshot.data) return Text("Registered");
}
return _register();
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
// http.Response response = await http.get(
// 'https://fase.centralindia.cloudapp.azure.com/course/?format=json');
// print("Response: ${response.body}");
// print("Response: ${response.statusCode}");
CourseApi().getCourses();
},
onPressed: () async {},
child: Icon(Icons.wifi),
),
);
}

Widget _register() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(StringResources.registerPrompt),
SizedBox(height: 20),
ElevatedButton(
child: Text(StringResources.register),
onPressed: () async {
Registration registrationData = Registration(
studentData: StudentData(
instituteEmail: FirebaseAuth.instance.currentUser.email,
googleUid: FirebaseAuth.instance.currentUser.uid,
name: FirebaseAuth.instance.currentUser.displayName,
),
deviceId: Globals.androidId,
isPhysical: Globals.isPhysicalDevice,
isRooted: await StartupCheck().isRooted(),
fingerprint: Globals.fingerprint,
sdkInt: Globals.sdk,
appVersionString: Globals.version,
appBuildNumber: Globals.buildNumber,
ssid: Globals.wifiName,
bssid: Globals.wifiBSSID,
localIp: Globals.wifiIP,
);
Registration registration =
await RegistrationAPi.postRegistration(registrationData);
setState(() {
Globals.secureStorage.write(
key: StringResources.serverKey,
value: registration.serverKey);
});
},
),
],
);
}
}
28 changes: 14 additions & 14 deletions lib/utils/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import 'dart:convert';
import 'package:fase/models/attendance_data.dart';
import 'package:fase/models/course.dart';
import 'package:fase/models/registration_data.dart';
import 'package:fase/models/student_data.dart';
import 'package:http/http.dart' as http;

const String BASE_URL = 'https://fase.centralindia.cloudapp.azure.com/';
const format = '?format=json';

class CourseApi {
static const endpoint = 'course/';
static const _endpoint = 'course/';

Future<List<Course>> getCourses() async {
http.Response response = await http.get(BASE_URL + endpoint + format);
static Future<List<Course>> getCourses() async {
http.Response response = await http.get(BASE_URL + _endpoint + format);
List<Course> courses = [];
json.decode(response.body).forEach((courseJson) {
courses.add(Course.fromJson(courseJson));
Expand All @@ -23,7 +22,7 @@ class CourseApi {
}

class RegistrationAPi {
static const endpoint = 'registration/';
static const _endpoint = 'registration/';

// static RegistrationData _registrationData = RegistrationData(
// studentData: StudentData(
Expand All @@ -41,9 +40,10 @@ class RegistrationAPi {
// localIp: 'localIp',
// );

Future<Registration> postRegistration(Registration registrationData) async {
static Future<Registration> postRegistration(
Registration registrationData) async {
http.Response response = await http.post(
BASE_URL + endpoint,
BASE_URL + _endpoint,
body: registrationData.toRawJson(),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
Expand All @@ -53,8 +53,8 @@ class RegistrationAPi {
return data;
}

Future<List<Registration>> getRegistration() async {
http.Response response = await http.get(BASE_URL + endpoint + format);
static Future<List<Registration>> getRegistration() async {
http.Response response = await http.get(BASE_URL + _endpoint + format);
List<Registration> registration = [];
json.decode(response.body).forEach((registrationJson) {
registration.add(Registration.fromJson(registrationJson));
Expand All @@ -64,7 +64,7 @@ class RegistrationAPi {
}

class AttendanceAPi {
static const endpoint = 'attendance/';
static const _endpoint = 'attendance/';

// static Attendance _attendanceData = Attendance(
// studentData: StudentData(
Expand All @@ -90,9 +90,9 @@ class AttendanceAPi {
// serverKey: "366f2a61058b6e49cc3c3b49ff6ffd0d175c33f3",
// );

Future<Attendance> postAttendance(Attendance attendanceData) async {
static Future<Attendance> postAttendance(Attendance attendanceData) async {
http.Response response = await http.post(
BASE_URL + endpoint,
BASE_URL + _endpoint,
body: attendanceData.toRawJson(),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
Expand All @@ -102,8 +102,8 @@ class AttendanceAPi {
return data;
}

Future<List<Attendance>> getAttendance() async {
http.Response response = await http.get(BASE_URL + endpoint + format);
static Future<List<Attendance>> getAttendance() async {
http.Response response = await http.get(BASE_URL + _endpoint + format);
List<Attendance> attendance = [];
json.decode(response.body).forEach((attendanceJson) {
attendance.add(Attendance.fromJson(attendanceJson));
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/startup_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StartupCheck {
/// Checks if the device is an actual device or an emulator.
/// Emulators cannot be allowed for registering attendance.
bool isPhysicalDevice() {
return Globals().isPhysicalDevice;
return Globals.isPhysicalDevice;
}

/// Checks if the device is rooted. Rooted devices are less trust-worthy and
Expand Down Expand Up @@ -56,9 +56,9 @@ class StartupCheck {
await this.isLocationEnabled()) {
// check for harcoded BSSID and SSID here
// TODO: add wifi verification here
Globals().wifiBSSID;
Globals().wifiName;
Globals().wifiIP;
Globals.wifiBSSID;
Globals.wifiName;
Globals.wifiIP;
throw UnimplementedError();
} else {
return false;
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: "direct main"
description:
name: fluttertoast
url: "https://pub.dartlang.org"
source: hosted
version: "7.1.6"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
json_annotation: ^3.1.1
http: ^0.12.2
flutter_secure_storage: ^3.3.5
fluttertoast: ^7.1.6

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit b01864a

Please sign in to comment.