Skip to content

Commit

Permalink
consume a bucketlist api with react-redux
Browse files Browse the repository at this point in the history
  • Loading branch information
Judy Njangi committed Nov 21, 2017
1 parent 0a99e88 commit cb71adb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions bucketlist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api
from configsettings.config import config
from flask_cors import CORS

db = SQLAlchemy()



def create_app(configuration):
app = Flask(__name__)
app.config.from_object(config[configuration])
db.app = app
db.init_app(app)
CORS(app)

return app

Expand Down
15 changes: 9 additions & 6 deletions bucketlist/resources/user_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from bucketlist.resources.models import Users, db
from bucketlist.functionalities.permissions import unauthorized
import re


class Register(Resource):
Expand All @@ -16,9 +17,9 @@ def post(self):
required=True,
help='Provide a username')
parser.add_argument('email',
type=inputs.regex(r"[^@]+@[^@]+\.[^@]+"),
type=str,
required=True,
help='You must provide a valid email address eg. username@example.com')
help='Provide a valid email address eg. username@example.com')
parser.add_argument('password',
type=str,
required=True,
Expand All @@ -37,7 +38,10 @@ def post(self):
password_hash=password)
new_user.hash_password(password)
new_user.hash_password(verify_password)
if password == verify_password:

if not re.match(r"[^@]+@[^@]+\.[^@]+", email) or not username or not password or not verify_password:
return {'message': 'Cannot submit blank fields or Validate your email address'}, 400
elif password == verify_password:
db.session.add(new_user)
db.session.commit()
return {'message': 'User successfully created', 'Username': '%s.' % username, 'email address': ' %s ' % email}, 201
Expand All @@ -47,7 +51,6 @@ def post(self):
db.session.rollback()
return {'message': 'Cannot create a new user. Please enter a valid email address'}, 400


class Login(Resource):
def post(self):
"""
Expand All @@ -69,12 +72,12 @@ def post(self):
if username and password:
user = Users.query.filter_by(username=username).first()
else:
return {'message': 'A username and password must be provided'}
return {'message': 'A username and password must be provided'}, 400

# Authenticate with username and password
if user and user.verify_password(password):
token = user.generate_auth_token(36000)
return {'message': 'Successfully logged in. This is your token', 'token': 'Token' + ' ' + token.decode('ascii'), 'duration': 36000}, 200
return {'message': 'Successfully logged in.', 'token': 'Token' + ' ' + token.decode('ascii'), 'duration': 36000}, 200

else:
return unauthorized("Incorrect username or password.")
Binary file modified configsettings/bucketlist.db
Binary file not shown.
1 change: 1 addition & 0 deletions my-app
Submodule my-app added at ef9962
21 changes: 21 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/7.6.0/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'start' ]
2 info using npm@4.1.2
3 info using node@v7.6.0
4 verbose stack Error: ENOENT: no such file or directory, open '/Users/judynjagi/Documents/bucketlist/package.json'
5 verbose cwd /Users/judynjagi/Documents/bucketlist
6 error Darwin 15.4.0
7 error argv "/usr/local/Cellar/node/7.6.0/bin/node" "/usr/local/bin/npm" "start"
8 error node v7.6.0
9 error npm v4.1.2
10 error path /Users/judynjagi/Documents/bucketlist/package.json
11 error code ENOENT
12 error errno -2
13 error syscall open
14 error enoent ENOENT: no such file or directory, open '/Users/judynjagi/Documents/bucketlist/package.json'
15 error enoent ENOENT: no such file or directory, open '/Users/judynjagi/Documents/bucketlist/package.json'
15 error enoent This is most likely not a problem with npm itself
15 error enoent and is related to npm not being able to find a file.
16 verbose exit [ -2, true ]

0 comments on commit cb71adb

Please sign in to comment.