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 enum
|
||||||
import hashlib
|
import random
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import stripe
|
import stripe
|
||||||
from arrow import Arrow
|
from arrow import Arrow
|
||||||
|
from flask import url_for
|
||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from sqlalchemy_utils import ArrowType
|
from sqlalchemy_utils import ArrowType
|
||||||
|
|
||||||
|
@ -180,9 +181,8 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
def profile_picture_url(self):
|
def profile_picture_url(self):
|
||||||
if self.profile_picture_id:
|
if self.profile_picture_id:
|
||||||
return self.profile_picture.get_url()
|
return self.profile_picture.get_url()
|
||||||
else: # use gravatar
|
else:
|
||||||
hash_email = hashlib.md5(self.email.encode("utf-8")).hexdigest()
|
return url_for("static", filename="default-avatar.png")
|
||||||
return f"https://www.gravatar.com/avatar/{hash_email}"
|
|
||||||
|
|
||||||
def plan_current_period_end(self) -> Arrow:
|
def plan_current_period_end(self) -> Arrow:
|
||||||
if not self.stripe_subscription_id:
|
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):
|
def test_activated_user_login(flask_client):
|
||||||
"""Start with a blank database."""
|
"""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)
|
User.create(email="a@b.c", password="password", name="Test User", activated=True)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
from app.config import EMAIL_DOMAIN
|
from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN
|
||||||
from app.models import generate_email
|
from app.extensions import db
|
||||||
|
from app.models import generate_email, User, GenEmail, PlanEnum
|
||||||
|
|
||||||
|
|
||||||
def test_generate_email(flask_client):
|
def test_generate_email(flask_client):
|
||||||
email = generate_email()
|
email = generate_email()
|
||||||
assert email.endswith("@" + EMAIL_DOMAIN)
|
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