Skip to content

Commit

Permalink
Merge pull request #14 from gabrielhicks/development
Browse files Browse the repository at this point in the history
Fixes issue #3
  • Loading branch information
DiptoChakrabarty authored Oct 5, 2020
2 parents 35a8c5b + 4b8a035 commit a8047b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 2 additions & 3 deletions model/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UserModel(db.Model):
__tablename__="users"
id = db.Column(db.Integer,primary_key=True)
username = db.Column(db.String(20),nullable=False,unique=True)
password = db.Column(db.String(20))
password = db.Column(db.String(20),nullable=True)
email = db.Column(db.String(40),nullable=False,unique=True)
activated = db.Column(db.Boolean,default=False) #set default as False

Expand All @@ -37,7 +37,6 @@ def delete_from_db(self):
db.session.delete(self)
db.session.commit()


def generate_mail(self):
serializer = URLSafeTimedSerializer("secrettoken",1800)
token = serializer.dumps({"email":self.email},salt="flask-email-confirmation")
Expand All @@ -63,7 +62,7 @@ def find_by_username(cls,username):
@classmethod
def find_by_email(cls,email):
return cls.query.filter_by(email=email).first()

@classmethod
def check_password(cls,username,password):
user=cls.query.filter_by(username=username).first()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ MarkupSafe==1.1.1
marshmallow==3.7.1
marshmallow-sqlalchemy==0.23.1
oauthlib==2.1.0
pkg-resources==0.0.0
pycparser==2.20
PyJWT==1.6.4
python-dateutil==2.8.1
Expand Down
13 changes: 11 additions & 2 deletions resource/github_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from outh import github
from model.users import UserModel
from flask_jwt_extended import create_access_token,create_refresh_token
import secrets
import string

class Github(Resource):
@classmethod
Expand All @@ -28,9 +30,16 @@ def get(cls):

#if UserModel.find_by_username(github_username):
# return {"msg": "User with username exists"}


#generate a sample password for github oauth users
@classmethod
def generate_sample_password(cls):
alpha = string.ascii_letters + string.digits
random = ''.join(secrets.choice(alpha) for i in range(20))
return random

#add user to database
user = UserModel(username=github_username,password=None,activated=True,email=github_email)
user = UserModel(username=github_username,password=GithubAuthorize.generate_sample_password(),activated=True,email=github_email)
user.save_to_db()

#create jwt tokens
Expand Down

0 comments on commit a8047b9

Please sign in to comment.