Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #3 #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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