-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Feature/1164 #1165
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
Open
DominikLudwiczak
wants to merge
11
commits into
gitroomhq:main
Choose a base branch
from
DominikLudwiczak:feature/1055
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/1164 #1165
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fc094a2
fix cors & running scripts
DominikLudwiczak 5400629
delete ignoredBuiltDependencies from package.json
DominikLudwiczak 909d714
delete unnecessary log from logger
DominikLudwiczak 0148f54
revert changes on package.json
DominikLudwiczak 0eea872
Merge branch 'feature/sign-in-issue' into feature/1055
DominikLudwiczak 4f4465e
Merge branch 'main' into feature/1163
DominikLudwiczak c9eb3b2
change password feature
DominikLudwiczak f71199c
revert previous changes
DominikLudwiczak f30d047
fix User model import
DominikLudwiczak e9ca64b
allow change password only for local users
DominikLudwiczak 9ffe670
check for null pointer
DominikLudwiczak 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,18 @@ import { OrganizationService } from '@gitroom/nestjs-libraries/database/prisma/o | |
| import { AddTeamMemberDto } from '@gitroom/nestjs-libraries/dtos/settings/add.team.member.dto'; | ||
| import { ApiTags } from '@nestjs/swagger'; | ||
| import { AuthorizationActions, Sections } from '@gitroom/backend/services/auth/permissions/permission.exception.class'; | ||
| import { User } from 'facebook-nodejs-business-sdk'; | ||
| import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request'; | ||
| import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service'; | ||
| import { ChangePasswordDto } from '@gitroom/nestjs-libraries/dtos/settings/change.password.dto'; | ||
| import { AuthService as AuthChecker } from '@gitroom/helpers/auth/auth.service'; | ||
|
|
||
| @ApiTags('Settings') | ||
| @Controller('/settings') | ||
| export class SettingsController { | ||
| constructor( | ||
| private _organizationService: OrganizationService | ||
| private _organizationService: OrganizationService, | ||
| private _userService: UsersService | ||
| ) {} | ||
|
|
||
| @Get('/team') | ||
|
|
@@ -46,4 +52,16 @@ export class SettingsController { | |
| ) { | ||
| return this._organizationService.deleteTeamMember(org, id); | ||
| } | ||
|
|
||
| @Post('/change-password') | ||
| async changePassword( | ||
| @GetUserFromRequest() user: User, | ||
| @Body() body: ChangePasswordDto | ||
| ) { | ||
| const userWithPassword = await this._userService.getUserById(user.id); | ||
| if(!userWithPassword || !AuthChecker.comparePassword(body.oldPassword, userWithPassword.password)) { | ||
|
||
| return false; | ||
| } | ||
| return this._userService.updatePassword(user.id, body.password); | ||
| } | ||
| } | ||
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
106 changes: 106 additions & 0 deletions
106
apps/frontend/src/components/settings/change-password.component.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,106 @@ | ||
| 'use client'; | ||
|
|
||
| import { useForm, SubmitHandler, FormProvider } from 'react-hook-form'; | ||
| import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; | ||
| import { Button } from '@gitroom/react/form/button'; | ||
| import { Input } from '@gitroom/react/form/input'; | ||
| import { useMemo, useState } from 'react'; | ||
| import { classValidatorResolver } from '@hookform/resolvers/class-validator'; | ||
| import { ChangePasswordDto } from '@gitroom/nestjs-libraries/dtos/settings/change.password.dto'; | ||
| import { useT } from '@gitroom/react/translation/get.transation.service.client'; | ||
| import { useToaster } from '@gitroom/react/toaster/toaster'; | ||
| type Inputs = { | ||
| oldPassword: string; | ||
| password: string; | ||
| repeatPassword: string; | ||
| }; | ||
|
|
||
| export const ChangePassword = () => { | ||
| const [loading, setLoading] = useState(false); | ||
| const t = useT(); | ||
| const toaster = useToaster(); | ||
| const [state, setState] = useState(false); | ||
| const resolver = useMemo(() => { | ||
| return classValidatorResolver(ChangePasswordDto); | ||
| }, []); | ||
| const form = useForm<Inputs>({ | ||
| resolver, | ||
| mode: 'onChange', | ||
| }); | ||
| const fetchData = useFetch(); | ||
| const onSubmit: SubmitHandler<Inputs> = async (data) => { | ||
| setLoading(true); | ||
|
|
||
| const response = await fetchData('/settings/change-password', { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| ...data, | ||
| }), | ||
| }); | ||
| const change = await response.json(); | ||
| console.log(change); | ||
| if (!change) { | ||
| form.setError('password', { | ||
| type: 'manual', | ||
| message: t('password_change_failed', 'Your password change has failed. Please try again.'), | ||
| }); | ||
| toaster.show('Password change failed', 'warning'); | ||
| setLoading(false); | ||
| return false; | ||
| } | ||
| setState(true); | ||
| setLoading(false); | ||
| }; | ||
| return ( | ||
| <div className="flex flex-col"> | ||
| <h3 className="text-[20px]">{t('change_password', 'Change Password')}</h3> | ||
| <FormProvider {...form}> | ||
| <form> | ||
| {!state ? ( | ||
| <> | ||
| <div className="space-y-4 text-textColor"> | ||
| <Input | ||
| label="Old Password" | ||
| translationKey="label_old_password" | ||
| {...form.register('oldPassword')} | ||
| type="password" | ||
| placeholder={t('label_old_password', 'Password')} | ||
| /> | ||
| <Input | ||
| label="New Password" | ||
| translationKey="label_new_password" | ||
| {...form.register('password')} | ||
| type="password" | ||
| placeholder={t('label_password', 'Password')} | ||
| /> | ||
| <Input | ||
| label="Repeat Password" | ||
| translationKey="label_repeat_password" | ||
| {...form.register('repeatPassword')} | ||
| type="password" | ||
| placeholder={t('label_repeat_password', 'Repeat Password')} | ||
| /> | ||
| </div> | ||
| <div className="text-center mt-6"> | ||
| <div className="w-full flex"> | ||
| <Button className="flex-1" loading={loading} onClick={form.handleSubmit(onSubmit)}> | ||
| {t('change_password', 'Change Password')} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <div className="text-start mt-6"> | ||
| {t( | ||
| 'we_successfully_changed_your_password', | ||
| 'We successfully changed your password' | ||
| )} | ||
| </div> | ||
| </> | ||
| )} | ||
| </form> | ||
| </FormProvider> | ||
| </div> | ||
| ); | ||
| }; |
21 changes: 21 additions & 0 deletions
21
libraries/nestjs-libraries/src/dtos/settings/change.password.dto.ts
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,21 @@ | ||
| import { makeId } from "@gitroom/nestjs-libraries/services/make.is"; | ||
| import { IsDefined, IsIn, IsString, MinLength, ValidateIf } from "class-validator"; | ||
|
|
||
| export class ChangePasswordDto { | ||
| @IsString() | ||
| @IsDefined() | ||
| oldPassword: string; | ||
|
|
||
| @IsString() | ||
| @IsDefined() | ||
| @MinLength(3) | ||
| password: string; | ||
|
|
||
| @IsString() | ||
| @IsDefined() | ||
| @IsIn([makeId(10)], { | ||
| message: 'Passwords do not match', | ||
| }) | ||
| @ValidateIf((o) => o.password !== o.repeatPassword) | ||
| repeatPassword: 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 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
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
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.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
right, I pushed change