forked from baimamboukar/voting_system_app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e60ab53
commit 42ba1b4
Showing
41 changed files
with
1,544 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "electchain", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "623103710021", | ||
"project_id": "electchain-8ea68", | ||
"storage_bucket": "electchain-8ea68.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:623103710021:android:ad74a9bd02f94be223642c", | ||
"android_client_info": { | ||
"package_name": "com.bravechains.electchain" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "623103710021-p6hqpduo0sb1q1s2vkfgr601am4odvoc.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyCvm74iYeDPCCIwhrznP-yQrirnB5RAbsI" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "623103710021-p6hqpduo0sb1q1s2vkfgr601am4odvoc.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:Electchain/services/database.dart'; | ||
import 'package:Electchain/controllers/controllers.dart'; | ||
|
||
class AddCandidateBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
getData() async { | ||
var data; | ||
await DataBase() | ||
.candidatesStream(Get.find<UserController>().user.id, | ||
Get.arguments[0].id.toString()) | ||
.then((election) { | ||
data = election.data()['options']; | ||
Get.find<ElectionController>().currentElection.options = data; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:Electchain/controllers/controllers.dart'; | ||
import 'package:get/get.dart'; | ||
|
||
class AuthBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.lazyPut<AuthController>(() => AuthController()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import 'package:Electchain/screens/screens.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:Electchain/models/add_vote_option.dart'; | ||
import 'package:Electchain/models/models.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
|
||
class VoteOptionController extends GetxController { | ||
final candidates = List<VoteOption>().obs; | ||
//addOption | ||
addOption(name, desc) { | ||
candidates.add(VoteOption(name: name, description: desc)); | ||
class CandidateController extends GetxController { | ||
CandidateModel fromDocumentSnapshot(DocumentSnapshot doc) { | ||
CandidateModel _candidate = CandidateModel(); | ||
_candidate.name = doc['name']; | ||
_candidate.description = doc['description']; | ||
return _candidate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:Electchain/models/models.dart'; | ||
import 'package:Electchain/services/database.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:Electchain/controllers/controllers.dart'; | ||
|
||
class AuthController extends GetxController { | ||
FirebaseAuth _auth = FirebaseAuth.instance; | ||
Rx<User> _firebaseUser = Rx<User>(); | ||
var usercontroller = Get.put(UserController()); | ||
|
||
String get user => _firebaseUser.value?.email; | ||
|
||
@override | ||
// ignore: must_call_super | ||
void onInit() { | ||
_firebaseUser.bindStream(_auth.authStateChanges()); | ||
} | ||
|
||
void createUser(name, phoneNumber, email, password) async { | ||
try { | ||
var _authResult = await _auth.createUserWithEmailAndPassword( | ||
email: email, password: password); | ||
|
||
//Create a user in firestore | ||
UserModel _user = UserModel( | ||
id: _authResult.user.uid, | ||
name: name, | ||
phoneNumber: phoneNumber, | ||
email: email); | ||
if (await DataBase().createNewUser(_user)) { | ||
Get.find<UserController>().user = _user; | ||
Get.back(); | ||
} | ||
} catch (err) { | ||
Get.snackbar('Processing Error', err.message); | ||
} | ||
} | ||
|
||
void loginUser(String email, String password) async { | ||
try { | ||
var _authResult = await _auth.signInWithEmailAndPassword( | ||
email: email, password: password); | ||
|
||
Get.find<UserController>().user = | ||
await DataBase().getUser(_authResult.user.uid); | ||
print(await DataBase().getUser(_authResult.user.uid)); | ||
Get.back(); | ||
} catch (err) { | ||
Get.snackbar('Processing Error', err.message); | ||
} | ||
} | ||
|
||
void signOut() { | ||
try { | ||
_auth.signOut(); | ||
Get.find<UserController>().clear(); | ||
} catch (err) { | ||
Get.snackbar('Processing Error', err.message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'add_vote_option.dart'; | ||
export 'auth_controller.dart'; | ||
export 'user_controller.dart'; | ||
export 'election_controller.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:Electchain/models/models.dart'; | ||
import 'package:Electchain/services/database.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
|
||
//Function to generate the vote access code as a mix of number and sting | ||
|
||
const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'; | ||
Random _random = Random(); | ||
|
||
String getRandomString(int length) => String.fromCharCodes(Iterable.generate( | ||
length, (_) => _chars.codeUnitAt(_random.nextInt(_chars.length)))); | ||
|
||
class ElectionController extends GetxController { | ||
Rx<ElectionModel> _electionModel = ElectionModel().obs; | ||
ElectionModel currentElection = ElectionModel(); | ||
|
||
ElectionModel get election => _electionModel.value; | ||
|
||
set user(ElectionModel value) => this._electionModel.value = value; | ||
|
||
bool endElection() { | ||
_electionModel.value.endDate = DateTime.now().toString(); | ||
return true; | ||
} | ||
|
||
createElection(name, description, owner, startDate, endDate) { | ||
ElectionModel election = ElectionModel( | ||
accessCode: getRandomString(6), | ||
name: name, | ||
description: description, | ||
owner: owner, | ||
startDate: startDate, | ||
endDate: endDate); | ||
DataBase().createElection(election); | ||
} | ||
|
||
candidatesStream(String _uid, String _electionId) { | ||
DataBase().candidatesStream(_uid, _electionId); | ||
} | ||
|
||
copyAccessCode() { | ||
//how to copy to the clipboard using dart | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:Electchain/models/models.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
|
||
class UserController extends GetxController { | ||
Rx<UserModel> _userModel = UserModel().obs; | ||
|
||
UserModel get user => _userModel.value; | ||
set user(UserModel value) => this._userModel.value = value; | ||
void clear() { | ||
_userModel.value = UserModel(); | ||
} | ||
|
||
UserModel fromDocumentSnapshot(DocumentSnapshot doc) { | ||
UserModel _user = UserModel(); | ||
_user.id = doc.id; | ||
_user.email = doc['email']; | ||
_user.name = doc['name']; | ||
_user.phoneNumber = doc['phonenumber']; | ||
return _user; | ||
} | ||
} |
Oops, something went wrong.