make sure to set File.user_id
This commit is contained in:
parent
cd19997424
commit
abd2278c24
|
@ -102,7 +102,7 @@ def facebook_callback():
|
||||||
if user:
|
if user:
|
||||||
if picture_url and not user.profile_picture_id:
|
if picture_url and not user.profile_picture_id:
|
||||||
LOG.d("set user profile picture to %s", picture_url)
|
LOG.d("set user profile picture to %s", picture_url)
|
||||||
file = create_file_from_url(picture_url)
|
file = create_file_from_url(user, picture_url)
|
||||||
user.profile_picture_id = file.id
|
user.profile_picture_id = file.id
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -120,10 +120,11 @@ def facebook_callback():
|
||||||
user = User.create(
|
user = User.create(
|
||||||
email=email.lower(), name=facebook_user_data["name"], activated=True
|
email=email.lower(), name=facebook_user_data["name"], activated=True
|
||||||
)
|
)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
if picture_url:
|
if picture_url:
|
||||||
LOG.d("set user profile picture to %s", picture_url)
|
LOG.d("set user profile picture to %s", picture_url)
|
||||||
file = create_file_from_url(picture_url)
|
file = create_file_from_url(user, picture_url)
|
||||||
user.profile_picture_id = file.id
|
user.profile_picture_id = file.id
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -88,7 +88,7 @@ def google_callback():
|
||||||
if user:
|
if user:
|
||||||
if picture_url and not user.profile_picture_id:
|
if picture_url and not user.profile_picture_id:
|
||||||
LOG.d("set user profile picture to %s", picture_url)
|
LOG.d("set user profile picture to %s", picture_url)
|
||||||
file = create_file_from_url(picture_url)
|
file = create_file_from_url(user, picture_url)
|
||||||
user.profile_picture_id = file.id
|
user.profile_picture_id = file.id
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# create user
|
# create user
|
||||||
|
@ -105,10 +105,11 @@ def google_callback():
|
||||||
user = User.create(
|
user = User.create(
|
||||||
email=email.lower(), name=google_user_data["name"], activated=True
|
email=email.lower(), name=google_user_data["name"], activated=True
|
||||||
)
|
)
|
||||||
|
db.session.flush()
|
||||||
|
|
||||||
if picture_url:
|
if picture_url:
|
||||||
LOG.d("set user profile picture to %s", picture_url)
|
LOG.d("set user profile picture to %s", picture_url)
|
||||||
file = create_file_from_url(picture_url)
|
file = create_file_from_url(user, picture_url)
|
||||||
user.profile_picture_id = file.id
|
user.profile_picture_id = file.id
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -133,9 +134,9 @@ def google_callback():
|
||||||
return after_login(user, next_url)
|
return after_login(user, next_url)
|
||||||
|
|
||||||
|
|
||||||
def create_file_from_url(url) -> File:
|
def create_file_from_url(user, url) -> File:
|
||||||
file_path = random_string(30)
|
file_path = random_string(30)
|
||||||
file = File.create(path=file_path)
|
file = File.create(path=file_path, user_id=user.id)
|
||||||
|
|
||||||
s3.upload_from_url(url, file_path)
|
s3.upload_from_url(url, file_path)
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ def setting():
|
||||||
|
|
||||||
if form.profile_picture.data:
|
if form.profile_picture.data:
|
||||||
file_path = random_string(30)
|
file_path = random_string(30)
|
||||||
file = File.create(path=file_path)
|
file = File.create(user_id=current_user.id, path=file_path)
|
||||||
|
|
||||||
s3.upload_from_bytesio(
|
s3.upload_from_bytesio(
|
||||||
file_path, BytesIO(form.profile_picture.data.read())
|
file_path, BytesIO(form.profile_picture.data.read())
|
||||||
|
|
|
@ -45,7 +45,7 @@ def client_detail(client_id):
|
||||||
# todo: remove current icon if any
|
# todo: remove current icon if any
|
||||||
# todo: handle remove icon
|
# todo: handle remove icon
|
||||||
file_path = random_string(30)
|
file_path = random_string(30)
|
||||||
file = File.create(path=file_path)
|
file = File.create(path=file_path, user_id=client.user_id)
|
||||||
|
|
||||||
s3.upload_from_bytesio(file_path, BytesIO(form.icon.data.read()))
|
s3.upload_from_bytesio(file_path, BytesIO(form.icon.data.read()))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue