-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from superphy/bearer
MERGE: 6.1.0 bearer accounts
- Loading branch information
Showing
8 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import hashlib | ||
import random | ||
from datetime import datetime | ||
# custom | ||
from middleware.mongo import mongo_update | ||
|
||
def generate_token(): | ||
""" | ||
Generates a bearer token for use by the front-end. | ||
Not actually secure, but suffices for our uses. | ||
""" | ||
now = datetime.now() | ||
now = now.strftime("%Y-%m-%d-%H-%M-%S-%f") | ||
salt = random.randint(100000,999999) | ||
seed = "{0}{1}".format(now,salt) | ||
token = hashlib.sha1(seed).hexdigest() | ||
return token | ||
|
||
def store(token): | ||
""" | ||
Stores the bearer token to MongoDB. | ||
""" | ||
# We should add a check for collision, but it's unlikely we'll see any. | ||
# Add the account to mongo. | ||
mongo_update(token, 'active', 'status') | ||
# Create an empty jobs dictionary for the account. | ||
mongo_update(token) | ||
|
||
def bearer(): | ||
token = generate_token() | ||
store(token) | ||
return token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from flask import Blueprint | ||
from middleware.bearer import bearer | ||
|
||
bp_ra_accounts = Blueprint('reactapp_accounts', __name__) | ||
|
||
@bp_ra_accounts.route('/api/v0/accounts') | ||
def create_account(): | ||
token = bearer() | ||
return token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule reactapp
updated
from 4f3a88 to a6b539