Skip to content

Commit

Permalink
[Feature] Added Login Page (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzm0809 authored Aug 23, 2023
1 parent 6b61132 commit 01ac555
Show file tree
Hide file tree
Showing 30 changed files with 778 additions and 54 deletions.
1 change: 1 addition & 0 deletions paimon-web-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ under the License.
</parent>

<artifactId>paimon-web-api</artifactId>
<name>Paimon : Web : Api</name>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
5 changes: 5 additions & 0 deletions paimon-web-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ under the License.
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

import org.apache.paimon.web.server.data.dto.LoginDto;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.data.vo.UserInfoVo;
import org.apache.paimon.web.server.service.UserService;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -48,7 +48,7 @@ public class LoginController {
* @return token string
*/
@PostMapping("/login")
public R<String> login(@Validated @RequestBody LoginDto loginDto) {
public R<UserInfoVo> login(@RequestBody LoginDto loginDto) {
return R.succeed(userService.login(loginDto));
}

Expand All @@ -65,7 +65,7 @@ public R<SaTokenInfo> tokenInfo() {
/** logout. */
@PostMapping("/logout")
public R<Void> logout() {
StpUtil.logout();
StpUtil.logout(StpUtil.getLoginIdAsInt());
return R.succeed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum Status {
USER_NOT_EXIST(10001, "user.not.exist"),
USER_PASSWORD_ERROR(10002, "user.password.error"),
USER_DISABLED_ERROR(10003, "user.is.disabled"),
USER_NOT_BING_TENANT(10004, "user.not.bing.tenant"),
/** ------------role-----------------. */
ROLE_IN_USED(10101, "role.in.used"),
ROLE_NAME_IS_EXIST(10102, "role.name.exist"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
* limitations under the License.
*/

package org.apache.paimon.web.server.data.dto;
package org.apache.paimon.web.server.data.result.exception.user;

import org.apache.paimon.web.server.data.model.Tenant;
import org.apache.paimon.web.server.data.model.User;
import org.apache.paimon.web.server.data.result.enums.Status;
import org.apache.paimon.web.server.data.result.exception.BaseException;

import lombok.Data;
/** Exception to user not bind tenant. */
public class UserNotBindTenantException extends BaseException {
private static final long serialVersionUID = 1L;

import java.util.List;

/** user data transfer object. */
@Data
public class UserDto {
private User user;
private List<Tenant> tenantList;
public UserNotBindTenantException() {
super(Status.USER_DISABLED_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.data.vo;

import org.apache.paimon.web.server.data.model.SysMenu;
import org.apache.paimon.web.server.data.model.SysRole;
import org.apache.paimon.web.server.data.model.Tenant;
import org.apache.paimon.web.server.data.model.User;

import cn.dev33.satoken.stp.SaTokenInfo;
import lombok.Data;

import java.util.List;

/** user data transfer object. */
@Data
public class UserInfoVo {
/** current user info. */
private User user;
/** current user's tenant list. */
private List<Tenant> tenantList;
/** current user's role list. */
private List<SysRole> roleList;
/** current user's token info. */
private SaTokenInfo saTokenInfo;
/** current user's menu list. */
private List<SysMenu> sysMenuList;
/** current user's tenant. */
private Tenant currentTenant;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service;

import org.apache.paimon.web.server.data.model.RoleMenu;

import com.baomidou.mybatisplus.extension.service.IService;

/** RoleMenu Service. */
public interface RoleMenuService extends IService<RoleMenu> {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import org.apache.paimon.web.server.data.tree.TreeSelect;
import org.apache.paimon.web.server.data.vo.RouterVo;

import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;
import java.util.Set;

/** Menu service. */
public interface SysMenuService {
public interface SysMenuService extends IService<SysMenu> {
/**
* Query menu list by user.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service;

import org.apache.paimon.web.server.data.model.Tenant;

import com.baomidou.mybatisplus.extension.service.IService;

/** Tenant Service. */
public interface TenantService extends IService<Tenant> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service;

import org.apache.paimon.web.server.data.model.User;
import org.apache.paimon.web.server.data.model.UserRole;

import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/** UserRole Service. */
public interface UserRoleService extends IService<UserRole> {

List<UserRole> selectUserRoleListByUserId(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.paimon.web.server.data.dto.LoginDto;
import org.apache.paimon.web.server.data.model.User;
import org.apache.paimon.web.server.data.result.exception.BaseException;
import org.apache.paimon.web.server.data.vo.UserInfoVo;

import com.baomidou.mybatisplus.extension.service.IService;

Expand All @@ -32,10 +33,10 @@ public interface UserService extends IService<User> {
/**
* login by username and password.
*
* @param loginDto login info
* @param loginDto login params
* @return {@link String}
*/
String login(LoginDto loginDto) throws BaseException;
UserInfoVo login(LoginDto loginDto) throws BaseException;

/**
* Query the list of assigned user roles.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service;

import org.apache.paimon.web.server.data.model.UserTenant;

import com.baomidou.mybatisplus.extension.service.IService;

/** Tenant Service. */
public interface UserTenantService extends IService<UserTenant> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service.impl;

import org.apache.paimon.web.server.data.model.RoleMenu;
import org.apache.paimon.web.server.mapper.RoleMenuMapper;
import org.apache.paimon.web.server.service.RoleMenuService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/** RoleMenuServiceImpl. */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu>
implements RoleMenuService {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service.impl;

import org.apache.paimon.web.server.data.model.Tenant;
import org.apache.paimon.web.server.mapper.TenantMapper;
import org.apache.paimon.web.server.service.TenantService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/** TenantServiceImpl. */
@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements TenantService {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.paimon.web.server.service.impl;

import org.apache.paimon.web.server.data.model.User;
import org.apache.paimon.web.server.data.model.UserRole;
import org.apache.paimon.web.server.mapper.UserRoleMapper;
import org.apache.paimon.web.server.service.UserRoleService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/** UserRoleServiceImpl. */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
implements UserRoleService {

@Override
public List<UserRole> selectUserRoleListByUserId(User user) {
return list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
}
}
Loading

0 comments on commit 01ac555

Please sign in to comment.