Skip to content

Commit

Permalink
Merge pull request #81 from factly/feat/update-password
Browse files Browse the repository at this point in the history
feat/update-password
  • Loading branch information
shreeharsha-factly authored Nov 22, 2021
2 parents 7d87c31 + 00821bd commit 1eb01bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
30 changes: 24 additions & 6 deletions web/src/components/GlobalNav/AccountMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Link } from 'react-router-dom';
import { Avatar } from 'antd';
import { useDispatch, useSelector } from 'react-redux';
import { getUserProfile } from '../../actions/profile';
import { notification } from 'antd';

const AccountMenu = () => {
const dispatch = useDispatch();
Expand All @@ -22,10 +23,29 @@ const AccountMenu = () => {
React.useEffect(() => {
dispatch(getUserProfile());
}, [dispatch]);


const handleLogout = ()=>{
fetch(window.REACT_APP_KRATOS_PUBLIC_URL + '/self-service/logout/browser')
.then((res) => {
if (res.status === 200) {
return res.json();
} else {
throw new Error(res.status);
}
})
.then((res)=>{
window.location.href = res.logout_url
}).catch((err)=>{
notification.error({
message:'Error',
description:'Unable to login'
})
})
}
return (
<Menu mode="horizontal">
<Menu.SubMenu
key="submenu"
title={
<>
{!loading && profile && profile.medium ? (
Expand All @@ -36,21 +56,19 @@ const AccountMenu = () => {
</>
}
>
<Menu.Item>
<Menu.Item key="password">
<Link to="/password">
<SafetyCertificateOutlined /> Security
</Link>
</Menu.Item>
<Menu.Item>
<Menu.Item key="profile">
<Link to="/profile">
<EditOutlined /> Profile
</Link>
</Menu.Item>
<Menu.Item>
<a href={window.REACT_APP_KRATOS_PUBLIC_URL + '/self-service/browser/flows/logout'}>
<Menu.Item key="logout" onClick={handleLogout}>
<LogoutOutlined />
Logout
</a>
</Menu.Item>
</Menu.SubMenu>
</Menu>
Expand Down
18 changes: 12 additions & 6 deletions web/src/pages/password/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Password() {
})
.then((res) => {
setUI(res.ui);
if (res.update_successful) {
if (res.state==='success') {
notification.success({
message: 'Success',
description: 'Password has been successful updated',
Expand All @@ -48,19 +48,25 @@ function Password() {
updatePasswordForm.method = ui.method;
updatePasswordForm.style.display = 'none';

var emailInput = document.createElement('input');
emailInput.name = 'password_identifier';
emailInput.value = ui.nodes[1].attributes.value;

var passwordInput = document.createElement('input');
passwordInput.name = 'password';
passwordInput.value = values.password;

var csrfInput = document.createElement('input');
csrfInput.name = 'csrf_token';
csrfInput.value = ui.nodes.find((value) => {
if (value.attributes.name === 'csrf_token') {
return value;
}
}).attributes.value;
csrfInput.value = ui.nodes.find((value) => value.attributes.name === 'csrf_token').attributes.value;

var methodInput = document.createElement('input');
methodInput.name = 'method';
methodInput.value = 'password';

updatePasswordForm.appendChild(emailInput)
updatePasswordForm.appendChild(passwordInput);
updatePasswordForm.appendChild(methodInput);
updatePasswordForm.appendChild(csrfInput);
document.body.appendChild(updatePasswordForm);
updatePasswordForm.submit();
Expand Down

0 comments on commit 1eb01bb

Please sign in to comment.