We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Разместить в interview/code_review/medium
Дан следующий класс:
package interview.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; import interview.model.User; import interview.repository.UserRepository; import interview.util.MailSenderUtil; import java.util.Optional; import java.util.UUID; import java.util.Random; import java.util.stream.Collectors; @RestController public class SessionController { @Autowired UserRepository userRepository; @GetMapping("/session") private void getSession(@RequestParam Integer userId) { Optional<User> user = userRepository.findById(userId); String code = new Random() .ints(0, 9) .limit(6) .mapToObj(String::valueOf) .collect(Collectors.joining()); if (user.isPresent()) { user.get().setConfirmationCode(code); MailSenderUtil.sendEmail(user.get().getEmail(), "Enter code: " + code); userRepository.save(user.get()); } else { throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "User not found"); } } @PostMapping("/session/confirm") private User confirmSession(@RequestParam Integer userId, @RequestParam String code) { Optional<User> user = userRepository.findById(userId); String session = UUID.randomUUID().toString(); if (user.isPresent()) { if (code.equals(user.get().getConfirmationCode())) { user.get().setSession(session); userRepository.save(user.get()); return user.get(); } else { throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Wrong code"); } } else { throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "User not found"); } } }
Необходимо провести и расписать проблемы как на code review, с пояснениями.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Разместить в interview/code_review/medium
Дан следующий класс:
Необходимо провести и расписать проблемы как на code review, с пояснениями.
The text was updated successfully, but these errors were encountered: