Skip to content

Commit

Permalink
<fix> fix github auth not unique bug
Browse files Browse the repository at this point in the history
Author:rapospectre@gmail.com

Desc: fix github auth not unique bug
  • Loading branch information
bluedazzle committed Feb 20, 2017
1 parent 8b2367b commit 7515aab
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ def get(self, request, *args, **kwargs):
state = request.GET.get('state')
if code and state:
access_token = get_access_token(code, state)
email, nick, avatar = get_user_info(access_token)
guest = Guest.objects.filter(email=email)
gid, email, nick, avatar = get_user_info(access_token)
guest = Guest.objects.filter(uid=gid)
token = self.create_token()
if guest.exists():
guest = guest[0]
guest.token = token
guest.save()
else:
# status, avatar_path = save_image(avatar, '{0}{1}.png'.format(nick, unicode(time.time()).split('.')[0]))
guest = Guest(email=email, nick=nick, token=token)
guest = Guest(email=email, nick=nick, token=token, uid=gid)
guest.set_password('123456q_+|')
# if status:
guest.avatar = avatar
Expand Down
4 changes: 3 additions & 1 deletion core/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def get_user_info(access_token):
url = 'https://api.github.com/user?access_token={0}'.format(access_token)
res = requests.get(url, headers={'Accept': 'application/json'})
json_data = json.loads(res.content)
print json_data
email = json_data.get('email')
nick = json_data.get('name')
gid = json_data.get('id')
if not nick:
nick = json_data.get('login', '')
avatar = json_data.get('avatar_url')
return email, nick, avatar
return gid, email, nick, avatar
1 change: 1 addition & 0 deletions myguest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Guest(BaseModel, AbstractBaseUser):
email = models.CharField(max_length=256, null=True, blank=True)
forbid = models.BooleanField(default=False)
token = models.CharField(max_length=64, unique=True)
uid = models.IntegerField(default=0)

def __unicode__(self):
return '{0}-{1}'.format(self.nick, self.email)
Binary file modified task_dispatch/celerybeat-schedule
Binary file not shown.

0 comments on commit 7515aab

Please sign in to comment.