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
d8bb19fd
"git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "001f167aadd7bfdea2b13268a5850e336d3766dd"
Commit
d8bb19fd
authored
Dec 29, 2023
by
Timothy J. Baek
Browse files
feat: change password frontend added
parent
9bd48ffd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
5 deletions
+69
-5
backend/apps/web/routers/auths.py
backend/apps/web/routers/auths.py
+8
-4
backend/constants.py
backend/constants.py
+3
-0
src/lib/apis/auths/index.ts
src/lib/apis/auths/index.ts
+31
-0
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+27
-1
No files found.
backend/apps/web/routers/auths.py
View file @
d8bb19fd
...
@@ -62,12 +62,16 @@ async def get_session_user(cred=Depends(bearer_scheme)):
...
@@ -62,12 +62,16 @@ async def get_session_user(cred=Depends(bearer_scheme)):
@
router
.
post
(
"/update/password"
,
response_model
=
bool
)
@
router
.
post
(
"/update/password"
,
response_model
=
bool
)
async
def
update_password
(
form_data
:
UpdatePasswordForm
,
cred
=
Depends
(
bearer_scheme
)):
async
def
update_password
(
form_data
:
UpdatePasswordForm
,
cred
=
Depends
(
bearer_scheme
)):
token
=
cred
.
credentials
token
=
cred
.
credentials
user
=
Users
.
get_user_by_token
(
token
)
session_
user
=
Users
.
get_user_by_token
(
token
)
if
user
:
if
session_user
:
hashed
=
get_password_hash
(
form_data
.
new_password
)
user
=
Auths
.
authenticate_user
(
session_user
.
email
,
form_data
.
password
)
return
Auths
.
update_user_password_by_id
(
user
.
id
,
form_data
.
password
,
hashed
)
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_PASSWORD
)
else
:
else
:
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
INVALID_CRED
)
raise
HTTPException
(
400
,
detail
=
ERROR_MESSAGES
.
INVALID_CRED
)
...
...
backend/constants.py
View file @
d8bb19fd
...
@@ -21,6 +21,9 @@ class ERROR_MESSAGES(str, Enum):
...
@@ -21,6 +21,9 @@ class ERROR_MESSAGES(str, Enum):
"Your session has expired or the token is invalid. Please sign in again."
"Your session has expired or the token is invalid. Please sign in again."
)
)
INVALID_CRED
=
"The email or password provided is incorrect. Please check for typos and try logging in again."
INVALID_CRED
=
"The email or password provided is incorrect. Please check for typos and try logging in again."
INVALID_PASSWORD
=
(
"The password provided is incorrect. Please check for typos and try again."
)
UNAUTHORIZED
=
"401 Unauthorized"
UNAUTHORIZED
=
"401 Unauthorized"
ACCESS_PROHIBITED
=
"You do not have permission to access this resource. Please contact your administrator for assistance."
ACCESS_PROHIBITED
=
"You do not have permission to access this resource. Please contact your administrator for assistance."
ACTION_PROHIBITED
=
(
ACTION_PROHIBITED
=
(
...
...
src/lib/apis/auths/index.ts
View file @
d8bb19fd
...
@@ -88,3 +88,34 @@ export const userSignUp = async (name: string, email: string, password: string)
...
@@ -88,3 +88,34 @@ export const userSignUp = async (name: string, email: string, password: string)
return
res
;
return
res
;
};
};
export
const
updateUserPassword
=
async
(
token
:
string
,
password
:
string
,
newPassword
:
string
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/auths/update/password`
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...(
token
&&
{
authorization
:
`Bearer
${
token
}
`
})
},
body
:
JSON
.
stringify
({
password
:
password
,
new_password
:
newPassword
})
})
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
error
=
err
.
detail
;
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
src/lib/components/chat/SettingsModal.svelte
View file @
d8bb19fd
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
import Advanced from './Settings/Advanced.svelte';
import Advanced from './Settings/Advanced.svelte';
import Modal from '../common/Modal.svelte';
import Modal from '../common/Modal.svelte';
import { updateUserPassword } from '$lib/apis/auths';
export let show = false;
export let show = false;
...
@@ -600,6 +601,31 @@
...
@@ -600,6 +601,31 @@
return models;
return models;
};
};
const updatePasswordHandler = async () => {
if (newPassword === newPasswordConfirm) {
const res = await updateUserPassword(localStorage.token, currentPassword, newPassword).catch(
(error) => {
toast.error(error);
return null;
}
);
if (res) {
toast.success('Successfully updated.');
}
currentPassword = '';
newPassword = '';
newPasswordConfirm = '';
} else {
toast.error(
`The passwords you entered don't quite match. Please double-check and try again.`
);
newPassword = '';
newPasswordConfirm = '';
}
};
onMount(async () => {
onMount(async () => {
let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
console.log(settings);
console.log(settings);
...
@@ -1852,7 +1878,7 @@
...
@@ -1852,7 +1878,7 @@
<form
<form
class="flex flex-col h-full text-sm"
class="flex flex-col h-full text-sm"
on:submit|preventDefault={() => {
on:submit|preventDefault={() => {
console.log('change save'
);
updatePasswordHandler(
);
}}
}}
>
>
<div class=" mb-2.5 font-medium">Change Password</div>
<div class=" mb-2.5 font-medium">Change Password</div>
...
...
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