mirror of https://gitee.com/y_project/RuoYi.git
支持配置是否开启记住我功能
parent
89719f0570
commit
0606663fe8
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.web.controller.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -103,9 +104,10 @@ public class CommonController
|
|||
{
|
||||
// 上传文件路径
|
||||
String filePath = RuoYiConfig.getUploadPath();
|
||||
List<String> fileNames = new ArrayList<>();
|
||||
List<String> urls = new ArrayList<>();
|
||||
for (MultipartFile file : files) {
|
||||
List<String> fileNames = new ArrayList<String>();
|
||||
List<String> urls = new ArrayList<String>();
|
||||
for (MultipartFile file : files)
|
||||
{
|
||||
// 上传并返回新文件名称
|
||||
String fileName = FileUploadUtils.upload(filePath, file);
|
||||
String url = serverConfig.getUrl() + fileName;
|
||||
|
@ -151,4 +153,4 @@ public class CommonController
|
|||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,10 @@ import org.apache.shiro.SecurityUtils;
|
|||
import org.apache.shiro.authc.AuthenticationException;
|
||||
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.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
@ -14,6 +17,7 @@ import com.ruoyi.common.core.controller.BaseController;
|
|||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.web.service.ConfigService;
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
|
@ -23,15 +27,27 @@ import com.ruoyi.common.utils.StringUtils;
|
|||
@Controller
|
||||
public class SysLoginController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 是否开启记住我功能
|
||||
*/
|
||||
@Value("${shiro.rememberMe.enabled: false}")
|
||||
private boolean rememberMe;
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@GetMapping("/login")
|
||||
public String login(HttpServletRequest request, HttpServletResponse response)
|
||||
public String login(HttpServletRequest request, HttpServletResponse response, ModelMap mmap)
|
||||
{
|
||||
// 如果是Ajax请求,返回Json字符串。
|
||||
if (ServletUtils.isAjaxRequest(request))
|
||||
{
|
||||
return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
|
||||
}
|
||||
|
||||
// 是否开启记住我
|
||||
mmap.put("isRemembered", rememberMe);
|
||||
// 是否开启用户注册
|
||||
mmap.put("isAllowRegister", configService.getKey("sys.account.registerUser"));
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,9 @@ shiro:
|
|||
maxSession: -1
|
||||
# 踢出之前登录的/之后登录的用户,默认踢出之前登录的用户
|
||||
kickoutAfter: false
|
||||
rememberMe:
|
||||
# 是否开启记住我
|
||||
enabled: true
|
||||
|
||||
# 防止XSS攻击
|
||||
xss:
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Thymeleaf</li>
|
||||
<li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Bootstrap</li>
|
||||
</ul>
|
||||
<strong th:if="${@config.getKey('sys.account.registerUser')}">还没有账号? <a th:href="@{/register}">立即注册»</a></strong>
|
||||
<strong th:if="${isAllowRegister}">还没有账号? <a th:href="@{/register}">立即注册»</a></strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-5">
|
||||
|
@ -56,7 +56,7 @@
|
|||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="checkbox-custom" th:classappend="${captchaEnabled==false} ? 'm-t'">
|
||||
<div class="checkbox-custom" th:if="${isRemembered}" th:classappend="${captchaEnabled==false} ? 'm-t'">
|
||||
<input type="checkbox" id="rememberme" name="rememberme"> <label for="rememberme">记住我</label>
|
||||
</div>
|
||||
<button class="btn btn-success btn-block" id="btnSubmit" data-loading="正在验证登录,请稍后...">登录</button>
|
||||
|
|
|
@ -123,6 +123,12 @@ public class ShiroConfig
|
|||
@Value("${shiro.user.unauthorizedUrl}")
|
||||
private String unauthorizedUrl;
|
||||
|
||||
/**
|
||||
* 是否开启记住我功能
|
||||
*/
|
||||
@Value("${shiro.rememberMe.enabled: false}")
|
||||
private boolean rememberMe;
|
||||
|
||||
/**
|
||||
* 缓存管理器 使用Ehcache实现
|
||||
*/
|
||||
|
@ -236,7 +242,7 @@ public class ShiroConfig
|
|||
// 设置realm.
|
||||
securityManager.setRealm(userRealm);
|
||||
// 记住我
|
||||
securityManager.setRememberMeManager(rememberMeManager());
|
||||
securityManager.setRememberMeManager(rememberMe ? rememberMeManager() : null);
|
||||
// 注入缓存管理器;
|
||||
securityManager.setCacheManager(getEhCacheManager());
|
||||
// session管理器
|
||||
|
|
Loading…
Reference in New Issue