update 2021年11月6日17:04:29
parent
c65968e420
commit
eba8a75554
|
|
@ -4,6 +4,7 @@ import com.github.pagehelper.PageInfo;
|
|||
import com.zhangmeng.api.service.admin_manager.UserControllerApi;
|
||||
import com.zhangmeng.model.base.baseController.BaseController;
|
||||
import com.zhangmeng.model.base.baseUtil.CommonUtil;
|
||||
import com.zhangmeng.model.bean.TokenTools;
|
||||
import com.zhangmeng.model.dto.query.QueryParams;
|
||||
import com.zhangmeng.model.entity.Role;
|
||||
import com.zhangmeng.model.entity.User;
|
||||
|
|
@ -29,6 +30,9 @@ public class UserController extends BaseController implements UserControllerApi
|
|||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private TokenTools tokenTools;
|
||||
|
||||
@Override
|
||||
@PostMapping("/save")
|
||||
public Result save(@RequestParam @RequestBody Map<String, Object> parms) {
|
||||
|
|
@ -77,7 +81,8 @@ public class UserController extends BaseController implements UserControllerApi
|
|||
@Override
|
||||
@GetMapping("/current")
|
||||
public Result current(){
|
||||
return null;
|
||||
Map<String, Object> userInfo = this.tokenTools.getUserInfo();
|
||||
return new Result(true,StatusCode.OK,"查询成功",userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.zhangmeng.gateway.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.reactive.*;
|
||||
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
//@Configuration
|
||||
//public class CorsConfig {
|
||||
// @Bean
|
||||
// public CorsWebFilter corsFilter() {
|
||||
// CorsConfiguration config = new CorsConfiguration();
|
||||
// config.addAllowedMethod("*");
|
||||
// config.addAllowedOrigin("*");
|
||||
// config.addAllowedHeader("*");
|
||||
//
|
||||
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
|
||||
// source.registerCorsConfiguration("/**", config);
|
||||
//
|
||||
// return new CorsWebFilter(source);
|
||||
// }
|
||||
//}
|
||||
|
|
@ -30,6 +30,7 @@ spring:
|
|||
- POST
|
||||
- PUT
|
||||
- DELETE
|
||||
add-to-simple-url-handler-mapping: true
|
||||
discovery:
|
||||
locator:
|
||||
enabled: false
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.zhangmeng.web_admin.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @version 1.0
|
||||
* @date 2021年6月17日11:04:19
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
/**
|
||||
* 跨域支持
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ server:
|
|||
port: 31007
|
||||
spring:
|
||||
application:
|
||||
name: mystyle-cloud-web-admin1
|
||||
name: mystyle-cloud-web-admin
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
//gate_way
|
||||
var gate_way_url = 'http://localhost:9000';
|
||||
//后台管理微服务 mystyle-cloud-admin-manager
|
||||
var admin_manager_url = 'mystyle-cloud-admin-manager';
|
||||
//验证码地址
|
||||
var code_url = gate_way_url + '/' + admin_manager_url + '/verificationCode/generate';
|
||||
//查询当前用户
|
||||
var current_user_url = gate_way_url + '/' + admin_manager_url + '/user/current';
|
||||
//登录授权地址
|
||||
var oauth_login_url = 'mystyle-cloud-oauth';
|
||||
//授权访问地址
|
||||
var oauth_login_request_url = gate_way_url + '/' + oauth_login_url + '/user/login';
|
||||
|
||||
|
||||
|
|
@ -1,70 +1,123 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Login Page</title>
|
||||
<!-- 样 式 文 件 -->
|
||||
<link rel="stylesheet" href="component/pear/css/pear.css" />
|
||||
<link rel="stylesheet" href="admin/css/other/login.css" />
|
||||
</head>
|
||||
<!-- 代 码 结 构 -->
|
||||
<body background="admin/images/background.svg" style="background-size: cover;">
|
||||
<form class="layui-form" action="javascript:void(0);">
|
||||
<div class="layui-form-item">
|
||||
<img class="logo" src="admin/images/logo.png" />
|
||||
<div class="title">Pear Admin</div>
|
||||
<div class="desc">
|
||||
明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input placeholder="账 户 : admin " lay-verify="required" hover class="layui-input" />
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input placeholder="密 码 : admin " lay-verify="required" hover class="layui-input" />
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input placeholder="验证码 : " hover lay-verify="required" class="code layui-input layui-input-inline" />
|
||||
<img src="admin/images/captcha.gif" class="codeImage" />
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
|
||||
登 入
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<!-- 资 源 引 入 -->
|
||||
<script src="component/layui/layui.js"></script>
|
||||
<script src="component/pear/pear.js"></script>
|
||||
<script>
|
||||
layui.use(['form', 'button', 'popup'], function() {
|
||||
var form = layui.form;
|
||||
var button = layui.button;
|
||||
var popup = layui.popup;
|
||||
|
||||
// 登 录 提 交
|
||||
form.on('submit(login)', function(data) {
|
||||
|
||||
/// 验证
|
||||
|
||||
/// 登录
|
||||
|
||||
/// 动画
|
||||
button.load({
|
||||
elem: '.login',
|
||||
time: 1500,
|
||||
done: function() {
|
||||
popup.success("登录成功", function() {
|
||||
location.href = "index.html"
|
||||
});
|
||||
}
|
||||
})
|
||||
return false;
|
||||
});
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Login Page</title>
|
||||
<!-- 样 式 文 件 -->
|
||||
<link rel="stylesheet" href="component/pear/css/pear.css"/>
|
||||
<link rel="stylesheet" href="admin/css/other/login.css"/>
|
||||
</head>
|
||||
<!-- 代 码 结 构 -->
|
||||
<body background="admin/images/background.svg" style="background-size: cover;">
|
||||
<form class="layui-form" action="javascript:void(0);">
|
||||
<div class="layui-form-item">
|
||||
<img class="logo" src="admin/images/logo.png"/>
|
||||
<div class="title">Pear Admin</div>
|
||||
<div class="desc">
|
||||
明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input placeholder="账 户 " id="username" name="username" lay-verify="required" hover class="layui-input"/>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input placeholder="密 码 " id="password" name="password" lay-verify="required" hover class="layui-input"/>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input placeholder="验证码 : " id="vcode" name="vcode" hover lay-verify="required" class="code layui-input layui-input-inline"/>
|
||||
<img src="" class="codeImage" id="captchaImage" />
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<button type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
|
||||
登 入
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<!-- 资 源 引 入 -->
|
||||
<script src="component/layui/layui.js"></script>
|
||||
<script src="component/pear/pear.js"></script>
|
||||
<script src="admin/js/mystyle-admin.js"></script>
|
||||
<script>
|
||||
layui.use(['form', 'jquery', 'layer', 'button', 'popup'], function () {
|
||||
let form = layui.form;
|
||||
let $ = layui.jquery;
|
||||
let layer = layui.layer;
|
||||
let button = layui.button;
|
||||
let popup = layui.popup;
|
||||
let captchaPath = code_url;
|
||||
layer.ready(function () {
|
||||
|
||||
$("#captchaImage").attr('src',code_url);
|
||||
|
||||
let token = localStorage.getItem("Authorization");
|
||||
if (token != null && token.trim().length != 0) {
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: current_user_url,
|
||||
beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader("Authorization:" + token);
|
||||
},
|
||||
success: function (data) {
|
||||
window.location.href = 'index.html';
|
||||
},
|
||||
error: function (xhr, textStatus, errorThrown) {
|
||||
var msg = xhr.responseText;
|
||||
var response = JSON.parse(msg);
|
||||
var code = response.code;
|
||||
var message = response.message;
|
||||
if (code == 401) {
|
||||
localStorage.removeItem("Authorization");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
form.on('submit(login)', function (data) {
|
||||
let loader = layer.load();
|
||||
let btn = button.load({elem: '.login'});
|
||||
$.ajax({
|
||||
url: oauth_login_request_url,
|
||||
data: data.field,
|
||||
type: "post",
|
||||
//dataType:"jsonp",
|
||||
// username:data.field.username,
|
||||
// password:data.field.password,
|
||||
/*beforeSend: function (xhr) {
|
||||
xhr.setRequestHeader("Access-Control-Allow-Origin:'*'");
|
||||
},*/
|
||||
success: function (result) {
|
||||
console.log(result);
|
||||
layer.close(loader);
|
||||
btn.stop(function () {
|
||||
if (result.flag) {
|
||||
popup.success(result.message, function () {
|
||||
localStorage.setItem("token", result.data.token);
|
||||
window.location.href= 'index.html';
|
||||
})
|
||||
} else {
|
||||
popup.failure(result.message, function () {
|
||||
document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
error: function (xhr, textStatus, errorThrown) {
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#captchaImage").click(function () {
|
||||
document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
|
||||
});
|
||||
setInterval(function () {
|
||||
document.getElementById("captchaImage").src = captchaPath + "?" + Math.random();
|
||||
}, 5 * 60 * 1000);
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue