-
Notifications
You must be signed in to change notification settings - Fork 29
Allow users to change their own email address #8671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
bdab4af
allow user to change email and set email in user list to read-only
knollengewaechs 8b4ac8b
send verification email
knollengewaechs 3562d51
enable users to edit their own email address
MichaelBuessemeyer 07fabe0
allow to edit own email addres for non admins
MichaelBuessemeyer 209bf8b
add specific column tracking when the last email change was for more…
MichaelBuessemeyer 9774d5a
Merge branch 'master' into users-can-change-email
knollengewaechs 58bcc29
clean up frontend code
knollengewaechs 74fe1f2
add password verification upon email update
MichaelBuessemeyer 5b866a0
Merge branch 'users-can-change-email' of github.com:scalableminds/web…
MichaelBuessemeyer 04151f4
disallow admins updating emails of other users
MichaelBuessemeyer 8d7ed7b
add entry to MIGRATIONS.unreleased.md
MichaelBuessemeyer 8be7adb
format backend
MichaelBuessemeyer 56098bc
Merge branch 'master' into users-can-change-email
MichaelBuessemeyer 9ec548d
remove logging used for testing
MichaelBuessemeyer d443e02
Merge branch 'users-can-change-email' of github.com:scalableminds/web…
MichaelBuessemeyer cc94854
Merge branch 'master' into users-can-change-email
fm3 2a1166d
unused import
fm3 9dd940d
Merge branch 'users-can-change-email' of github.com:scalableminds/web…
fm3 7ff58c0
add missing emailChangeDate column to multi
MichaelBuessemeyer c45795f
apply pr feedback
MichaelBuessemeyer dae5355
Merge branch 'master' of github.com:scalableminds/webknossos into use…
MichaelBuessemeyer 34bb221
Merge branch 'users-can-change-email' of github.com:scalableminds/web…
MichaelBuessemeyer c9731b2
include multiuserid in in logging upon email changed by user
MichaelBuessemeyer 4477287
Update unreleased_changes/8671.md
MichaelBuessemeyer b4e3e55
merge master
knollengewaechs d540be7
Revert "merge master"
knollengewaechs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import { LockOutlined, MailOutlined } from "@ant-design/icons"; | ||
import { updateUser } from "admin/rest_api"; | ||
import { Alert, Button, Col, Form, Input, Row } from "antd"; | ||
import { useWkSelector } from "libs/react_hooks"; | ||
import Request from "libs/request"; | ||
import Toast from "libs/toast"; | ||
import { type RouteComponentProps, withRouter } from "react-router-dom"; | ||
import { handleResendVerificationEmail } from "./verify_email_view"; | ||
const FormItem = Form.Item; | ||
|
||
function ChangeEmailView() { | ||
const [form] = Form.useForm(); | ||
const activeUser = useWkSelector((state) => state.activeUser); | ||
|
||
async function changeEmail(newEmail: string) { | ||
const newUser = Object.assign({}, activeUser, { | ||
email: newEmail, | ||
}); | ||
return updateUser(newUser); | ||
} | ||
|
||
function onFinish() { | ||
const newEmail = form.getFieldValue("newEmail"); | ||
changeEmail(newEmail) | ||
.then(() => { | ||
handleResendVerificationEmail(); | ||
Toast.success("Email address changed successfully. You will be logged out."); | ||
return Request.receiveJSON("/api/auth/logout"); | ||
}) | ||
.then(() => { | ||
form.resetFields(); | ||
// Redirect to login page after successful email change | ||
window.location.href = "/auth/login"; | ||
}) | ||
.catch((error) => { | ||
Toast.error( | ||
"An unexpected error occurred while changing the email address: " + error.message, | ||
); | ||
}); | ||
} | ||
|
||
function checkEmailsAreMatching(value: string, otherEmailFieldKey: string[]) { | ||
const otherFieldValue = form.getFieldValue(otherEmailFieldKey); | ||
|
||
if (value && otherFieldValue) { | ||
if (value !== otherFieldValue) { | ||
return Promise.reject(new Error("Email addresses do not match")); | ||
} else if (form.getFieldError(otherEmailFieldKey).length > 0) { | ||
form.validateFields([otherEmailFieldKey]); | ||
} | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
return ( | ||
<Row | ||
justify="center" | ||
align="middle" | ||
style={{ | ||
padding: 50, | ||
}} | ||
> | ||
<Col span={8}> | ||
<h3>Change Email</h3> | ||
<Alert | ||
type="info" | ||
message="You will be logged out after changing your email address." | ||
showIcon | ||
style={{ | ||
marginBottom: 24, | ||
}} | ||
/> | ||
<Form onFinish={onFinish} form={form}> | ||
<FormItem | ||
name="password" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: "Please enter your password for verification", | ||
}, | ||
]} | ||
> | ||
<Input.Password | ||
prefix={ | ||
<LockOutlined | ||
style={{ | ||
fontSize: 13, | ||
}} | ||
/> | ||
} | ||
placeholder="Your Password" | ||
/> | ||
</FormItem> | ||
<FormItem | ||
hasFeedback | ||
name="newEmail" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: "Please enter your new email address", | ||
}, | ||
{ | ||
type: "email", | ||
message: "Please enter a valid email address", | ||
}, | ||
{ | ||
validator: (_, value: string) => checkEmailsAreMatching(value, ["confirmNewEmail"]), | ||
}, | ||
]} | ||
> | ||
<Input | ||
prefix={ | ||
<MailOutlined | ||
style={{ | ||
fontSize: 13, | ||
}} | ||
/> | ||
} | ||
placeholder="New Email Address" | ||
/> | ||
</FormItem> | ||
<FormItem | ||
hasFeedback | ||
name="confirmNewEmail" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: "Please confirm your new email address", | ||
}, | ||
{ | ||
type: "email", | ||
message: "Please enter a valid email address", | ||
}, | ||
{ | ||
validator: (_, value: string) => checkEmailsAreMatching(value, ["newEmail"]), | ||
}, | ||
]} | ||
> | ||
<Input | ||
prefix={ | ||
<MailOutlined | ||
style={{ | ||
fontSize: 13, | ||
}} | ||
/> | ||
} | ||
placeholder="Confirm New Email Address" | ||
/> | ||
</FormItem> | ||
<FormItem> | ||
<Button | ||
type="primary" | ||
htmlType="submit" | ||
style={{ | ||
width: "100%", | ||
}} | ||
> | ||
Change Email | ||
</Button> | ||
</FormItem> | ||
</Form> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
|
||
export default withRouter<RouteComponentProps, any>(ChangeEmailView); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for testing purposes. REMOVE BEFORE MERGING