Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
a4a44d2b
Commit
a4a44d2b
authored
8 years ago
by
Megan Henning
Browse files
Options
Downloads
Plain Diff
Merge pull request #257 from scitran/gravatar-bug
Lookup gravatar and save info on login
parents
87a11071
459af230
No related branches found
No related tags found
Loading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/base.py
+8
-3
8 additions, 3 deletions
api/base.py
api/handlers/userhandler.py
+1
-16
1 addition, 16 deletions
api/handlers/userhandler.py
api/util.py
+14
-0
14 additions, 0 deletions
api/util.py
with
23 additions
and
19 deletions
api/base.py
+
8
−
3
View file @
a4a44d2b
...
...
@@ -158,12 +158,17 @@ class RequestHandler(webapp2.RequestHandler):
query
.
pop
(
'
sz
'
,
None
)
u
=
u
.
_replace
(
query
=
urllib
.
urlencode
(
query
,
True
))
provider_avatar
=
urlparse
.
urlunparse
(
u
)
# Update the user's provider avatar if it has changed.
config
.
db
.
users
.
update_one
({
'
_id
'
:
uid
,
'
avatars.provider
'
:
{
'
$ne
'
:
provider_avatar
}},
{
'
$set
'
:{
'
avatars.provider
'
:
provider_avatar
,
'
modified
'
:
timestamp
}})
# If the user has no avatar set, mark th
is
as their chosen avatar.
# If the user has no avatar set, mark th
eir provider_avatar
as their chosen avatar.
config
.
db
.
users
.
update_one
({
'
_id
'
:
uid
,
'
avatar
'
:
{
'
$exists
'
:
False
}},
{
'
$set
'
:{
'
avatar
'
:
provider_avatar
,
'
modified
'
:
timestamp
}})
# Update the user's provider avatar if it has changed.
config
.
db
.
users
.
update_one
({
'
_id
'
:
uid
,
'
avatars.provider
'
:
{
'
$ne
'
:
provider_avatar
}},
{
'
$set
'
:{
'
avatars.provider
'
:
provider_avatar
,
'
modified
'
:
timestamp
}})
# Look to see if user has a Gravatar
gravatar
=
util
.
resolve_gravatar
(
uid
)
if
gravatar
is
not
None
:
# Update the user's gravatar if it has changed.
config
.
db
.
users
.
update_one
({
'
_id
'
:
uid
,
'
avatars.gravatar
'
:
{
'
$ne
'
:
gravatar
}},
{
'
$set
'
:{
'
avatars.gravatar
'
:
gravatar
,
'
modified
'
:
timestamp
}})
return
uid
...
...
This diff is collapsed.
Click to expand it.
api/handlers/userhandler.py
+
1
−
16
View file @
a4a44d2b
import
datetime
import
hashlib
import
pymongo
import
requests
from
..
import
base
from
..
import
util
...
...
@@ -127,7 +125,7 @@ class UserHandler(base.RequestHandler):
# If the user exists but has no set avatar, try to get one
if
user
and
avatar
is
None
:
gravatar
=
self
.
_
resolve_gravatar
(
email
)
gravatar
=
util
.
resolve_gravatar
(
email
)
if
gravatar
is
not
None
:
user
=
config
.
db
[
'
users
'
].
find_one_and_update
({
...
...
@@ -149,19 +147,6 @@ class UserHandler(base.RequestHandler):
else
:
self
.
abort
(
404
,
'
no avatar
'
)
def
_resolve_gravatar
(
self
,
email
):
"""
Given an email, returns a URL if that email has a gravatar set.
Otherwise returns None.
"""
gravatar
=
'
https://gravatar.com/avatar/
'
+
hashlib
.
md5
(
email
).
hexdigest
()
+
'
?s=512
'
if
requests
.
head
(
gravatar
,
params
=
{
'
d
'
:
'
404
'
}):
return
gravatar
else
:
return
None
def
_get_user
(
self
,
_id
):
user
=
self
.
storage
.
get_container
(
_id
)
if
user
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
api/util.py
+
14
−
0
View file @
a4a44d2b
...
...
@@ -8,6 +8,8 @@ import os
import
pytz
import
tempdir
as
tempfile
import
uuid
import
requests
import
hashlib
from
.
import
config
MIMETYPES
=
[
...
...
@@ -54,6 +56,18 @@ def user_perm(permissions, _id, site=None):
else
:
return
{}
def
resolve_gravatar
(
email
):
"""
Given an email, returns a URL if that email has a gravatar set.
Otherwise returns None.
"""
gravatar
=
'
https://gravatar.com/avatar/
'
+
hashlib
.
md5
(
email
).
hexdigest
()
+
'
?s=512
'
if
requests
.
head
(
gravatar
,
params
=
{
'
d
'
:
'
404
'
}):
return
gravatar
else
:
return
None
def
container_fileinfo
(
container
,
filename
):
for
fileinfo
in
container
.
get
(
'
files
'
,
[]):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment