Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
418da747
Commit
418da747
authored
Jan 26, 2024
by
Timothy J. Baek
Browse files
feat: profile image update backend
parent
0e831f4c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
11 deletions
+52
-11
backend/apps/web/models/auths.py
backend/apps/web/models/auths.py
+4
-0
backend/apps/web/models/users.py
backend/apps/web/models/users.py
+14
-0
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+34
-11
No files found.
backend/apps/web/models/auths.py
View file @
418da747
...
@@ -63,6 +63,10 @@ class SigninForm(BaseModel):
...
@@ -63,6 +63,10 @@ class SigninForm(BaseModel):
password
:
str
password
:
str
class
ProfileImageUrlForm
(
BaseModel
):
profile_image_url
:
str
class
UpdatePasswordForm
(
BaseModel
):
class
UpdatePasswordForm
(
BaseModel
):
password
:
str
password
:
str
new_password
:
str
new_password
:
str
...
...
backend/apps/web/models/users.py
View file @
418da747
...
@@ -108,6 +108,20 @@ class UsersTable:
...
@@ -108,6 +108,20 @@ class UsersTable:
except
:
except
:
return
None
return
None
def
update_user_profile_image_url_by_id
(
self
,
id
:
str
,
profile_image_url
:
str
)
->
Optional
[
UserModel
]:
try
:
query
=
User
.
update
(
profile_image_url
=
profile_image_url
).
where
(
User
.
id
==
id
)
query
.
execute
()
user
=
User
.
get
(
User
.
id
==
id
)
return
UserModel
(
**
model_to_dict
(
user
))
except
:
return
None
def
update_user_by_id
(
self
,
id
:
str
,
updated
:
dict
)
->
Optional
[
UserModel
]:
def
update_user_by_id
(
self
,
id
:
str
,
updated
:
dict
)
->
Optional
[
UserModel
]:
try
:
try
:
query
=
User
.
update
(
**
updated
).
where
(
User
.
id
==
id
)
query
=
User
.
update
(
**
updated
).
where
(
User
.
id
==
id
)
...
...
backend/apps/web/routers/auths.py
View file @
418da747
...
@@ -11,6 +11,7 @@ import uuid
...
@@ -11,6 +11,7 @@ import uuid
from
apps.web.models.auths
import
(
from
apps.web.models.auths
import
(
SigninForm
,
SigninForm
,
SignupForm
,
SignupForm
,
ProfileImageUrlForm
,
UpdatePasswordForm
,
UpdatePasswordForm
,
UserResponse
,
UserResponse
,
SigninResponse
,
SigninResponse
,
...
@@ -40,14 +41,36 @@ async def get_session_user(user=Depends(get_current_user)):
...
@@ -40,14 +41,36 @@ async def get_session_user(user=Depends(get_current_user)):
}
}
############################
# Update Profile Image Url
############################
@
router
.
post
(
"/update/profile"
,
response_model
=
UserResponse
)
async
def
update_profile_image_url
(
form_data
:
ProfileImageUrlForm
,
session_user
=
Depends
(
get_current_user
)
):
if
session_user
:
user
=
Users
.
update_user_profile_image_url_by_id
(
session_user
.
id
,
form_data
.
profile_image_url
)
if
user
:
return
user
else
:
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
DEFAULT
())
else
:
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
INVALID_CRED
)
############################
############################
# Update Password
# Update Password
############################
############################
@
router
.
post
(
"/update/password"
,
response_model
=
bool
)
@
router
.
post
(
"/update/password"
,
response_model
=
bool
)
async
def
update_password
(
form_data
:
UpdatePasswordForm
,
async
def
update_password
(
session_user
=
Depends
(
get_current_user
)):
form_data
:
UpdatePasswordForm
,
session_user
=
Depends
(
get_current_user
)
):
if
session_user
:
if
session_user
:
user
=
Auths
.
authenticate_user
(
session_user
.
email
,
form_data
.
password
)
user
=
Auths
.
authenticate_user
(
session_user
.
email
,
form_data
.
password
)
...
@@ -103,8 +126,9 @@ async def signup(request: Request, form_data: SignupForm):
...
@@ -103,8 +126,9 @@ async def signup(request: Request, form_data: SignupForm):
try
:
try
:
role
=
"admin"
if
Users
.
get_num_users
()
==
0
else
"pending"
role
=
"admin"
if
Users
.
get_num_users
()
==
0
else
"pending"
hashed
=
get_password_hash
(
form_data
.
password
)
hashed
=
get_password_hash
(
form_data
.
password
)
user
=
Auths
.
insert_new_auth
(
form_data
.
email
.
lower
(),
user
=
Auths
.
insert_new_auth
(
hashed
,
form_data
.
name
,
role
)
form_data
.
email
.
lower
(),
hashed
,
form_data
.
name
,
role
)
if
user
:
if
user
:
token
=
create_token
(
data
=
{
"email"
:
user
.
email
})
token
=
create_token
(
data
=
{
"email"
:
user
.
email
})
...
@@ -120,11 +144,10 @@ async def signup(request: Request, form_data: SignupForm):
...
@@ -120,11 +144,10 @@ async def signup(request: Request, form_data: SignupForm):
"profile_image_url"
:
user
.
profile_image_url
,
"profile_image_url"
:
user
.
profile_image_url
,
}
}
else
:
else
:
raise
HTTPException
(
raise
HTTPException
(
500
,
detail
=
ERROR_MESSAGES
.
CREATE_USER_ERROR
)
500
,
detail
=
ERROR_MESSAGES
.
CREATE_USER_ERROR
)
except
Exception
as
err
:
except
Exception
as
err
:
raise
HTTPException
(
500
,
raise
HTTPException
(
500
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(
err
))
detail
=
ERROR_MESSAGES
.
DEFAULT
(
err
))
############################
############################
# ToggleSignUp
# ToggleSignUp
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment