Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions home/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ def clean_Email(self):
def clean_Confirm_Password(self):
pass1 = self.cleaned_data['Password']
pass2 = self.cleaned_data['Confirm_Password']
MAX_LEN = 8
if pass1 and pass2:
if pass1 != pass2:
raise forms.ValidationError("Two passwords not same")
else:
if len(pass1) < MAX_LEN:
raise forms.ValidationError("Password should be %d characters" %MAX_LEN)
if pass1.isdigit():
raise forms.ValidationError("Password should not all numeric")
MAX_LEN = 8
if len(pass1) < MAX_LEN:
raise forms.ValidationError("Password should be %d characters" %MAX_LEN)
if pass1.isdigit():
raise forms.ValidationError("Password should not all numeric")
Comment on lines -39 to +46
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RegForm.clean_Confirm_Password refactored with the following changes:


40 changes: 20 additions & 20 deletions home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def signupview(request):
if form.is_valid():
form.save()
request.session['username'] = form.cleaned_data['Username']
system('mkdir media\{}'.format(request.session['username']))
system(f"mkdir media\\{request.session['username']}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function signupview refactored with the following changes:

return render(request, 'take_image.html')
else:
form = RegForm()
Expand All @@ -50,7 +50,7 @@ def logoutview(request):
return HttpResponseRedirect(reverse('indexview'))


def save_image ( request ):
def save_image( request ):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function save_image refactored with the following changes:

if request.method != 'POST':
return HttpResponseRedirect(reverse('signupview'))

Expand All @@ -62,60 +62,60 @@ def save_image ( request ):

if request.resolver_match.url_name == 'signup_save_img':
user = request.session['username']
with open(r'images/train/{}.jpg'.format(user), 'wb') as f:
with open(f'images/train/{user}.jpg', 'wb') as f:
f.write(image_data)
with open(r'user/static/img/{}.jpg'.format(user), 'wb') as f:
with open(f'user/static/img/{user}.jpg', 'wb') as f:
f.write(image_data)

if face_validation(r'images/train/{}.jpg'.format(user)):
if face_validation(f'images/train/{user}.jpg'):
del user
return render(request, 'index.html', {'mess': 'success'})
else:
system ( r'del images\train\{}.jpg'.format(user))
system(f'del images\\train\\{user}.jpg')
messages.error(request, "We cann't not recognise your face")
messages.error(request, "Please take a another pic having your face only...")
return render(request, 'take_image.html')

if request.resolver_match.url_name == 'signin_save_img':
user = request.session['username']
with open(r'images/test/{}.jpg'.format(user), 'wb') as f:
with open(f'images/test/{user}.jpg', 'wb') as f:
f.write(image_data)

if face_validation(r'images/test/{}.jpg'.format(user)):
known_face = r'images/train/{}.jpg'.format(user)
unknown_face = r'images/test/{}.jpg'.format(user)
if face_validation(f'images/test/{user}.jpg'):
known_face = f'images/train/{user}.jpg'
unknown_face = f'images/test/{user}.jpg'

if match_face(known_face, unknown_face):
system(r'del images\test\{}.jpg'.format(user))
system(f'del images\\test\\{user}.jpg')
return HttpResponseRedirect(reverse('dashboard'))
else:
system(r'del images\test\{}.jpg'.format(user))
system(f'del images\\test\\{user}.jpg')
messages.error(request, "Face does not match...")
return render(request, 'take_image.html')
else:
system(r'del images\test\{}.jpg'.format(user))
system(f'del images\\test\\{user}.jpg')
messages.error(request, "We cann't not recognise your face")
messages.error(request, "Please take a another pic having your face only...")
return render(request, 'take_image.html')

if request.resolver_match.url_name == 'changepass_save_img':
user = request.session['username']
with open(r'images/test/{}.jpg'.format(user), 'wb') as f:
with open(f'images/test/{user}.jpg', 'wb') as f:
f.write(image_data)

if face_validation(r'images/test/{}.jpg'.format(user)):
known_face = r'images/train/{}.jpg'.format(user)
unknown_face = r'images/test/{}.jpg'.format(user)
if face_validation(f'images/test/{user}.jpg'):
known_face = f'images/train/{user}.jpg'
unknown_face = f'images/test/{user}.jpg'

if match_face(known_face, unknown_face):
system(r'del images\test\{}.jpg'.format(user))
system(f'del images\\test\\{user}.jpg')
return HttpResponseRedirect(reverse('updatepass'))
else:
system(r'del images\test\{}.jpg'.format(user))
system(f'del images\\test\\{user}.jpg')
messages.error(request, "Face does not match...")
return render(request, 'take_image.html')
else:
system(r'del images\test\{}.jpg'.format(user))
system(f'del images\\test\\{user}.jpg')
messages.error(request, "We cann't not recognise your face")
messages.error(request, "Please take a another pic having your face only...")
return render(request, 'take_image.html')
Expand Down
23 changes: 9 additions & 14 deletions user/encdec.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import threading
import base64

def encryption( filename , encno ) :
fd = open( filename , 'rb')
data = fd . read()
fd . close()

def encryption( filename , encno ):
with open( filename , 'rb') as fd:
data = fd . read()
data = chr( int(encno)) + data [: : -1 ].decode ( 'latin-1')
data = data . encode ( 'latin-1', "ignore")
data = base64 . b64encode ( data )

fd = open( filename , 'wb')
fd . write( data )
fd . close()
with open( filename , 'wb') as fd:
fd . write( data )
Comment on lines -4 to +12
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function encryption refactored with the following changes:

return 'Success fully encrypted with key '


def decryption(filename, decno):
fd = open(filename, 'rb')
data= fd. read()
fd . close()
with open(filename, 'rb') as fd:
data= fd. read()
data = base64.b64decode(data)
encno = data[0]
if chr(encno) == chr(int(decno)):
data = data.decode('latin-1')
data = data[:0:-1].encode('latin-1')
fd = open(filename, 'wb')
fd . write(data)
fd . close()
with open(filename, 'wb') as fd:
fd . write(data)
Comment on lines -20 to +25
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function decryption refactored with the following changes:

t=threading.Thread(target=encryption, args=(filename, encno))
t.start()
return True
Expand Down
88 changes: 44 additions & 44 deletions user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ def dashboard(request):
if request.method == 'POST':
filename = request.POST['filename']
enckey = request.POST['enckey']
file_path = 'media\{}\{}'.format(request.session['username'], filename)
fd = open(file_path, 'rb')
data = fd.read()
fd.close()
file_path = f"media\\{request.session['username']}\\{filename}"
with open(file_path, 'rb') as fd:
data = fd.read()
data = base64.b64decode(data)
if chr(data[0]) == chr(int(enckey)):
os.system('del "{}"'.format(file_path))
os.system(f'del "{file_path}"')
Comment on lines -19 to +24
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function dashboard refactored with the following changes:

messages.success(request, "File deleted successfully...")
else:
messages.error(request, "Enc Key mismatch. Cann't delete file...")
try:
user = request.session['username']
except KeyError:
return HttpResponseRedirect(reverse('indexview'))
path = 'media/' + user
path = f'media/{user}'
filelist = os.listdir(path)
filestorage = counter(filelist)
return render(request, 'dashboard.html', {'list': filelist, 'filestorage':filestorage})
Expand All @@ -41,17 +40,22 @@ def upload(request):
user = request.session['username']
myfile = request.FILES['myfile']
fs = FileSystemStorage()
if os.path.exists('media/{}/{}'.format(user, myfile.name)):
x = os.getcwd() +'\\media\\{}\\{}'.format(user, myfile.name)
if os.path.exists(f'media/{user}/{myfile.name}'):
x = os.getcwd() + f'\\media\\{user}\\{myfile.name}'
os.system('del "' + x + '"')
filename = fs.save("media/{}/{}".format(user, myfile.name), myfile)
filename = fs.save(f"media/{user}/{myfile.name}", myfile)
encdec.encryption( filename , request.POST ['enckey'])
rec = myuser.objects.filter( Username = user)

if rec[0].history == None or rec[0].history == [['None']]:
newhistory = myfile.name +' saved on' + str (time.ctime())
if rec[0].history is None or rec[0].history == [['None']]:
newhistory = f'{myfile.name} saved on{str(time.ctime())}'
else:
newhistory = myfile.name +' saved on' + str(time.ctime ()) + '\n' + rec[0].history
newhistory = (
f'{myfile.name} saved on{str(time.ctime ())}'
+ '\n'
+ rec[0].history
)

Comment on lines -44 to +58
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function upload refactored with the following changes:


myuser.objects.filter( Username = user).update(history = newhistory)
messages.success(request, "File Uploaded Successfully")
Expand All @@ -67,7 +71,7 @@ def download(request):
if request.method == 'POST':
filename = request.POST['filename']
enckey = request.POST['enckey']
file_path = 'media/{}/{}'.format(request.session['username'], filename)
file_path = f"media/{request.session['username']}/{filename}"
Comment on lines -70 to +74
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function download refactored with the following changes:

if(encdec . decryption ( file_path , enckey )):
with open(file_path, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
Expand All @@ -76,9 +80,9 @@ def download(request):
else:
messages.error(request, 'Invalid encryption key. Please provide a right key...')
return HttpResponseRedirect(reverse('download'))
elif 'username' in request . session :
elif 'username' in request . session:
user = request.session['username']
path = 'media/' + user
path = f'media/{user}'
filelist = os.listdir(path)
return render (request , 'download.html', {'list' : filelist})
else:
Expand All @@ -87,22 +91,20 @@ def download(request):


def history(request):
if 'username' in request.session:
rec = myuser.objects.filter(Username = request.session['username'])
history = rec[0].history
if 'username' not in request.session:
return HttpResponseRedirect(reverse('indexview'))
rec = myuser.objects.filter(Username = request.session['username'])
history = rec[0].history

if history != None and history != '':
history = history.split('\n')
history = [ x.split ('saved on') for x in history ]
if history in [None, '']:
return render ( request, 'history.html')
history = history.split('\n')
history = [ x.split ('saved on') for x in history ]

for x in history :
x [ 0 ] = x[ 0 ]. replace ( request.session['username'] +'/', '')
for x in history :
x [ 0 ] = x[ 0 ]. replace ( request.session['username'] +'/', '')

return render (request , 'history.html', {'history': history})
else:
return render ( request, 'history.html')
else :
return HttpResponseRedirect(reverse('indexview'))
return render (request , 'history.html', {'history': history})
Comment on lines -90 to +107
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function history refactored with the following changes:



def clear_history(request):
Expand Down Expand Up @@ -130,21 +132,20 @@ def chngpass(request):


def sendmail(request):
if 'username' in request.session:
if request.method == 'POST':
to_mail = request.POST['tomail']
subject = request.POST['subject']
message = request.POST['mailbody']
email = EmailMessage(subject=subject,body=message,to=[to_mail])
try:
email.send()
except:
messages.error(request,"Mail can not send")
else:
messages.success(request, "The Email has successfully sent")
return HttpResponseRedirect(reverse('dashboard'))
else :
if 'username' not in request.session:
return HttpResponseRedirect(reverse('indexview'))
if request.method == 'POST':
to_mail = request.POST['tomail']
subject = request.POST['subject']
message = request.POST['mailbody']
email = EmailMessage(subject=subject,body=message,to=[to_mail])
try:
email.send()
except:
messages.error(request,"Mail can not send")
else:
messages.success(request, "The Email has successfully sent")
return HttpResponseRedirect(reverse('dashboard'))
Comment on lines -133 to +148
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sendmail refactored with the following changes:


def profile(request):
if request.method == 'POST':
Expand Down Expand Up @@ -181,5 +182,4 @@ def counter(path):
mCount = len([file for mEx in music for file in path if file.lower().endswith(mEx)])
vCount = len([file for vEx in video for file in path if file.lower().endswith(vEx)])

list = {'image':imgCount, 'document':docCount, 'video':vCount, 'music':mCount}
return list
return {'image':imgCount, 'document':docCount, 'video':vCount, 'music':mCount}
Comment on lines -184 to +185
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function counter refactored with the following changes: