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
9bd48ffd
Commit
9bd48ffd
authored
Dec 29, 2023
by
Timothy J. Baek
Browse files
feat: change password support
parent
450b9b6a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
1 deletion
+108
-1
backend/apps/web/models/auths.py
backend/apps/web/models/auths.py
+23
-1
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+19
-0
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+66
-0
No files found.
backend/apps/web/models/auths.py
View file @
9bd48ffd
...
...
@@ -64,6 +64,11 @@ class SigninForm(BaseModel):
password
:
str
class
UpdatePasswordForm
(
BaseModel
):
password
:
str
new_password
:
str
class
SignupForm
(
BaseModel
):
name
:
str
email
:
str
...
...
@@ -109,7 +114,24 @@ class AuthsTable:
except
:
return
None
def
delete_auth_by_id
(
self
,
id
:
str
)
->
Optional
[
UserModel
]:
def
update_user_password_by_id
(
self
,
id
:
str
,
password
:
str
,
new_password
:
str
)
->
bool
:
try
:
auth
=
Auth
.
get
(
Auth
.
id
==
id
,
Auth
.
active
==
True
)
if
auth
:
if
verify_password
(
password
,
auth
.
password
):
query
=
Auth
.
update
(
password
=
new_password
).
where
(
Auth
.
id
==
id
)
result
=
query
.
execute
()
print
(
result
)
return
True
else
:
return
False
return
True
except
:
return
False
def
delete_auth_by_id
(
self
,
id
:
str
)
->
bool
:
try
:
# Delete User
result
=
Users
.
delete_user_by_id
(
id
)
...
...
backend/apps/web/routers/auths.py
View file @
9bd48ffd
...
...
@@ -11,6 +11,7 @@ import uuid
from
apps.web.models.auths
import
(
SigninForm
,
SignupForm
,
UpdatePasswordForm
,
UserResponse
,
SigninResponse
,
Auths
,
...
...
@@ -53,6 +54,24 @@ async def get_session_user(cred=Depends(bearer_scheme)):
)
############################
# Update Password
############################
@
router
.
post
(
"/update/password"
,
response_model
=
bool
)
async
def
update_password
(
form_data
:
UpdatePasswordForm
,
cred
=
Depends
(
bearer_scheme
)):
token
=
cred
.
credentials
user
=
Users
.
get_user_by_token
(
token
)
if
user
:
hashed
=
get_password_hash
(
form_data
.
new_password
)
return
Auths
.
update_user_password_by_id
(
user
.
id
,
form_data
.
password
,
hashed
)
else
:
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
INVALID_CRED
)
############################
# SignIn
############################
...
...
src/lib/components/chat/SettingsModal.svelte
View file @
9bd48ffd
...
...
@@ -118,6 +118,11 @@
let authType = 'Basic';
let authContent = '';
// Account
let currentPassword = '';
let newPassword = '';
let newPasswordConfirm = '';
// About
let ollamaVersion = '';
...
...
@@ -1843,6 +1848,67 @@
</button>
</div>
</form>
{:else if selectedTab === 'account'}
<form
class="flex flex-col h-full text-sm"
on:submit|preventDefault={() => {
console.log('change save');
}}
>
<div class=" mb-2.5 font-medium">Change Password</div>
<div class=" space-y-1.5">
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">Current Password</div>
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
type="password"
bind:value={currentPassword}
autocomplete="current-password"
required
/>
</div>
</div>
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">New Password</div>
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
type="password"
bind:value={newPassword}
autocomplete="new-password"
required
/>
</div>
</div>
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">Confirm Password</div>
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
type="password"
bind:value={newPasswordConfirm}
autocomplete="off"
required
/>
</div>
</div>
</div>
<div class="mt-3 flex justify-end">
<button
class=" px-4 py-2 text-xs bg-gray-800 hover:bg-gray-900 dark:bg-gray-700 dark:hover:bg-gray-800 text-gray-100 transition rounded-md font-medium"
>
Update password
</button>
</div>
</form>
{:else if selectedTab === 'about'}
<div class="flex flex-col h-full justify-between space-y-3 text-sm mb-6">
<div class=" space-y-3">
...
...
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