forked from fanruan/finekit
89 lines
2.7 KiB
89 lines
2.7 KiB
package com.fanruan.api.decision.user; |
|
|
|
import com.fr.decision.authority.AuthorityContext; |
|
import com.fr.decision.authority.data.User; |
|
import com.fr.decision.webservice.utils.UserSourceFactory; |
|
import com.fr.decision.webservice.utils.user.source.UserSource; |
|
import com.fr.decision.webservice.v10.user.UserService; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
import java.util.List; |
|
|
|
/** |
|
* @author richie |
|
* @version 10.0 |
|
* Created by richie on 2019-09-19 |
|
*/ |
|
public class UserKit { |
|
|
|
/** |
|
* 根据用户名获取这个用户的来源 |
|
* |
|
* @param username 用户名 |
|
* @return 用户来源 |
|
* @throws Exception 如果在获取用户的过程中出错了,则抛出此异常 |
|
*/ |
|
public static UserSource fetchUserSource(String username) throws Exception { |
|
User user = UserService.getInstance().getUserByUserName(username); |
|
return UserSourceFactory.getInstance().getUserSource(user); |
|
} |
|
|
|
public static OpenUser getUserByRequest(HttpServletRequest req) throws Exception { |
|
User user = UserService.getInstance().getUserByRequest(req); |
|
return OpenUser.wrap(user); |
|
} |
|
|
|
/** |
|
* 根据用户名获取用户信息 |
|
* |
|
* @param username 用户名 |
|
* @return 用户信息 |
|
* @throws Exception 如果获取用户出错,则抛出此异常 |
|
*/ |
|
public static OpenUser getUser(String username) throws Exception { |
|
User user = UserService.getInstance().getUserByUserName(username); |
|
return OpenUser.wrap(user); |
|
} |
|
|
|
/** |
|
* 更新一个用户信息 |
|
* |
|
* @param user 用户 |
|
* @throws Exception 更新用户信息失败则抛出此异常 |
|
*/ |
|
public static void update(OpenUser user) throws Exception { |
|
AuthorityContext.getInstance().getUserController().update(user.select()); |
|
} |
|
|
|
/** |
|
* 添加一个用户 |
|
* |
|
* @param user 用户 |
|
* @throws Exception 添加用户失败则抛出此异常 |
|
*/ |
|
public static void add(OpenUser user) throws Exception { |
|
AuthorityContext.getInstance().getUserController().update(user.select()); |
|
} |
|
|
|
/** |
|
* 通过邮箱获取用户名数组 |
|
* |
|
* @param email 邮箱 |
|
* @return 用户名数组 |
|
* @throws Exception 如果邮箱不存在则抛出此异常 |
|
*/ |
|
public static List<String> getUserNamesFromEmail(String email) throws Exception { |
|
return UserService.getInstance().getUserNamesFromEmail(email); |
|
} |
|
|
|
/** |
|
* 获取当前用户id |
|
* |
|
* @param request 请求体 |
|
* @return 用户id |
|
* @throws Exception 异常 |
|
*/ |
|
public static String getCurrentUserId(HttpServletRequest request) throws Exception { |
|
return UserService.getInstance().getCurrentUserId(request); |
|
} |
|
}
|
|
|