This repository was archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Implementing zxcvbn instead of stupid rules #272
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
268447b
Small refactorings
open-schnick 1722595
Refactored ruleChecks in Profile
open-schnick b45ff85
Added basic wrapper component and dependency
open-schnick 4b1dc8e
More refactoring
open-schnick 80fb56f
Refactorings, Removed useless rules
open-schnick d02615b
Fixed submit function in Profile
open-schnick 5031a42
Renaming works again
open-schnick 8b7d3f7
Profile now checks for updates
open-schnick a05d76b
Removed Todos, added fixmes
open-schnick 25756ad
Removed useless asyncs
open-schnick d40b8a0
Updated Snapshots
open-schnick fcd611d
Merge branch 'master' into feature/zxcvbn
open-schnick 4a0198c
Comments
open-schnick fe01983
Prettier
open-schnick 1c671b9
Implemented changes requested by @qvalentin
open-schnick 9f032ad
Updated Snapshots
open-schnick 79092e6
Prettier
open-schnick bc31c95
Fixed password strength check
open-schnick 1a79534
Merge branch 'master' into feature/zxcvbn
open-schnick fdc156a
Fixed folderContentMock.json formatting
open-schnick cfe8e9b
Updated Snapshot
open-schnick 02f2fbd
Automaticly add new snapshots to pre-push hook
open-schnick f16e10f
Merge branch 'master' into feature/zxcvbn
open-schnick 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
eslint --max-warnings 0 src --ext .ts --ext .tsx --cache | ||
npm test -- --watchAll=false | ||
git add -A src | ||
Large diffs are not rendered by default.
Oops, something went wrong.
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,8 @@ | ||
/** | ||
* Interface describing the standart return value of the backend | ||
*/ | ||
// FIXME implement it if needed. | ||
export interface ApiStatusResponse { | ||
responseCode: number | ||
responseStatus: { statusMessage: string; message: string } | ||
} |
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 was deleted.
Oops, something went wrong.
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,37 @@ | ||
import React, { Suspense } from "react" | ||
import { PasswordFeedback } from "react-password-strength-bar" | ||
|
||
// lazy load the lib | ||
const PasswordStrengthBar = React.lazy( | ||
() => import("react-password-strength-bar") | ||
) | ||
|
||
type PasswordStrengthBarWrapperArgs = { | ||
currentPassword: string | ||
scoreChangeCallback: (score: number, feedback: PasswordFeedback) => void | ||
} | ||
|
||
// a small component wrapping the password strength checks by lazy loading the component if necessary. | ||
const PasswordStrengthBarWrapper = ({ | ||
currentPassword, | ||
scoreChangeCallback, | ||
}: PasswordStrengthBarWrapperArgs): JSX.Element | null => { | ||
// if the user typed something show the component | ||
if (currentPassword.length > 0) { | ||
return ( | ||
<Suspense fallback={""}> | ||
<PasswordStrengthBar | ||
password={currentPassword} | ||
onChangeScore={(score, feedback) => | ||
scoreChangeCallback(score, feedback) | ||
} | ||
scoreWords={["weak", "weak", "ok", "strong", "epic"]} | ||
/> | ||
</Suspense> | ||
) | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
export { PasswordStrengthBarWrapper } |
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 |
---|---|---|
|
@@ -5,15 +5,12 @@ import UserInformationInput, { | |
} from "./UserInformationInput" | ||
import { useSelector } from "react-redux" | ||
import { RootState } from "../../../background/redux/store" | ||
import { | ||
DEFAULT_ALERT_DURATION, | ||
MIN_PASSWORD_LENGTH, | ||
} from "../../../background/constants" | ||
import { DEFAULT_ALERT_DURATION } from "../../../background/constants" | ||
import { | ||
changeUserInformation, | ||
UserInformation, | ||
} from "../../../background/api/userInformation" | ||
import { notMinStrLength } from "../../../background/methods/checkInput" | ||
import { ApiStatusResponse } from "../../../background/api/sharedApiTypes" | ||
import edit_svg from "../../../assets/images/icons/material.io/edit_white_24dp.svg" | ||
import { hashPassword } from "../../../background/methods/passwords" | ||
|
||
|
@@ -59,75 +56,81 @@ export default function Profile(): ReactElement { | |
} | ||
|
||
function changeEditMode(): void { | ||
console.log("[PROFILE] changedEditMode") | ||
console.log("[Profile] changedEditMode") | ||
setIsEditing(!isEditing) | ||
} | ||
|
||
const handleSubmit = async (inputUser: UserInformationInputInterface) => { | ||
console.log("[PROFILE] handleSubmit") | ||
let newUser: UserInformation = { | ||
groups: user.groups, | ||
userId: user.userId, | ||
const handleSubmit = async (userInput: UserInformationInputInterface) => { | ||
console.log("[Profile] handleSubmit") | ||
|
||
let updatedUser: UserInformation = { | ||
...user, | ||
username: userInput.username, | ||
} | ||
if (!inputUser.username) { | ||
|
||
if (userInput.password) { | ||
// if the user updated the password | ||
const hashedPassword = await hashPassword(userInput.password) | ||
updatedUser.password = hashedPassword | ||
updatedUser.confirmationPassword = hashedPassword | ||
} else if (user.username === userInput.username) { | ||
// if the new username is the old one show erorr instead of calling the backend | ||
// FIXME should we even show something here? | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
"Error: Please choose an username." | ||
"Error: No Changes." | ||
) | ||
return | ||
} | ||
newUser["username"] = inputUser.username | ||
if (inputUser.password || inputUser.passwordConfirmation) { | ||
if (inputUser.password !== inputUser.passwordConfirmation) { | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
"Error: Password and password confirmation must match." | ||
) | ||
return | ||
} | ||
if ( | ||
inputUser.password.match(/\d/) == null || | ||
inputUser.password.match(/[a-z]/) == null || | ||
inputUser.password.match(/[A-Z]/) == null || | ||
notMinStrLength(inputUser.password, MIN_PASSWORD_LENGTH) | ||
) { | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
"Error: Please pay attention to the notes below the input fields." | ||
) | ||
return | ||
} | ||
newUser["password"] = await hashPassword(inputUser.password) | ||
newUser["confirmationPassword"] = newUser["password"] | ||
} | ||
|
||
await changeUserInformation(newUser) | ||
// trigger api call | ||
await changeUserInformation(updatedUser) | ||
.then((res) => { | ||
changeEditMode() | ||
// FIXME this does never appear, because we rerender it and this gets lost | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alerts should be defined global. Would need a lot more refacotring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Y. Dont know why we are not using something like this: https://www.npmjs.com/package/react-notifications |
||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"success", | ||
"Worked: " + res | ||
) | ||
}) | ||
.catch((err) => { | ||
console.log("Error:" + err) | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
"Error: " + err | ||
.catch(({ responseStatus, responseCode }: ApiStatusResponse) => { | ||
console.log( | ||
"[Profile] Error: (" + | ||
responseCode + | ||
") - " + | ||
responseStatus.message | ||
) | ||
|
||
// 409 === Username already taken | ||
if (responseCode === 409) { | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
"Error: Username already taken" | ||
) | ||
} else { | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
"Error: " + responseStatus.message | ||
) | ||
} | ||
}) | ||
} | ||
|
||
function EditProfile(): ReactElement { | ||
return ( | ||
<> | ||
<UserInformationInput | ||
triggerAlert={handleAlertVisibility} | ||
triggerAlert={(errorMessage: string) => | ||
handleAlertVisibility( | ||
DEFAULT_ALERT_DURATION, | ||
"danger", | ||
errorMessage | ||
) | ||
} | ||
submitFunction={handleSubmit} | ||
presets={{ username: user.username ?? "", password: "" }} | ||
/> | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.