]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Add hash to avatar
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Oct 2019 11:18:46 +0000 (11:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Oct 2019 11:20:32 +0000 (11:20 +0000)
This allows us to see the change immediately

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py

index 9e2049fd203c6ebb5c37bb91cf0ee940bed66a2f..63c99a6dd6e65bc1c47193a9e2902850cf0dcb19 100644 (file)
@@ -3,6 +3,7 @@
 
 import base64
 import datetime
+import hashlib
 import hmac
 import json
 import ldap
@@ -963,10 +964,10 @@ class Account(Object):
                return has_avatar
 
        def avatar_url(self, size=None):
-               url = "https://people.ipfire.org/users/%s.jpg" % self.uid
+               url = "https://people.ipfire.org/users/%s.jpg?h=%s" % (self.uid, self.avatar_hash)
 
                if size:
-                       url += "?size=%s" % size
+                       url += "&size=%s" % size
 
                return url
 
@@ -994,12 +995,27 @@ class Account(Object):
 
                return avatar
 
+       @property
+       def avatar_hash(self):
+               hash = self.memcache.get("accounts:%s:avatar-hash" % self.dn)
+               if not hash:
+                       h = hashlib.new("md5")
+                       h.update(self.get_avatar() or b"")
+                       hash = h.hexdigest()[:7]
+
+                       self.memcache.set("accounts:%s:avatar-hash" % self.dn, hash, 86400)
+
+               return hash
+
        def upload_avatar(self, avatar):
                self._set("jpegPhoto", avatar)
 
                # Delete cached avatar status
                self.memcache.delete("accounts:%s:has-avatar" % self.uid)
 
+               # Delete avatar hash
+               self.memcache.delete("accounts:%s:avatar-hash" % self.uid)
+
 
 class StopForumSpam(Object):
        def init(self, uid, email, address):