Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from demonduck/dev
Browse files Browse the repository at this point in the history
Small fixes for big bugs
  • Loading branch information
demonduck authored Sep 13, 2017
2 parents 8d3ad5f + ac5bd96 commit e771d9f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@

# Autodoc settings
autoclass_content = 'class'
autodoc_mock_imports = ['httplib2', 'oauth2client', 'apiclient', 'mongoengine',
'django', 'bson', 'distorm3', 'mongoengine.queryset',
'bson.objectid']
autodoc_mock_imports = ['httplib2', 'oauth2client', 'apiclient',
'django', 'capstone']

class _MyMockModule(sphinx.ext.autodoc._MockModule):
'''Class created to get around autodoc issues with server's dependencies.'''
Expand Down
13 changes: 7 additions & 6 deletions server/first_core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@
from functools import wraps

# Django Modules
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse, HttpRequest
from django.shortcuts import render, redirect
from django.urls import reverse

# FIRST Modules
# TODO: Use DBManager to get user objects and do User operations
from first.settings import CONFIG
from first_core.models import User
from first_core.error import FIRSTError

# Thirdy Party
import httplib2
from oauth2client import client
from apiclient import discovery
from mongoengine.queryset import DoesNotExist



Expand Down Expand Up @@ -118,7 +119,7 @@ class Authentication():
def __init__(self, request):
self.request = request
redirect_uri = request.build_absolute_uri(reverse('www:oauth', kwargs={'service' : 'google'}))
secret = os.environ.get('GOOGLE_SECRET', '/usr/local/etc/google_secret.json')
secret = CONFIG.get('oauth_path', '/usr/local/etc/google_secret.json')
try:
self.flow = {'google' : client.flow_from_clientsecrets(secret,
scope=['https://www.googleapis.com/auth/userinfo.profile',
Expand Down Expand Up @@ -200,7 +201,7 @@ def login_step_2(self, auth_code, url, login=True):

return redirect(url)

except DoesNotExist:
except ObjectDoesNotExist:
self.request.session.flush()
raise FIRSTAuthError('User is not registered.')

Expand Down Expand Up @@ -236,7 +237,7 @@ def register_user(self):
user = None
continue

except DoesNotExist:
except ObjectDoesNotExist:
pass

# Create random 4 digit value for the handle
Expand All @@ -248,7 +249,7 @@ def register_user(self):
user = User.objects.get(handle=handle, number=num)
user = None

except DoesNotExist:
except ObjectDoesNotExist:
user = User(name=name,
email=email,
api_key=api_key,
Expand All @@ -269,5 +270,5 @@ def get_user_data(email):
user = User.objects.get(email=email)
return user

except DoesNotExist:
except ObjectDoesNotExist:
return None
6 changes: 2 additions & 4 deletions server/first_core/dbs/builtin_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
from hashlib import md5

# Third Party Modules
import bson

from django.utils import timezone
from django.core.paginator import Paginator
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
Expand Down Expand Up @@ -161,14 +159,14 @@ def get_function(self, opcodes, architecture, apis, create=False, **kwargs):

try:
function = Function.objects.get(sha256=sha256_hash,
opcodes=bson.Binary(opcodes),
opcodes=opcodes,
architecture=architecture) #,
#apis__api=apis)
except ObjectDoesNotExist:
if create:
# Create function and add it to sample
function = Function.objects.create( sha256=sha256_hash,
opcodes=bson.Binary(opcodes),
opcodes=opcodes,
architecture=architecture)

apis_ = [FunctionApis.objects.get_or_create(x)[0] for x in apis]
Expand Down
2 changes: 1 addition & 1 deletion server/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def profile(request):
if not user:
return redirect(reverse('www:index'))

count = Function.objects(metadata__user=user).count()
count = Function.objects.filter(metadata__user=user).count()
data = {'title' : 'Profile',
'user' : user.dump(True),
'metadata_count' : count}
Expand Down

0 comments on commit e771d9f

Please sign in to comment.