Skip to content

Commit

Permalink
Merge pull request #102 from Tech-Harbor/Bezsmertnyi
Browse files Browse the repository at this point in the history
Bezsmertnyi | Checkstyle, Added Log, SendMessageEmail
  • Loading branch information
Vladik-gif authored Apr 11, 2024
2 parents ad3141c + 5426f51 commit 61c4eab
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class AuthController {
private static final String REQUEST_EMAIL_UPDATE_PASSWORD = "/request/email";
private static final String ACTIVE_USER = "/active";
private static final String INFO = "/accouth";
private static final String SEND_MESSAGE_EMAIL_NOT_ACTIVE = "/sendMessageEmail";

@PostMapping(SIGNUP_URI)
@SecurityRequirement(name = "Bearer Authentication")
Expand Down Expand Up @@ -121,4 +122,14 @@ public void requestEmailUpdatePassword(@RequestBody @Validated final EmailReques
public void activeUser(@RequestHeader(AUTHORIZATION) final String jwt) {
authService.activeUser(jwt);
}

@PostMapping(SEND_MESSAGE_EMAIL_NOT_ACTIVE)
@Operation(summary = "Re-sending the account activation letter if the first letter was not successful")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK")
}
)
public void sendEmailSecondActive() {
authService.sendEmailActive();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public interface AuthService {
* @Returns void
*/
void activeUser(String jwt);
/**
* This method sends a letter to the user's mail if he did not have time to activate the account the first time
*/
void sendEmailActive();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.example.backend.utils.enums.RegisterAuthStatus;
import com.example.backend.utils.enums.Role;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -27,6 +28,7 @@
import static com.example.backend.web.exception.RequestException.badRequestException;

@Service
@Slf4j
@RequiredArgsConstructor
public class AuthServiceImpl implements AuthService {

Expand Down Expand Up @@ -58,6 +60,8 @@ public void signup(final RegisterRequest registerRequest) {

userService.mySave(user);

log.info("Register User: " + user);

mailService.sendEmail(user, MailType.REGISTRATION, new Properties());
}

Expand All @@ -78,6 +82,8 @@ public AuthResponse login(final AuthRequest authRequest) {

final var refreshToken = jwtService.generateRefreshToken(authentication);

log.info("Login user: " + authentication);

return AuthResponse.builder()
.accessToken(accessToken)
.refreshToken(refreshToken)
Expand All @@ -92,6 +98,8 @@ public void formUpdatePassword(final String jwt, final PasswordRequest passwordR

userId.setPassword(myPasswordEncoder.passwordEncoder().encode(passwordRequest.password()));

log.info("Update Password :" + userId.getLastname());

userService.mySave(userId);
}

Expand All @@ -101,6 +109,8 @@ public void requestEmailUpdatePassword(final EmailRequest emailRequest) {
() -> badRequestException("This email is not exists")
);

log.info("Email user" + emailUser.getEmail());

mailService.sendEmail(emailUser, MailType.NEW_PASSWORD, new Properties());
}

Expand All @@ -112,6 +122,19 @@ public void activeUser(final String jwt) {

activeUserTrue.setEnabled(true);

log.info("Active user: " + activeUserTrue.getLastname());

userService.mySave(activeUserTrue);
}

@Override
public void sendEmailActive() {
final var id = 1L;

final var user = userService.getById(id);

log.info("SendEmail user: " + user.getLastname());

mailService.sendEmail(user, MailType.REGISTRATION, new Properties());
}
}
1 change: 1 addition & 0 deletions src/main/java/com/example/backend/web/User/UserEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Table(name = "users")
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Optional<UserEntity> getByEmail(final String email) {
@Override
public List<UserDTO> getByAllUser() {
return userRepository.findAll().stream()
.map(userFactory::apply)
.map(userFactory)
.collect(Collectors.toList());
}

Expand Down
34 changes: 2 additions & 32 deletions src/main/resources/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@
<module name="NonEmptyAtclauseDescription"/>
<module name="InvalidJavadocPosition"/>

<module name="SummaryJavadoc">
<property name="forbiddenSummaryFragments"
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>

<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target"
Expand Down Expand Up @@ -270,8 +265,6 @@
LITERAL_YIELD, LITERAL_CASE"/>
</module>

<!-- Checks for Naming Conventions. -->
<!-- See https://checkstyle.org/checks/naming/index.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
Expand All @@ -281,22 +274,15 @@
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>

<!-- Checks for imports -->
<!-- See https://checkstyle.org/checks/imports/index.html -->
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="IllegalImport"/>
<module name="RedundantImport"/>

<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>

<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/checks/sizes/index.html -->
<module name="MethodLength"/>
<module name="ParameterNumber"/>

<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/checks/whitespace/index.html -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
Expand All @@ -307,42 +293,26 @@
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>

<!-- Modifier Checks -->
<!-- See https://checkstyle.org/checks/modifier/index.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/checks/blocks/index.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/checks/coding/index.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MissingSwitchDefault"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->
<!-- See https://checkstyle.org/checks/design/index.html -->
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>

<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/checks/misc/index.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="TodoComment"/>
<module name="UpperEll"/>


</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,22 @@ void activeUserTest() {
assertTrue(userActive.getEnabled());
}

@Test
void sendEmailActiveTest() {
final var id = 1L;

final UserEntity userId = UserEntity.builder()
.id(id)
.build();

when(userService.getById(id)).thenReturn(userId);

authService.sendEmailActive();

verify(userService).getById(id);

verify(mailService).sendEmail(any(UserEntity.class), eq(MailType.REGISTRATION), any(Properties.class));
}

private static final class PasswordEncoderTestUtils implements PasswordEncoder {
@Override
Expand Down

0 comments on commit 61c4eab

Please sign in to comment.