Skip to content

Commit

Permalink
[Fix][API] Fix that the response body does not return the token attri…
Browse files Browse the repository at this point in the history
…bute after successful login (apache#21)

* Fix that the response body does not return the token attribute after successful login

* fix code style

* Add application ports
  • Loading branch information
zhuangchong authored Feb 20, 2023
1 parent 5ec3888 commit 96ace88
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 80 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class AuthController {
@GetMapping("/userRole")
@ApiOperation(value = "check relation between user and role", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "user name", dataType = "String"),
@ApiImplicitParam(name = "roleName", value = "role name", dataType = "String"),
@ApiImplicitParam(name = "username", value = "user name", dataType = "String"),
@ApiImplicitParam(name = "roleName", value = "role name", dataType = "String"),
})
public Result<Boolean> userRole(@RequestParam("username") @NotNull String username, @RequestParam("roleName") @NotNull String roleName){
final boolean b = roleServiceImpl.checkUserRole(username, roleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Result<Void> updateScriptParam(@ApiParam(value = "script id", required =
@GetMapping("/{scriptId}/param")
@ApiOperation(value = "fetch script param", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "script id", dataType = "Integer"),
@ApiImplicitParam(name = "id", value = "script id", dataType = "Integer"),
})
public Result<List<ScriptParamRes>> fetchScriptParam(@ApiParam(value = "script id", required = true) @PathVariable(value = "scriptId") Integer scriptId) {
return Result.success(iScriptService.fetchScriptParam(scriptId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class BaseUserInfoRes {
private int id;
@ApiModelProperty(value = "user name", dataType = "String")
private String name;
@ApiModelProperty(value = "user token", dataType = "String")
private String token;
@ApiModelProperty(value = "user status", dataType = "type")
private byte status;
@ApiModelProperty(value = "user type", dataType = "type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@

import static org.apache.seatunnel.server.common.SeatunnelErrorEnum.USERNAME_PASSWORD_NO_MATCHED;

import org.apache.seatunnel.app.common.UserTokenStatusEnum;
import org.apache.seatunnel.app.dal.dao.IUserDao;
import org.apache.seatunnel.app.dal.entity.User;
import org.apache.seatunnel.app.domain.dto.user.ListUserDto;
import org.apache.seatunnel.app.domain.dto.user.UpdateUserDto;
import org.apache.seatunnel.app.domain.dto.user.UserLoginLogDto;
import org.apache.seatunnel.app.domain.request.user.AddUserReq;
import org.apache.seatunnel.app.domain.request.user.UpdateUserReq;
import org.apache.seatunnel.app.domain.request.user.UserListReq;
import org.apache.seatunnel.app.domain.request.user.UserLoginReq;
import org.apache.seatunnel.app.domain.response.PageInfo;
import org.apache.seatunnel.app.domain.response.user.AddUserRes;
import org.apache.seatunnel.app.domain.response.user.UserSimpleInfoRes;
import org.apache.seatunnel.app.security.JwtUtils;
import org.apache.seatunnel.app.service.IRoleService;
import org.apache.seatunnel.app.service.IUserService;
import org.apache.seatunnel.app.utils.PasswordUtils;
Expand All @@ -54,6 +57,9 @@ public class UserServiceImpl implements IUserService {
@Resource
private IRoleService roleServiceImpl;

@Resource
private JwtUtils jwtUtils;

@Value("${user.default.passwordSalt:seatunnel}")
private String defaultSalt;

Expand Down Expand Up @@ -142,7 +148,19 @@ public UserSimpleInfoRes login(UserLoginReq req) {
if (Objects.isNull(user)) {
throw new SeatunnelException(USERNAME_PASSWORD_NO_MATCHED);
}
return translate(user);

UserSimpleInfoRes translate = translate(user);
final String token = jwtUtils.genToken(translate.toMap());
translate.setToken(token);

final UserLoginLogDto logDto = UserLoginLogDto.builder()
.token(token)
.tokenStatus(UserTokenStatusEnum.ENABLE.enable())
.userId(user.getId())
.build();
userDaoImpl.insertLoginLog(logDto);

return translate;
}

private UserSimpleInfoRes translate(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# limitations under the License.
#

server:
port: 8801

spring:
application:
name: seatunnel
Expand Down
2 changes: 1 addition & 1 deletion seatunnel-ui/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

NODE_ENV=development

VITE_APP_DEV_WEB_URL=''
VITE_APP_DEV_WEB_URL='http://127.0.0.1:8801'
1 change: 1 addition & 0 deletions seatunnel-ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
node_modules
dist
dist-ssr
package-lock.json

.pnpm-debug.log

0 comments on commit 96ace88

Please sign in to comment.