-
Notifications
You must be signed in to change notification settings - Fork 891
Add reset user password action #1320
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
346e5e4
Add UpdateUserHashedPassword query
BrunoQuaresma 4bd7557
chore: Merge branch 'main' of github.com:coder/coder into bq/update-u…
BrunoQuaresma de39cf5
Add database functions
BrunoQuaresma 2fe1716
Add update user password endpoint
BrunoQuaresma 212020a
Add tests and fixes
BrunoQuaresma 2699445
Remove confirmation and fix lint issues
BrunoQuaresma 355f163
Return hash error as server error
BrunoQuaresma 56b29fd
Update coderd/database/databasefake/databasefake.go
BrunoQuaresma 30b8f15
Improve readbility
BrunoQuaresma f6be255
Add RBAC
BrunoQuaresma 5df5763
Fix route
BrunoQuaresma b9dbd64
Merge branch 'bq/update-user-password' of github.com:coder/coder into…
BrunoQuaresma 69af903
Add missing TS types
BrunoQuaresma d85092b
Update update password request params
BrunoQuaresma d35139c
Add FE for reset user password
BrunoQuaresma 2a9b9be
Merge branch 'main' of github.com:coder/coder into bq/fe/update-user-…
BrunoQuaresma 8957339
Add reset password dialog to storybook
BrunoQuaresma e388f8a
Add tests
BrunoQuaresma 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
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
23 changes: 23 additions & 0 deletions
23
site/src/components/ResetPasswordDialog/ResetPasswordDialog.stories.tsx
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,23 @@ | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { MockUser } from "../../testHelpers" | ||
import { generateRandomString } from "../../util/random" | ||
import { ResetPasswordDialog, ResetPasswordDialogProps } from "./ResetPasswordDialog" | ||
|
||
export default { | ||
title: "components/ResetPasswordDialog", | ||
component: ResetPasswordDialog, | ||
argTypes: { | ||
onClose: { action: "onClose" }, | ||
onConfirm: { action: "onConfirm" }, | ||
}, | ||
} | ||
|
||
const Template: Story<ResetPasswordDialogProps> = (args: ResetPasswordDialogProps) => <ResetPasswordDialog {...args} /> | ||
|
||
export const Example = Template.bind({}) | ||
Example.args = { | ||
open: true, | ||
user: MockUser, | ||
newPassword: generateRandomString(12), | ||
} |
69 changes: 69 additions & 0 deletions
69
site/src/components/ResetPasswordDialog/ResetPasswordDialog.tsx
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,69 @@ | ||
import DialogActions from "@material-ui/core/DialogActions" | ||
import DialogContent from "@material-ui/core/DialogContent" | ||
import DialogContentText from "@material-ui/core/DialogContentText" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import React from "react" | ||
import * as TypesGen from "../../api/typesGenerated" | ||
import { CodeBlock } from "../CodeBlock/CodeBlock" | ||
import { Dialog, DialogActionButtons, DialogTitle } from "../Dialog/Dialog" | ||
|
||
export interface ResetPasswordDialogProps { | ||
open: boolean | ||
onClose: () => void | ||
onConfirm: () => void | ||
user?: TypesGen.User | ||
newPassword?: string | ||
loading: boolean | ||
} | ||
|
||
export const Language = { | ||
title: "Reset password", | ||
message: (username?: string): JSX.Element => ( | ||
<> | ||
You will need to send <strong>{username}</strong> the following password: | ||
</> | ||
), | ||
confirmText: "Reset password", | ||
} | ||
|
||
export const ResetPasswordDialog: React.FC<ResetPasswordDialogProps> = ({ | ||
open, | ||
onClose, | ||
onConfirm, | ||
user, | ||
newPassword, | ||
loading, | ||
}) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Dialog open={open} onClose={onClose}> | ||
<DialogTitle title={Language.title} /> | ||
|
||
<DialogContent> | ||
<DialogContentText variant="subtitle2">{Language.message(user?.username)}</DialogContentText> | ||
|
||
<DialogContentText component="div"> | ||
<CodeBlock lines={[newPassword ?? ""]} className={styles.codeBlock} /> | ||
</DialogContentText> | ||
</DialogContent> | ||
|
||
<DialogActions> | ||
<DialogActionButtons | ||
onCancel={onClose} | ||
confirmText={Language.confirmText} | ||
onConfirm={onConfirm} | ||
confirmLoading={loading} | ||
/> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
codeBlock: { | ||
minHeight: "auto", | ||
userSelect: "all", | ||
width: "100%", | ||
}, | ||
})) |
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
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,19 @@ | ||
/** | ||
* Generate a cryptographically secure random string using the specified number | ||
* of bytes then encode with base64. | ||
* | ||
* Base64 encodes 6 bits per character and pads with = so the length will not | ||
* equal the number of randomly generated bytes. | ||
* @see <https://developer.mozilla.org/en-US/docs/Glossary/Base64#encoded_size_increase> | ||
*/ | ||
export const generateRandomString = (bytes: number): string => { | ||
const byteArr = window.crypto.getRandomValues(new Uint8Array(bytes)) | ||
// The types for `map` don't seem to support mapping from one array type to | ||
// another and `String.fromCharCode.apply` wants `number[]` so loop like this | ||
// instead. | ||
const strArr: string[] = [] | ||
for (const byte of byteArr) { | ||
strArr.push(String.fromCharCode(byte)) | ||
} | ||
return btoa(strArr.join("")) | ||
} |
Oops, something went wrong.
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.
In the future we may want to find a way to make the XService give the component the user instead of the user id, but this is fine for now.
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.
Yes, I've been wondering about that, instead of passing a userId, we could just send the full user object to make things easier but it makes it hard to sync, if we need it, in case the same user is updated by any other action. Using the ID we keep the reference to the user in the list which is always updated since it is the source of the truth. Makes sense?