Skip to content

Commit

Permalink
Fix mongo; work on auth issues for v1 timer fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLockwood committed Jan 2, 2016
1 parent 55bc34e commit bd62d11
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
3 changes: 2 additions & 1 deletion docs/hours.John.json
Expand Up @@ -112,5 +112,6 @@
{"date": "12/24/2015", "hours": 0.3, "description": "Remove Marshmallow - deprecate HARD"},
{"date": "12/27/2015", "hours": 3.2, "description": "Continue timer v1 work including lots of work on formatters, preliminary post working."},
{"date": "12/28/2015", "hours": 2.8, "description": "Timer v1 API - CRUD methods implemented, addtional testing."},
{"date": "01/01/2016", "hours": 2.6, "description": "V1 Timer work - refactor Timer into new RestfulResource class which can serve as the basis of our work going forward"}
{"date": "01/01/2016", "hours": 2.6, "description": "V1 Timer work - refactor Timer into new RestfulResource class which can serve as the basis of our work going forward"},
{"date": "01/02/2016", "hours": 1.4, "description": "Fix mongo; work on auth issues for v1 timer fixes #10"}
]}
6 changes: 3 additions & 3 deletions goalboost/blueprints/api/timer_resource.py
@@ -1,16 +1,16 @@
from flask import jsonify, request, Response
import http.client
from flask import abort

from flask.ext.login import current_user

from goalboost.blueprints.api.restful_resource import RestfulResource
from goalboost.blueprints.auth.token_auth import httpBasicAuth
from goalboost.model.timer_models import TimerDAO, TimerFormatter, TimerEntity


class TimerResource(RestfulResource):

@httpBasicAuth.login_required
def get_one(self, id):
# def timer_get_one(timer_id):
dao = TimerDAO()
timer = dao.get(id)
as_dict = TimerFormatter().model_to_dict(timer)
Expand Down
16 changes: 6 additions & 10 deletions goalboost/blueprints/auth/token_auth.py
Expand Up @@ -12,13 +12,9 @@ def verify_password(username, password):
user = User.verify_auth_token(password)
if not user:
return False

# Adding these lines will (correctly -- was tested at one point) mean "current_user" can be used from
# contexts that need it, but leaving them off for now as it is not a good design for a restful API,
# which verify_password is designed to support
#
# user.authenticated = True
# login_user(user, remember=True)

return True

# The next two lines set the current user correctly for the token case, on a
# per-request basis, Tthe user still needs to re-authenticate with each
# request, so the RESTful statelessness is implemented correctly.
user.authenticated = True
login_user(user, remember=True)
return True
41 changes: 38 additions & 3 deletions goalboost/model/timer_models.py
Expand Up @@ -126,14 +126,49 @@ class LocalTicker():
TimeDog is a better name.
'''
class RemoteTicker(object):
startTime = None
seconds = 0
is_running = False

def __init__(self, startTime=None):
if startTime is None:
self.startTime = datetime.utcnow()
else:
self.startTime = startTime

def start(self):
pass
self.startTime = datetime.utcnow()
self.is_running = True


def stop(self):
pass
self.seconds = self.seconds + self.current_elapsed()
self.is_running = False


def current_elapsed(self):
# current_elapsed is only diff between lastRestart and now if we're running.
# If we're stopped then the total should haved been added to the seconds field
# and current_elapsed is 0
if not self.is_running:
return 0
now = datetime.utcnow()
then = self.startTime
return int((now - then).total_seconds())

def total_elapsed(self):
return self.current_elapsed() + self.seconds

def counter(self):
pass
return self.fmt_seconds(self.total_elapsed())

def fmt_seconds(self, seconds):
hrs = int(seconds/3600)
mins_secs = seconds % 3600
mins = int(mins_secs / 60)
secs = mins_secs % 60
return "{:0>2}:{:0>2}:{:0>2}".format(hrs, mins, secs)


class TimerFormatter(ModelFormatter):
pass
4 changes: 2 additions & 2 deletions manage.py
Expand Up @@ -3,7 +3,7 @@

from goalboost.model import db
from goalboost import app
from goalboost.model.timer_models import TimerEntity
from goalboost.model.timer_models import TimerEntity, RemoteTicker
from goalboost.model.legacy_timer_models import LegacyTimer

manager = Manager(app)
Expand All @@ -14,7 +14,7 @@ def runserver_debug():

@manager.shell
def make_shell_context():
return dict(app=app, db=db, Timer=LegacyTimer, TimerEntity=TimerEntity)
return dict(app=app, db=db, Timer=LegacyTimer, TimerEntity=TimerEntity, Timer2=RemoteTicker)

manager.add_command("shell", Shell(make_context=make_shell_context))

Expand Down

0 comments on commit bd62d11

Please sign in to comment.