add default-avatar and use it instead of gravatar
This commit is contained in:
parent
d9f2d65cc2
commit
d05749d577
|
@ -1,10 +1,11 @@
|
|||
import enum
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
import arrow
|
||||
import bcrypt
|
||||
import stripe
|
||||
from arrow import Arrow
|
||||
from flask import url_for
|
||||
from flask_login import UserMixin
|
||||
from sqlalchemy_utils import ArrowType
|
||||
|
||||
|
@ -180,9 +181,8 @@ class User(db.Model, ModelMixin, UserMixin):
|
|||
def profile_picture_url(self):
|
||||
if self.profile_picture_id:
|
||||
return self.profile_picture.get_url()
|
||||
else: # use gravatar
|
||||
hash_email = hashlib.md5(self.email.encode("utf-8")).hexdigest()
|
||||
return f"https://www.gravatar.com/avatar/{hash_email}"
|
||||
else:
|
||||
return url_for("static", filename="default-avatar.png")
|
||||
|
||||
def plan_current_period_end(self) -> Arrow:
|
||||
if not self.stripe_subscription_id:
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
|
@ -27,7 +27,7 @@ def test_unactivated_user_login(flask_client):
|
|||
def test_activated_user_login(flask_client):
|
||||
"""Start with a blank database."""
|
||||
|
||||
# create user, user is not activated
|
||||
# create user, user is activated
|
||||
User.create(email="a@b.c", password="password", name="Test User", activated=True)
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
from app.config import EMAIL_DOMAIN
|
||||
from app.models import generate_email
|
||||
from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN
|
||||
from app.extensions import db
|
||||
from app.models import generate_email, User, GenEmail, PlanEnum
|
||||
|
||||
|
||||
def test_generate_email(flask_client):
|
||||
email = generate_email()
|
||||
assert email.endswith("@" + EMAIL_DOMAIN)
|
||||
|
||||
|
||||
def test_profile_picture_url(flask_client):
|
||||
user = User.create(
|
||||
email="a@b.c", password="password", name="Test User", activated=True
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
assert user.profile_picture_url() == "http://sl.test/static/default-avatar.png"
|
||||
|
|
Loading…
Reference in New Issue