| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.google.code.kaptcha.Constants; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.common.exception.InvalidKaptchaException; |
| | |
| | | import com.stylefeng.guns.core.shiro.ShiroUser; |
| | | import com.stylefeng.guns.core.shiro.factory.IShiro; |
| | | import com.stylefeng.guns.core.util.ApiMenuFilter; |
| | | import com.stylefeng.guns.core.util.JwtTokenUtil; |
| | | import com.stylefeng.guns.core.util.KaptchaUtil; |
| | | import com.stylefeng.guns.core.util.SinataUtil; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.dao.TCompanyMapper; |
| | | import com.stylefeng.guns.modular.system.dao.UserMapper; |
| | | import com.stylefeng.guns.modular.system.model.Menu; |
| | | import com.stylefeng.guns.modular.system.model.SysUserCompanyScope; |
| | | import com.stylefeng.guns.modular.system.model.TCompany; |
| | | import com.stylefeng.guns.modular.system.model.User; |
| | |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.Model; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | import static com.stylefeng.guns.core.support.HttpKit.getIp; |
| | |
| | | @Slf4j |
| | | @Controller |
| | | public class LoginController extends BaseController { |
| | | |
| | | @Value("${embedded.route-switch-url}") |
| | | private String routeSwitchUrl; |
| | | |
| | | |
| | | // 快车相关菜单(isSpe=2时过滤) |
| | | private static final List<String> SPE_MENUS = Arrays.asList( |
| | |
| | | * 跳转到主页 |
| | | */ |
| | | @RequestMapping(value = "/", method = RequestMethod.GET) |
| | | public String index(Model model) throws UnsupportedEncodingException { |
| | | public String index(Model model, String routeRedirect) throws UnsupportedEncodingException { |
| | | ShiroUser shiroUser = ShiroKit.getUser(); |
| | | if (Objects.isNull(shiroUser)) { |
| | | ShiroKit.getSubject().logout(); |
| | |
| | | model.addAttribute("avatar", avatar); |
| | | model.addAttribute("userName", user.getName()); |
| | | model.addAttribute("type", 0); |
| | | addDefaultPageModel(model, routeRedirect); |
| | | |
| | | |
| | | return "/index.html"; |
| | | } |
| | | |
| | | private void addDefaultPageModel(Model model, String routeRedirect) { |
| | | String defaultPageUrl = getValidRouteRedirect(routeRedirect); |
| | | String defaultPageTitle = "首页"; |
| | | if (!"/blackboard".equals(defaultPageUrl)) { |
| | | Menu menu = menuService.selectOne( |
| | | new EntityWrapper<Menu>().eq("url", defaultPageUrl).eq("status", 1).eq("ismenu", 1)); |
| | | if (menu != null && ToolUtil.isNotEmpty(menu.getName())) { |
| | | defaultPageTitle = menu.getName(); |
| | | } |
| | | } |
| | | model.addAttribute("defaultPageUrl", defaultPageUrl); |
| | | model.addAttribute("defaultPageTitle", defaultPageTitle); |
| | | } |
| | | |
| | | private String getValidRouteRedirect(String routeRedirect) { |
| | | if (ToolUtil.isEmpty(routeRedirect)) { |
| | | return "/blackboard"; |
| | | } |
| | | String url = routeRedirect.trim(); |
| | | String lowerUrl = url.toLowerCase(); |
| | | if (!url.startsWith("/") || url.startsWith("//") |
| | | || lowerUrl.contains("http:") || lowerUrl.contains("https:") || lowerUrl.contains("javascript:")) { |
| | | return "/blackboard"; |
| | | } |
| | | return url; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | ShiroKit.getSession().setAttribute("sessionFlag", true); |
| | | |
| | | return REDIRECT + "/"; |
| | | return redirectToRouteSwitchPage(shiroUser); |
| | | } |
| | | |
| | | private String redirectToRouteSwitchPage(ShiroUser shiroUser) { |
| | | if (shiroUser == null || shiroUser.getId() == null) { |
| | | return REDIRECT + "/"; |
| | | } |
| | | try { |
| | | String token = JwtTokenUtil.generateToken(shiroUser.getId().toString()); |
| | | return REDIRECT + routeSwitchUrl + URLEncoder.encode(token, "UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.error("生成路由切换页token失败", e); |
| | | return REDIRECT + "/"; |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |