-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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']}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return render(request, 'take_image.html') | ||
| else: | ||
| form = RegForm() | ||
|
|
@@ -50,7 +50,7 @@ def logoutview(request): | |
| return HttpResponseRedirect(reverse('indexview')) | ||
|
|
||
|
|
||
| def save_image ( request ): | ||
| def save_image( request ): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if request.method != 'POST': | ||
| return HttpResponseRedirect(reverse('signupview')) | ||
|
|
||
|
|
@@ -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') | ||
|
|
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| t=threading.Thread(target=encryption, args=(filename, encno)) | ||
| t.start() | ||
| return True | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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}) | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| myuser.objects.filter( Username = user).update(history = newhistory) | ||
| messages.success(request, "File Uploaded Successfully") | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if(encdec . decryption ( file_path , enckey )): | ||
| with open(file_path, 'rb') as fh: | ||
| response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel") | ||
|
|
@@ -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: | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def clear_history(request): | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def profile(request): | ||
| if request.method == 'POST': | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
RegForm.clean_Confirm_Passwordrefactored with the following changes:move-assign)swap-if-else-branches)remove-unnecessary-else)