diff --git a/README.md b/README.md index 04125f3c3d3f6bcf5a5adc24c0a7226cd96972b9..7be1424eebf7a2809dc5e4128b7514d2cad55ce8 100644 --- a/README.md +++ b/README.md @@ -118,5 +118,4 @@ IntelliJ IDEA或Eclipse请先安装lombok插件。 ![管理端主页](tutorial/screenshots/index.png) ## 分享交流 -在使用过程中有任何疑问或者问题,可以微信扫码询问。 -![author](tutorial/screenshots/author.jpg) \ No newline at end of file +在使用过程中有任何疑问或者问题,请提交issue,我会在收到的第一时间予以回复。 \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml index 351bac1244d89add33aed6b74aa4f3a894e1ca30..0f8cdeaed980364a3062bce787bae042486c8842 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -1,22 +1,22 @@ + + com.simon + oauthserver + 2.0.20190506-alpha + ../pom.xml + + 4.0.0 api - 2.0.20190506-alpha + ${parent.version} jar api Api Module - - com.simon - oauthserver - 2.0.20190506-alpha - ../pom.xml - - org.springframework.cloud @@ -112,6 +112,7 @@ org.springframework.boot spring-boot-devtools + runtime true @@ -276,7 +277,7 @@ com.simon common - 2.0.20190506-alpha + ${parent.version} diff --git a/api/src/main/java/com/simon/common/config/DataSourceConfig.java b/api/src/main/java/com/simon/common/config/DataSourceConfig.java index e09d2e605f2d81e915dd4b42a06733469ed73d42..68fd9938ef0ecfb58b8ec290fa52dc6e24641bab 100644 --- a/api/src/main/java/com/simon/common/config/DataSourceConfig.java +++ b/api/src/main/java/com/simon/common/config/DataSourceConfig.java @@ -7,6 +7,7 @@ import org.mybatis.spring.SqlSessionFactoryBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.core.JdbcTemplate; @@ -20,6 +21,7 @@ import java.util.Properties; * @author simon * @date 2019-02-18 */ +@Configuration public class DataSourceConfig { @Value("${mybatis.mapper-locations}") private String mapperLocations; diff --git a/api/src/main/java/com/simon/controller/OauthUserController.java b/api/src/main/java/com/simon/controller/OauthUserController.java index 58ecdda98b0110297d581e2371ec6ae73d74088a..5bbdd12d84b42f643643cab1f23eb1fc09abe5fa 100644 --- a/api/src/main/java/com/simon/controller/OauthUserController.java +++ b/api/src/main/java/com/simon/controller/OauthUserController.java @@ -8,6 +8,7 @@ import com.simon.common.domain.UserEntity; import com.simon.common.exception.RegisterException; import com.simon.common.factory.SmsServiceFactory; import com.simon.common.utils.BeanUtils; +import com.simon.dto.OauthUserDto; import com.simon.model.OauthUser; import com.simon.service.BaseSmsService; import com.simon.service.OauthUserService; @@ -110,14 +111,16 @@ public class OauthUserController extends BaseController { @ApiOperation(value = "更新个人信息") @PatchMapping @ResponseBody - public ResultMsg update(@RequestBody OauthUser oauthUser, @ApiIgnore @ApiParam(hidden = true) Authentication authentication) { - oauthUserService.updateByPrimaryKeySelective(oauthUser); + public ResultMsg update(@RequestBody OauthUserDto oauthUserDto, @ApiIgnore @ApiParam(hidden = true) Authentication authentication) { UserEntity userEntity = getCurrentUser(authentication); if (null != userEntity) { //更新session中的principal - BeanUtils.copyPropertiesIgnoreNull(oauthUser, userEntity); + BeanUtils.copyPropertiesIgnoreNull(oauthUserDto, userEntity); } - + OauthUser oauthUser = new OauthUser(); + oauthUser.setId(userEntity.getId()); + BeanUtils.copyPropertiesIgnoreNull(oauthUserDto, oauthUser); + oauthUserService.updateByPrimaryKeySelective(oauthUser); return ResultMsg.success(); } diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties index db67a423c213e040638f8238561a431dedcacc02..e269efe5d5c42d4f0b300f6585e7fa00695b1b70 100644 --- a/api/src/main/resources/application.properties +++ b/api/src/main/resources/application.properties @@ -1,4 +1,4 @@ -# 벻Ҫserver.portƶyamlļУ޷ȷļ· +# \u8BF7\u4E0D\u8981\u628Aserver.port\u914D\u7F6E\u79FB\u52A8\u5230yaml\u6587\u4EF6\u4E2D\uFF0C\u5426\u5219\u5C06\u65E0\u6CD5\u6B63\u786E\u8BBE\u7F6E\u6587\u4EF6\u8BBF\u95EE\u8DEF\u5F84 server.port=8181 spring.profiles.include=common \ No newline at end of file diff --git a/api/src/main/resources/code-gen.properties b/api/src/main/resources/code-gen.properties index 128eb8673dd534a7bcb0b10799f28fc145019a78..0a4826360d90ed70c3dca780c0777424772c3734 100644 --- a/api/src/main/resources/code-gen.properties +++ b/api/src/main/resources/code-gen.properties @@ -1,4 +1,4 @@ -# +# \u4EE3\u7801\u751F\u6210\u5668\u914D\u7F6E # MySQL jdbc_url=jdbc:mysql://127.0.0.1:3306/thymelte?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false jdbc_username=root @@ -17,6 +17,6 @@ jdbc_driver_class_name=com.mysql.cj.jdbc.Driver #jdbc_password=thymelte123456 #jdbc_driver_class_name=oracle.jdbc.driver.OracleDriver -# Spring BootģĿ¼ -# Mapperӿڵȫ޶(ڶᵽĺļ̳нӿMapper) +# Spring Boot\u6A21\u5757\u76EE\u5F55 +# Mapper\u63D2\u4EF6\u57FA\u7840\u63A5\u53E3\u7684\u5B8C\u5168\u9650\u5B9A\u540D(\u7B2C\u4E8C\u6B65\u63D0\u5230\u7684\u6838\u5FC3\u7EE7\u627F\u63A5\u53E3Mapper) mapper_interface_reference=@base.package@.common.mapper.MyMapper \ No newline at end of file diff --git a/common/src/main/java/com/simon/dto/OauthUserDto.java b/common/src/main/java/com/simon/dto/OauthUserDto.java new file mode 100644 index 0000000000000000000000000000000000000000..d74f64f3bacc05a63223a1c82881506b159f9032 --- /dev/null +++ b/common/src/main/java/com/simon/dto/OauthUserDto.java @@ -0,0 +1,55 @@ +package com.simon.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.simon.common.config.AppConfig; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDate; + +/** + * @author simon + * @version 1.0 + * @date 2019-07-09 9:28 + */ +@ApiModel(description = "用户dto") +@Data +@EqualsAndHashCode(callSuper = false) +public class OauthUserDto implements Serializable { + private static final long serialVersionUID = -4619525018151286048L; + + @ApiModelProperty(value = "用户名") + private String username; + + @ApiModelProperty(value = "手机号") + private String phone; + + @ApiModelProperty(value = "邮箱") + private String email; + + @ApiModelProperty(value = "地址") + private String address; + + @ApiModelProperty(value = "年龄") + private Integer age; + + @ApiModelProperty(value = "生日") + @JSONField(format = AppConfig.DATE_PATTERN_DAY) + @DateTimeFormat(pattern = AppConfig.DATE_PATTERN_DAY) + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = AppConfig.DATE_PATTERN_DAY, timezone = AppConfig.DATE_TIMEZONE) + private LocalDate birth; + + @ApiModelProperty(value = "头像") + private String headPhoto; + + @ApiModelProperty(value = "个人简介") + private String personBrief; + + @ApiModelProperty(value = "性别") + private Boolean sex; +} diff --git a/pom.xml b/pom.xml index 3a7900c06ce79bb26ea0ca3373fa3f5618184d69..12ebd1bfd53ccfdecbf856645ea519d51ed3ca40 100644 --- a/pom.xml +++ b/pom.xml @@ -184,6 +184,7 @@ org.springframework.boot spring-boot-devtools ${spring-boot.version} + runtime true diff --git a/tutorial/api.md b/tutorial/api.md index 470e36b535083c1f066db177766913f9c5ea4228..8f937eb138dfb20cc443ab71dda132aa7c4fd0bc 100644 --- a/tutorial/api.md +++ b/tutorial/api.md @@ -156,4 +156,9 @@ status=200,返回的json数据: ## app实践指南 app获取到token信息后,需要保存token信息和请求时间。在传access_token之前,需要检查access_token是否过期。为了减少后台压力,检查access_token是否过期应该是在app本地完成。通过token的key`expires_in`(剩余有效期)的值,以及本地记录的请求时间,和当前时间做对比,可以很方便地判断出access_token是否过期。如果过期了,需要通过refresh_token获取新的access_token。因为access_token的有效期只有2个小时,这个验证是必须的。 -refresh_token同理。 +refresh_token同理。 +但是,Spring Security Oauth2授权框架没有解决一个账号多端登录的问题。账号和token是一对一的关系,如果系统允许一个账号多端登录,那么必然出现以下这种情况。用户在客户端A和客户端B同时登录,客户端A的access_token过期了,客户端A选择刷新access_token;在客户端A刷新了access_token之后,客户端B发现自己手上的access_token不可用了,也选择刷新access_token,造成客户端A手上的access_token不可用了,循环反复,客户端A和客户端B一直在疯狂刷新access_token。 +如何解决上面的问题呢?此处提供三种解决方案以供参考。 +1. 设置access_token永不失效,不去刷新access_token; +2. 自定义刷新access_token的请求接口,在接口里判断access_token是否过期,过期了就刷新并返回access_token,没过期就直接返回access_token。 +3. 记录每次刷新token的设备,如果这一次刷新的设备和上一次一致就返回新token,如果设备不一致就返回上一次的token,如果上一次的token已过期就返回新token,这样让两台设备的token保持一样就不会出现问题。 \ No newline at end of file diff --git a/web/pom.xml b/web/pom.xml index 776d51608ca47c423eb977d296b69d679ca760d0..2b5ca72e6a9133c2cfb6dedb208c0155c513ea1d 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -1,22 +1,22 @@ + + com.simon + oauthserver + 2.0.20190506-alpha + ../pom.xml + + 4.0.0 web - 2.0.20190506-alpha + ${parent.version} jar web Web Module - - com.simon - oauthserver - 2.0.20190506-alpha - ../pom.xml - - org.springframework.cloud @@ -97,6 +97,7 @@ org.springframework.boot spring-boot-devtools + runtime true @@ -327,7 +328,7 @@ com.simon common - 2.0.20190506-alpha + ${parent.version} diff --git a/web/src/main/java/com/simon/controller/TableController.java b/web/src/main/java/com/simon/controller/TableController.java index 3c16e88f7ee88d9856507723c7462081a92ef735..bc7e4def5e442b19362cf445e9f923d28fc1b0f8 100644 --- a/web/src/main/java/com/simon/controller/TableController.java +++ b/web/src/main/java/com/simon/controller/TableController.java @@ -88,23 +88,6 @@ public class TableController extends BaseController { } } - /*@RequestMapping(value = "generate", method = RequestMethod.GET) - @ResponseBody - public ResultMsg generate( - @RequestParam String tableName, - @RequestParam String entityName, - @ApiParam(value = "表id列类型", required = false, example = "Long") @RequestParam(required = false, defaultValue = "Long") String idType, - @RequestParam(required = false) String genModules, - Authentication authentication) { - if (null != authentication) { - UserEntity userEntity = getCurrentUser(authentication); - CodeGenerator.genCodeByCustomModelName(tableName, entityName, idType, genModules, userEntity.getUsername()); - } else { - CodeGenerator.genCodeByCustomModelName(tableName, entityName, idType, genModules); - } - return ResultMsg.success(); - }*/ - @GetMapping(value = "codeGenerate") public String codeGenerate( Model model, diff --git a/web/src/main/resources/application.properties b/web/src/main/resources/application.properties index 953198baef87b92029a8e1272d840dcda502c16c..baef00f182be95f77b4ff343cb8082589969ef00 100644 --- a/web/src/main/resources/application.properties +++ b/web/src/main/resources/application.properties @@ -1,4 +1,4 @@ -# 벻Ҫserver.portƶyamlļУ޷ȷļ· +# \u8BF7\u4E0D\u8981\u628Aserver.port\u914D\u7F6E\u79FB\u52A8\u5230yaml\u6587\u4EF6\u4E2D\uFF0C\u5426\u5219\u5C06\u65E0\u6CD5\u6B63\u786E\u8BBE\u7F6E\u6587\u4EF6\u8BBF\u95EE\u8DEF\u5F84 server.port=8182 spring.profiles.include=common \ No newline at end of file diff --git a/web/src/main/resources/code-gen.properties b/web/src/main/resources/code-gen.properties index bd717633fde7249ffc2d7dbcaa6214f8edca7331..3ccb414bb14ce203619dfd1c8b4624254dfe17c9 100644 --- a/web/src/main/resources/code-gen.properties +++ b/web/src/main/resources/code-gen.properties @@ -1,4 +1,4 @@ -# +# \u4EE3\u7801\u751F\u6210\u5668\u914D\u7F6E # MySQL jdbc_url=jdbc:mysql://127.0.0.1:3306/thymelte?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false jdbc_username=root @@ -17,6 +17,6 @@ jdbc_driver_class_name=com.mysql.cj.jdbc.Driver #jdbc_password=yuhang #jdbc_driver_class_name=oracle.jdbc.OracleDriver -# Spring BootģĿ¼ -# Mapperӿڵȫ޶(ڶᵽĺļ̳нӿMapper) +# Spring Boot\u6A21\u5757\u76EE\u5F55 +# Mapper\u63D2\u4EF6\u57FA\u7840\u63A5\u53E3\u7684\u5B8C\u5168\u9650\u5B9A\u540D(\u7B2C\u4E8C\u6B65\u63D0\u5230\u7684\u6838\u5FC3\u7EE7\u627F\u63A5\u53E3Mapper) mapper_interface_reference=@base.package@.common.mapper.MyMapper \ No newline at end of file