-
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
8d498c0
commit 80d8fb7
Showing
11 changed files
with
560 additions
and
0 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,5 @@ | ||
const Migrations = artifacts.require("Migrations"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Migrations); | ||
}; |
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,5 @@ | ||
var Election = artifacts.require("./Election.sol"); | ||
|
||
module.exports = function(deployer) { | ||
deployer.deploy(Election); | ||
}; |
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,53 @@ | ||
pragma solidity 0.4.24; | ||
|
||
contract Election { | ||
struct Candidate { | ||
uint id; | ||
string name; | ||
uint voteCount; | ||
} | ||
bool goingon = true; | ||
mapping(address => bool) public voters; | ||
mapping(uint => Candidate) public candidates; | ||
uint public candidatesCount; | ||
|
||
event votedEvent ( | ||
uint indexed _candidateId | ||
); | ||
|
||
constructor () public { | ||
addCandidate("Candidate 1"); | ||
addCandidate("Candidate 2"); | ||
addCandidate("Candidate 3"); | ||
addCandidate("Candidate 4"); | ||
addCandidate("Candidate 5"); | ||
addCandidate("Candidate 6"); | ||
addCandidate("Candidate 7"); | ||
addCandidate("Candidate 8"); | ||
addCandidate("Candidate 9"); | ||
addCandidate("Candidate 10"); | ||
} | ||
|
||
function addCandidate (string memory _name) private { | ||
candidatesCount ++; | ||
candidates[candidatesCount] = Candidate(candidatesCount, _name, 0); | ||
} | ||
|
||
function end () public { | ||
goingon = false; | ||
} | ||
|
||
function vote (uint _candidateId) public { | ||
require(!voters[msg.sender],"Already voted"); | ||
|
||
require(_candidateId > 0 && _candidateId <= candidatesCount,"Invalid candidate"); | ||
|
||
require(goingon,"Election ended"); | ||
|
||
voters[msg.sender] = true; | ||
|
||
candidates[_candidateId].voteCount ++; | ||
|
||
emit votedEvent(_candidateId); | ||
} | ||
} |
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,23 @@ | ||
pragma solidity 0.4.24; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<meta charset="UTF-8"> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway"> | ||
<style> | ||
body, html {font-family: "Raleway", sans-serif; height: 100%} | ||
p {font-size: 400%} | ||
button { | ||
background-color: rgb(19, 141, 255); /* Green */ | ||
border: none; | ||
color: white; | ||
padding: 15px 32px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
margin: 4px 2px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19); | ||
} | ||
|
||
</style> | ||
<body> | ||
<div style="height: 30%"></div> | ||
<center><p>{{message}} | ||
{% if code==200 %} | ||
<span style='color: green;'>✔</span> | ||
{% else %} | ||
<span style='color: red;'>✖</span> | ||
{% endif %} | ||
</p> | ||
<button value="Back" onClick="window.location.href=window.location.href">back</button> | ||
</center> | ||
</body> | ||
</html> |
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,75 @@ | ||
from flask import Flask, render_template, flash, request, session, redirect, url_for | ||
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField | ||
import requests; | ||
import json; | ||
|
||
backend_addr = "https://election-backend.azurewebsites.net/" | ||
|
||
app = Flask(__name__) | ||
app.secret_key = 'i love white chocolate' | ||
|
||
@app.route("/", methods=['GET', 'POST']) | ||
def home(): | ||
return redirect(url_for('verify')) | ||
|
||
@app.route("/results", methods=['GET']) | ||
def results(): | ||
try: | ||
resp = requests.get(backend_addr+'results') | ||
if(resp.status_code!=200): | ||
return render_template('confirmation.html',message=resp.text),resp.status_code | ||
result = eval(resp.text) | ||
print(result) | ||
result.sort(reverse=True,key=lambda x: x[2]) | ||
return render_template('results.html',result=result) | ||
except: | ||
return render_template('confirmation.html',message="Error processing"),500 | ||
|
||
@app.route("/verify", methods=['GET', 'POST']) | ||
def verify(): | ||
try: | ||
resp = requests.get(backend_addr+'isended') | ||
if(not eval(resp.text)): | ||
if request.method == 'POST': | ||
aid = request.form['aid'] | ||
bio = request.form['biometric'] | ||
resp = requests.get(backend_addr+'number_of_users') | ||
number_of_accounts = int(resp.text) | ||
if(bio == 'yes' and aid.isdigit() and int(aid)<=number_of_accounts): | ||
session['verified'] = True | ||
session['aid'] = int(aid) | ||
return redirect(url_for('vote')) | ||
return render_template('verification.html') | ||
else: | ||
return render_template('confirmation.html',message="Election ended",code=400),400 | ||
except: | ||
return render_template('confirmation.html',message="Error processing"),500 | ||
|
||
@app.route("/vote", methods=['GET', 'POST']) | ||
def vote(): | ||
resp = requests.get(backend_addr+'isended') | ||
if(not eval(resp.text)): | ||
if('verified' in session): | ||
resp = requests.get(backend_addr+'candidates_list') | ||
candidates = eval(resp.text) | ||
print(candidates) | ||
candidates1 = candidates[:int(len(candidates)/2)] | ||
candidates2 = candidates[int(len(candidates)/2):] | ||
if request.method == 'POST': | ||
aid = session['aid'] | ||
session.pop('verified') | ||
session.pop('aid') | ||
candidate = request.form['candidate'] | ||
cid = candidates.index(candidate)+1 | ||
print(cid) | ||
resp = requests.post(backend_addr,json.dumps({'aadhaarID':aid,'candidateID':cid})) | ||
print(resp) | ||
return render_template('confirmation.html',message=resp.text,code=resp.status_code),resp.status_code | ||
return render_template('vote.html',candidates1=candidates1,candidates2=candidates2),200 | ||
else: | ||
return redirect(url_for('verify')) | ||
else: | ||
return render_template('confirmation.html',message="Election ended",code=400),400 | ||
|
||
if __name__ == '__main__': | ||
app.run(host="0.0.0.0" ,port=80, debug = True) |
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 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
|
||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway"> | ||
<style> | ||
table { | ||
font-family: arial, sans-serif; | ||
border-collapse: collapse; | ||
width: 50%; | ||
} | ||
|
||
td, th { | ||
border: 1px solid #dddddd; | ||
text-align: left; | ||
padding: 8px; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: #dddddd; | ||
} | ||
body, html {font-family: "Raleway", sans-serif; height: 100%} | ||
p {font-size: 300%} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<center> | ||
<p>Results</p> | ||
|
||
<table> | ||
<tr> | ||
<th>Candidate ID</th> | ||
<th>Candidate</th> | ||
<th>Votes</th> | ||
</tr> | ||
{% for ele in result %} | ||
<tr> | ||
<td>{{ele[0]}}</td> | ||
<td>{{ele[1]}}</td> | ||
<td>{{ele[2]}}</td> | ||
</tr> | ||
{% endfor%} | ||
</table> | ||
</center> | ||
</body> | ||
</html> |
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,51 @@ | ||
body | ||
{ | ||
background-color: #f7f5f9; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; | ||
|
||
} | ||
label { | ||
display: inline-block; | ||
font-family: sans-serif, Arial; | ||
font-size: 16px; | ||
border: 2px solid #444; | ||
border-radius: 4px; | ||
padding: 1% 1% 1% 1%; | ||
width: 10%; | ||
} | ||
input[type="radio"] { | ||
opacity: 0; | ||
position: fixed; | ||
width: 0; | ||
} | ||
input[type="radio"]:checked + label { | ||
background-color:#bfb; | ||
} | ||
label:hover { | ||
background-color: lightblue; | ||
cursor: pointer; | ||
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19); | ||
} | ||
|
||
input[type="submit"] { | ||
background-color: #4CAF50; /* Green */ | ||
border: none; | ||
color: white; | ||
padding: 15px 32px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
margin: 4px 2px; | ||
cursor: pointer; | ||
} | ||
|
||
input[type="submit"]:hover { | ||
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19); | ||
} | ||
|
||
#submit { | ||
visibility: hidden; | ||
float: left; | ||
border-left: 2%; | ||
} |
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,75 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway"> | ||
<style> | ||
body, html {font-family: "Raleway", sans-serif; height: 100%; padding-left: 0.5%;} | ||
label { | ||
display: inline-block; | ||
font-family: sans-serif, Arial; | ||
font-size: 16px; | ||
border: 2px solid #444; | ||
border-radius: 4px; | ||
padding: 1% 1% 1% 1%; | ||
width: 20%; | ||
} | ||
input[type="radio"] { | ||
opacity: 0; | ||
position: fixed; | ||
width: 0; | ||
} | ||
input[type="radio"]:checked + label { | ||
background-color:#bfb; | ||
} | ||
label:hover { | ||
background-color: lightblue; | ||
cursor: pointer; | ||
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19); | ||
} | ||
|
||
input[type="submit"] { | ||
background-color: #4CAF50; /* Green */ | ||
border: none; | ||
color: white; | ||
padding: 15px 32px; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
margin: 4px 2px; | ||
cursor: pointer; | ||
} | ||
|
||
input[type="submit"]:hover { | ||
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19); | ||
} | ||
|
||
#submit { | ||
visibility: hidden; | ||
float: left; | ||
border-left: 2%; | ||
} | ||
</style> | ||
|
||
<p><span style='font-size: 300%'>Biometric Verification</span></p><br> | ||
|
||
<form action="" method="POST"> | ||
Enter your ID (Aadhaar): | ||
<input name="aid" type="text"><br><br> | ||
|
||
<div> | ||
|
||
<input type="radio" id="biometric_yes" name="biometric" value="yes"> | ||
<label onClick = "(function() {document.getElementById('submit').style.visibility = 'visible';})()" for="biometric_yes">Complete Verification</label><br><br> | ||
|
||
</div> | ||
|
||
<input id = "submit" type="submit" value="Submit"> | ||
|
||
</form> | ||
<br> <br> <br> <br> | ||
Enabled By - <br> | ||
<img src="/static/enabled_by.PNG" height="15%" alt="ENABLED BY"/> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.