-
Notifications
You must be signed in to change notification settings - Fork 1
Get all info user #93 #93
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
VladNesterov
wants to merge
13
commits into
master
Choose a base branch
from
Get_All_Info_User
base: master
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
337b880
RCJ-93 for switch
VladNesterov 161ddd0
RCJ-93 Get user by token and improve logic in singIn method from FnsW…
VladNesterov 271368d
RCJ-93 rename
VladNesterov a9e936a
RCJ-93 add email and name in first login, also add email and name whe…
VladNesterov f272340
RCJ-93 add new Exception Handler and finish logic with searching by t…
VladNesterov 5cc7773
RCJ-93 rewrite ResponseErrorHandleFNS.kt
VladNesterov 8ec3480
RCJ-93 add check on HttpStatus.NO_CONTENT
VladNesterov f85e365
RCJ-93 rebuild exception handler, rename dto, and add try cuth to si…
VladNesterov a9ccaa6
RCJ-93 change http status for exception
VladNesterov c2e09fa
RCJ-93 removed exception
VladNesterov 5187e14
RCJ-93 move logic from ErrorHandler to FnsReceiptWebClient.kt
VladNesterov 3fdbe24
RCJ-93 rewrite logic for login
VladNesterov 9d515ed
RCJ-93 return 404 if token not found
VladNesterov 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
9 changes: 9 additions & 0 deletions
9
fns-sdk/src/main/kotlin/space/shefer/receipt/fnssdk/dto/FnsLoginResponse.kt
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,9 @@ | ||
| package space.shefer.receipt.fnssdk.dto | ||
|
|
||
|
|
||
| class FnsLoginResponse { | ||
|
|
||
| lateinit var email: String | ||
| lateinit var name: 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
17 changes: 17 additions & 0 deletions
17
fns-sdk/src/main/kotlin/space/shefer/receipt/fnssdk/service/ResponseErrorHandleFNS.kt
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,17 @@ | ||
| package space.shefer.receipt.fnssdk.service | ||
|
|
||
| import org.springframework.http.client.ClientHttpResponse | ||
| import org.springframework.web.client.ResponseErrorHandler | ||
| import java.io.IOException | ||
|
|
||
| class ResponseErrorHandleFNS : ResponseErrorHandler { | ||
|
|
||
| @Throws(IOException::class) | ||
| override fun handleError(httpResponse: ClientHttpResponse) { | ||
|
|
||
| } | ||
|
|
||
| override fun hasError(response: ClientHttpResponse): Boolean { | ||
| return false | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -9,7 +9,9 @@ import org.springframework.stereotype.Component | |
| import org.springframework.web.client.HttpClientErrorException | ||
| import org.springframework.web.client.HttpServerErrorException | ||
| import org.springframework.web.client.RestTemplate | ||
| import space.shefer.receipt.fnssdk.excepion.AuthorizationFailedException | ||
| import space.shefer.receipt.fnssdk.dto.FnsLoginResponse | ||
| import space.shefer.receipt.fnssdk.excepion.* | ||
| import space.shefer.receipt.fnssdk.service.ResponseErrorHandleFNS | ||
| import java.net.URI | ||
| import java.util.* | ||
|
|
||
|
|
@@ -46,7 +48,6 @@ class FnsReceiptWebClient { | |
| return null | ||
| } | ||
|
|
||
|
|
||
| fun getReceiptExists(fn: String, fd: String, fp: String, time: String, money: Float): Boolean { | ||
| val moneyForUrl: Int = (money * 100).toInt() | ||
| val uri = "$HOST/v1/ofds/*/inns/*/fss/$fn/operations/1/tickets/$fd?fiscalSign=$fp&date=$time&sum=$moneyForUrl" | ||
|
|
@@ -66,7 +67,6 @@ class FnsReceiptWebClient { | |
|
|
||
| throw e | ||
| } | ||
|
|
||
| return responseEntity.statusCode == HttpStatus.NO_CONTENT | ||
| } | ||
|
|
||
|
|
@@ -84,25 +84,42 @@ class FnsReceiptWebClient { | |
| fun signUp(email: String, name: String, phone: String) { | ||
| val headers = HttpHeaders() | ||
| headers.add("Content-Type", "application/json; charset=UTF-8") | ||
| RestTemplate().exchange( | ||
| val restTemplate = RestTemplate() | ||
| restTemplate.errorHandler = ResponseErrorHandleFNS() | ||
| val responseEntity = restTemplate.exchange( | ||
| URI("$HOST/v1/mobile/users/signup"), | ||
| HttpMethod.POST, | ||
| HttpEntity("""{"email":"$email","name":"$name","phone":"$phone"}""", headers), | ||
| String::class.java | ||
| ) | ||
| if (responseEntity.statusCode == HttpStatus.NO_CONTENT) { | ||
| return | ||
| } | ||
| if (responseEntity.statusCode == HttpStatus.CONFLICT && responseEntity.body.toString() == "user exists") { | ||
| throw UserAlreadyExistsException(name); | ||
| } else if (responseEntity.statusCode == HttpStatus.BAD_REQUEST | ||
| && responseEntity.body.toString().contains("Object didn't pass validation for format email")) { | ||
| throw IncorrectEmailException(email); | ||
| } else if (responseEntity.statusCode == HttpStatus.INTERNAL_SERVER_ERROR | ||
| && responseEntity.body.toString() == "failed with code 20101") { | ||
| throw IncorrectPhoneException(phone) | ||
| } else { | ||
| throw UnexpectedHttpException() | ||
| } | ||
vladimirshefer marked this conversation as resolved.
Show resolved
Hide resolved
vladimirshefer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
|
|
||
| fun login(login: String, password: String) { | ||
| fun login(phone: String, password: String): FnsLoginResponse? { | ||
| val headers = HttpHeaders() | ||
| headers.add("Content-Type", "application/json; charset=UTF-8") | ||
| headers.add("Authorization", getAuthHeader(login, password)) | ||
| try { | ||
| RestTemplate().exchange( | ||
| return RestTemplate().exchange( | ||
vladimirshefer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| URI("$HOST/v1/mobile/users/login"), | ||
| HttpMethod.GET, | ||
| HttpEntity<String>(headers), | ||
| String::class.java | ||
| ) | ||
| FnsLoginResponse::class.java | ||
| ).body | ||
|
Member
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. поставь тут !! и в методе возвращаемый тип сделай без вопросика
Collaborator
Author
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. Расскажи подробнее, что это и как. Я даже не знаю как это загуглить) |
||
| } catch (e: HttpClientErrorException.Forbidden) { | ||
| throw AuthorizationFailedException(login, e) | ||
| } | ||
|
|
||
28 changes: 25 additions & 3 deletions
28
rest-api/src/main/java/space/shefer/receipt/rest/controller/UserController.java
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 |
|---|---|---|
| @@ -1,47 +1,69 @@ | ||
| package space.shefer.receipt.rest.controller; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.lang.Nullable; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestHeader; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestMethod; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
| import space.shefer.receipt.fnssdk.excepion.ErrorToken; | ||
| import space.shefer.receipt.fnssdk.webclient.FnsReceiptWebClient; | ||
| import space.shefer.receipt.platform.core.entity.UserProfile; | ||
| import space.shefer.receipt.platform.core.service.UserProfileService; | ||
| import space.shefer.receipt.rest.dto.UserLoginDto; | ||
| import space.shefer.receipt.rest.dto.UserPasswordRestoreDto; | ||
| import space.shefer.receipt.rest.dto.UserSignUpDto; | ||
| import space.shefer.receipt.rest.service.FnsUserService; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
|
|
||
| import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
|
|
||
|
|
||
| @RestController | ||
| public class UserController { | ||
|
|
||
| private final FnsReceiptWebClient fnsReceiptWebClient; | ||
| private final UserProfileService userProfileService; | ||
| private final FnsUserService fnsUserService; | ||
|
|
||
| @Autowired | ||
| public UserController(FnsReceiptWebClient fnsReceiptWebClient, UserProfileService userProfileService) { | ||
| public UserController(FnsReceiptWebClient fnsReceiptWebClient, UserProfileService userProfileService, FnsUserService fnsUserService) { | ||
| this.fnsReceiptWebClient = fnsReceiptWebClient; | ||
| this.userProfileService = userProfileService; | ||
| this.fnsUserService = fnsUserService; | ||
| } | ||
|
|
||
| @RequestMapping(value = "/login", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) | ||
| public String login(@RequestBody UserLoginDto userLoginDto) { | ||
| fnsReceiptWebClient.login(userLoginDto.getPhone(), userLoginDto.getPassword()); | ||
| fnsUserService.login(userLoginDto); | ||
| UserProfile userProfile = userProfileService.createOrUpdate(userLoginDto.getPhone(), userLoginDto.getPassword()); | ||
| return userProfile.getAccessToken(); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/signUp", method = RequestMethod.POST) | ||
| public void signUp(@RequestBody UserSignUpDto userSignUpDto) { | ||
| fnsReceiptWebClient.signUp(userSignUpDto.getEmail(), userSignUpDto.getName(), userSignUpDto.getPhone()); | ||
| fnsUserService.signUp(userSignUpDto); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/users/me", method = RequestMethod.GET) | ||
| public UserSignUpDto getInfoByToken(@Nullable @RequestHeader("Authorization") String authHeader) { | ||
| if (authHeader != null) { | ||
| return fnsUserService.getUserByToken(getTokenFromAuthHeader(authHeader)); | ||
| } | ||
| throw new ErrorToken(); | ||
| } | ||
|
|
||
| @RequestMapping(value = "/passwordRestore", method = RequestMethod.POST) | ||
| public void passwordRestore(@RequestBody UserPasswordRestoreDto userPasswordRestoreDto) { | ||
| fnsReceiptWebClient.passwordRestore(userPasswordRestoreDto.getPhone()); | ||
| } | ||
|
|
||
| public String getTokenFromAuthHeader(String authHeader) { | ||
| return authHeader.substring(authHeader.indexOf(" ") + 1); | ||
| } | ||
|
|
||
| } |
62 changes: 62 additions & 0 deletions
62
rest-api/src/main/java/space/shefer/receipt/rest/service/FnsUserService.java
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,62 @@ | ||
| package space.shefer.receipt.rest.service; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Service; | ||
| import space.shefer.receipt.fnssdk.dto.FnsLoginResponse; | ||
| import space.shefer.receipt.fnssdk.webclient.FnsReceiptWebClient; | ||
| import space.shefer.receipt.platform.core.entity.UserProfile; | ||
| import space.shefer.receipt.platform.core.repository.UserProfileRepository; | ||
| import space.shefer.receipt.rest.dto.UserLoginDto; | ||
| import space.shefer.receipt.rest.dto.UserSignUpDto; | ||
|
|
||
| @Service | ||
| public class FnsUserService { | ||
|
|
||
| private final UserProfileRepository userProfileRepository; | ||
| private final FnsReceiptWebClient fnsReceiptWebClient; | ||
|
|
||
| @Autowired | ||
| public FnsUserService(UserProfileRepository userProfileRepository, FnsReceiptWebClient fnsReceiptWebClient) { | ||
| this.userProfileRepository = userProfileRepository; | ||
| this.fnsReceiptWebClient = fnsReceiptWebClient; | ||
| } | ||
|
|
||
| public void signUp(UserSignUpDto userSignUpDto) { | ||
| fnsReceiptWebClient.signUp(userSignUpDto.getEmail(), userSignUpDto.getName(), userSignUpDto.getPhone()); | ||
| } | ||
|
|
||
| public UserSignUpDto getUserByToken(String authHeader) { | ||
| UserProfile userProfile = userProfileRepository.getByAccessToken(authHeader); | ||
| if (userProfile == null) { | ||
| return null; | ||
| } | ||
| UserSignUpDto userSignUpDto = new UserSignUpDto(); | ||
| userSignUpDto.setEmail(userProfile.getEmail()); | ||
| userSignUpDto.setName(userProfile.getName()); | ||
| userSignUpDto.setPhone(userProfile.getPhone()); | ||
| return userSignUpDto; | ||
| } | ||
|
|
||
| public void login(UserLoginDto userLoginDto) { | ||
| FnsLoginResponse responseEntity = fnsReceiptWebClient.login(userLoginDto.getPhone(), userLoginDto.getPassword()); | ||
| if (responseEntity != null) { | ||
| UserProfile userProfile = userProfileRepository.getByPhone(userLoginDto.getPhone()); | ||
| if (userProfile != null) { | ||
| if (!userProfile.getEmail().equals(responseEntity.email) || (!userProfile.getName().equals(responseEntity.name))) { | ||
| userProfile.setName(responseEntity.getName()); | ||
| userProfile.setEmail(responseEntity.getEmail()); | ||
| userProfileRepository.save(userProfile); | ||
| } | ||
| } | ||
| else { | ||
| UserProfile newUserProfile = new UserProfile(); | ||
| newUserProfile.setPhone(userLoginDto.getPhone()); | ||
| newUserProfile.setEmail(responseEntity.email); | ||
| newUserProfile.setName(responseEntity.name); | ||
| newUserProfile.setPassword(userLoginDto.getPassword()); | ||
| userProfileRepository.save(newUserProfile); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
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.