Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54d3049
Create LICENSE
adeen-s Mar 30, 2018
8a9a3cb
Fix bug in data retrieval
adeen-s Mar 30, 2018
324b87e
Fix missing name in attendance page
adeen-s Mar 30, 2018
fdb3491
Fix missing comma
adeen-s Mar 30, 2018
76ac547
Refactor and reorganise code as per accepted coding standards
adeen-s Mar 31, 2018
c7a733b
Merge pull request #1 from adeen-s/experimental
adeen-s Mar 31, 2018
3af887f
Remove __pycache__
adeen-s Mar 31, 2018
3ae4287
Update README.md to reflect new method of running the app
adeen-s Mar 31, 2018
6b79978
Update README.md with todos
adeen-s Mar 31, 2018
3a7986b
Implement function to check integrity
adeen-s Apr 1, 2018
615a4d9
Merge branch 'master' into experimental
adeen-s Apr 1, 2018
ebadb55
Merge pull request #2 from adeen-s/experimental
adeen-s Apr 1, 2018
63957e7
Import materializecss
adeen-s Apr 1, 2018
616c4e4
Merge branch 'experimental' of https://github.com/adeen-s/MiniProject…
adeen-s Apr 1, 2018
b204ba7
Merge pull request #3 from adeen-s/experimental
adeen-s Apr 1, 2018
79cf278
Link CSS files to jinja templates
adeen-s Apr 1, 2018
8329d3a
Add CSS to index.html
adeen-s Apr 8, 2018
544070a
Change index.html background
adeen-s Apr 8, 2018
7ea40e7
Change Project title
adeen-s Apr 8, 2018
ed74ace
Add CSS to attendance.html
adeen-s Apr 8, 2018
3e59b3b
Add CSS to attendance.html
adeen-s Apr 8, 2018
0f96d7f
Add CSS to result.html
adeen-s Apr 8, 2018
c170878
Fix name input type in class.html
adeen-s Apr 8, 2018
362a0a3
Add CSS to view.html
adeen-s Apr 8, 2018
2e5c9da
Merge pull request #4 from adeen-s/Css-ify
adeen-s Apr 8, 2018
70c90c1
Remove TODO from README.md
adeen-s Apr 8, 2018
9686cf5
Add Copyright information
adeen-s Apr 22, 2018
41b3b3f
Fix path in the README
adeen-s Apr 22, 2018
472addf
Update Formatting and add GIF to README
adeen-s Apr 23, 2018
d0c97c4
Update result.html
pulkitsoni03 Oct 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Adeen Shukla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
## E-Attendance using *Blockchain*
###### Our project implements an E-Attendance system which stores student attendance data on a blockchain.
---

Mini Project for the 4th semester of MCA 6 years course

![Gif of workflow](https://media.giphy.com/media/mxnAJxpllD9P80hGND/giphy.gif)
#### Introduction
Blockchain is the technology behind cryptocurrencies such as Bitcoin, Ethereum, Litecoin etc.

A blockchain, is a list of records, called blocks, which are linked and secured using cryptography. Each block contains a cryptographic hash of the previous block, a timestamp and transaction data. The data, once entered in a block is immutable due to the way blockchains are designed.

This concept of immutable digital data storage can be used for storing data securely, such as student attendance, medical records, and financial transactions, to prevent tampering with this data.

###### Our project implements an E-Attendance system which stores student attendance data on a blockchain.

#### Disclaimer and assumptions

This project is to be considered as a proof of concept only. As such the basic algorithm behind a blockchain is used which constructs blocks and associates them using their cryptographic hashes. A proof of work or proof of stake algorithm has not been implemented to prevent the need for higher computing resources. Unlike traditional decentralized blockchains, this blockchain works using a centralized flask server to avoid dealing with multiple nodes unnecessarily for now.
Expand Down Expand Up @@ -62,14 +60,13 @@ $ pip install requests
- Open a Terminal
- Navigate to the root folder of the project.
```
$ cd path/to/MiniProject
$ cd path/to/Blockendance
```
- Specify the flask application by adding it to the environment variable.
- Run the python app
```
$ export FLASK_APP=blockchain.py
```
- Run the flask app
```
$ flask run
$ python blockchain.py
```
- Open a web browser and navigate to "http://localhost:5000" to use the application.

#### Copyright and License
Copyright (c) 2018 Adeen Shukla - Released under the MIT License
Binary file removed __pycache__/block.cpython-36.pyc
Binary file not shown.
Binary file removed __pycache__/blockchain.cpython-36.pyc
Binary file not shown.
Binary file removed __pycache__/genesis.cpython-36.pyc
Binary file not shown.
Binary file removed __pycache__/newBlock.cpython-36.pyc
Binary file not shown.
98 changes: 45 additions & 53 deletions blockchain.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,84 @@
# Python module imports
import datetime as dt
import hashlib
from flask import Flask, request, render_template, Response

from genesis import create_genesis_block
from newBlock import next_block
# Importing local functions
from block import *
from genesis import create_genesis_block
from newBlock import next_block, add_block
from getBlock import find_records
from checkChain import check_integrity

# TODO CSS

# Flask declarations
app = Flask(__name__)
response = Response()
response.headers.add('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0')

# Initializing blockchain with the genesis block
blockchain = create_genesis_block()
previous_block = blockchain[0]
data = []

def add_block(form):
global data
global previous_block
data.append([])# TODO retrieve correct records
i = 1
while form.get("roll_no{}".format(i)):
data[len(data) - 1].append(form.get("roll_no{}".format(i)))
i += 1
block_to_add = next_block(previous_block, data)
blockchain.append(block_to_add)
previous_block = block_to_add
print ("Block #{} has been added to the blockchain!".format(block_to_add.index))
print ("Hash: {}\n".format(block_to_add.hash))
print(data)
return "Block #{} has been added to the blockchain!".format(block_to_add.index)

def findRecords(form):
for block in blockchain:
if block.data[0] == form.get("name"):
if block.data[1] == form.get("date"):
if block.data[2] == form.get("course"):
if block.data[3] == form.get("year"):
return data[4]
return -1

# Default Landing page of the app
@app.route('/', methods = ['GET'])
def index():
return render_template("index.html")

@app.route('/view.html', methods = ['GET'])
def view():
return render_template("class.html")

@app.route('/view.html', methods = ['POST'])
def show_records():
data = findRecords(request.form)
if data == -1:
return "Records not found"
return render_template("view.html",
name = request.form.get("name"),
course = request.form.get("course"),
year = request.form.get("year"),
status = data,
number = int(request.form.get("number")),
date = request.form.get("date"))

# Get Form input and decide what is to be done with it
@app.route('/', methods = ['POST'])
def parse_request():
global data
if(request.form.get("name")):
data = []
while len(data) > 0:
data.pop()
data.append(request.form.get("name"))
data.append(str(dt.date.today()))
return render_template("class.html",
name = request.form.get("name"),
date = dt.date.today())

elif(request.form.get("number")):
data = data[0:2]
while len(data) > 2:
data.pop()
data.append(request.form.get("course"))
data.append(request.form.get("year"))
return render_template("attendance.html",
name = data[0],
course = request.form.get("course"),
year = request.form.get("year"),
number = int(request.form.get("number")))
elif(request.form.get("roll_no1")):
data = data[0:4]
return render_template("submitted.html", result = add_block(request.form))
while len(data) > 4:
data.pop()
return render_template("result.html", result = add_block(request.form, data, blockchain))

else:
return "Invalid POST request. This incident has been recorded."

# Show page to get information for fetching records
@app.route('/view.html', methods = ['GET'])
def view():
return render_template("class.html")

# Process form input for fetching records from the blockchain
@app.route('/view.html', methods = ['POST'])
def show_records():
data = []
data = find_records(request.form, blockchain)
if data == -1:
return "Records not found"
return render_template("view.html",
name = request.form.get("name"),
course = request.form.get("course"),
year = request.form.get("year"),
status = data,
number = int(request.form.get("number")),
date = request.form.get("date"))

# Show page with result of checking blockchain integrity
@app.route('/result.html', methods = ['GET'])
def check():
return render_template("result.html", result = check_integrity(blockchain))

# Start the flask app when program is executed
if __name__ == "__main__":
main()
app.run()
8 changes: 8 additions & 0 deletions checkChain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def check_integrity(chain):
for i, block in enumerate(chain):
if i < len(chain) - 1:
print("Checking integrity of block {}".format(i))
if block.hash_block() != chain[i+1].prev_hash:
return ("Chain has been modified at block index {}".format(i))
else:
return ("Chain has not been modified")
11 changes: 11 additions & 0 deletions getBlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def find_records(form, blockchain):
for block in blockchain:
print(block.data)
condition = (block.data[0] == form.get("name") and
block.data[1] == form.get("date") and
block.data[2] == form.get("course") and
block.data[3] == form.get("year") and
len(block.data[4]) == int(form.get("number")))
if condition:
return block.data[4]
return -1
17 changes: 16 additions & 1 deletion newBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
def next_block(last_block, data):
this_index = last_block.index + 1
this_timestamp = dt.datetime.now()
this_data = data
# A one level deep copy of data has been created since data is modified repeatedly
# in the calling function and if data is a direct pointer, it leads to modification
# of old data in the chain.
this_data = data[:]
this_prev_hash = last_block.hash
return Block(this_index, this_timestamp, this_data, this_prev_hash)

def add_block(form, data, blockchain):
data.append([])
i = 1
while form.get("roll_no{}".format(i)):
data[-1].append(form.get("roll_no{}".format(i)))
i += 1
previous_block = blockchain[-1]
block_to_add = next_block(previous_block, data)
blockchain.append(block_to_add)
previous_block = block_to_add
return "Block #{} has been added to the blockchain!".format(block_to_add.index)
21 changes: 21 additions & 0 deletions static/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014-2018 Materialize

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions static/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
max-width: 500px;
margin: auto;
padding-top: 50px;
}
Loading