Skip to content

Commit edca57b

Browse files
committed
重构:移除字符集常量
重构:新增认证接口及公共抽象类
1 parent 38acab3 commit edca57b

30 files changed

+472
-582
lines changed

Diff for: sparrow-mvc-thymeleaf/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</parent>
2828
<modelVersion>4.0.0</modelVersion>
2929
<artifactId>sparrow-mvc-thymeleaf</artifactId>
30-
<version>1.0.0-RELEASE</version>
30+
<version>1.0.1-RELEASE</version>
3131
<properties>
3232
<maven.compiler.source>8</maven.compiler.source>
3333
<maven.compiler.target>8</maven.compiler.target>
@@ -60,4 +60,4 @@
6060
</dependency>
6161
</dependencies>
6262

63-
</project>
63+
</project>

Diff for: sparrow-mvc/src/main/java/com/sparrow/web/support/ValidateCode.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public ValidateCode() {
4040
}
4141

4242
private static final long serialVersionUID = -5813134629255375160L;
43-
private int imagewidth = 100;
44-
private int imageheight = 35;
43+
private int imageWidth = 100;
44+
private int imageHeight = 35;
4545
private int codeCount = 4;
4646
private int fontHeight;
4747
private int codeY;
@@ -58,35 +58,35 @@ public void init() throws ServletException {
5858
String strCodeCount = this.getInitParameter("codeCount");
5959
try {
6060
if (strWidth != null && strWidth.length() != 0) {
61-
this.imagewidth = Integer.parseInt(strWidth);
61+
this.imageWidth = Integer.parseInt(strWidth);
6262
}
6363
if (strHeight != null && strHeight.length() != 0) {
64-
this.imageheight = Integer.parseInt(strHeight);
64+
this.imageHeight = Integer.parseInt(strHeight);
6565
}
6666
if (strCodeCount != null && strCodeCount.length() != 0) {
6767
codeCount = Integer.parseInt(strCodeCount);
6868
}
6969
} catch (NumberFormatException e) {
7070
e.printStackTrace();
7171
}
72-
this.codeWidth = this.imagewidth / (codeCount + 1);
73-
this.fontHeight = this.imageheight - 2;
74-
this.codeY = this.imageheight - 4;
72+
this.codeWidth = this.imageWidth / (codeCount + 1);
73+
this.fontHeight = this.imageHeight - 2;
74+
this.codeY = this.imageHeight - 4;
7575

7676
}
7777

7878
@Override
7979
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
8080
throws ServletException, IOException {
81-
BufferedImage buffImg = new BufferedImage(this.imagewidth,
82-
this.imageheight, BufferedImage.TYPE_INT_RGB);
81+
BufferedImage buffImg = new BufferedImage(this.imageWidth,
82+
this.imageHeight, BufferedImage.TYPE_INT_RGB);
8383
Graphics2D gd = buffImg.createGraphics();
8484
Random random = new Random();
8585
gd.setColor(Color.white);
86-
gd.fillRect(0, 0, this.imagewidth, this.imageheight);
86+
gd.fillRect(0, 0, this.imageWidth, this.imageHeight);
8787
Font font = new Font("Fixedsys", Font.PLAIN, fontHeight);
8888
gd.setFont(font);
89-
gd.drawRect(0, 0, this.imagewidth - 1, this.imageheight - 1);
89+
gd.drawRect(0, 0, this.imageWidth - 1, this.imageHeight - 1);
9090

9191
StringBuilder randomCode = new StringBuilder();
9292
int red = 0, green = 0, blue = 0;
@@ -118,7 +118,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
118118
throws IOException {
119119
if (req.getParameter(Constant.VALIDATE_CODE) != null
120120
&& req.getParameter(Constant.VALIDATE_CODE).equalsIgnoreCase(req.getSession().getAttribute(
121-
Constant.VALIDATE_CODE)
121+
Constant.VALIDATE_CODE)
122122
.toString().toLowerCase())) {
123123
resp.getWriter().write("OK");
124124
return;

Diff for: sparrow-protocol/src/main/java/com/sparrow/protocol/LoginUser.java

+44-45
Original file line numberDiff line numberDiff line change
@@ -17,99 +17,98 @@
1717
package com.sparrow.protocol;
1818

1919
public class LoginUser implements VO {
20+
/**
21+
* 用户ID
22+
*/
2023
private Long userId;
24+
/**
25+
* 用户昵称
26+
*/
2127
private String nickName;
28+
/**
29+
* 用户名
30+
*/
2231
private String userName;
32+
/**
33+
* 头象
34+
*/
2335
private String avatar;
36+
/**
37+
* 设备id
38+
*/
2439
private String deviceId;
25-
private Boolean activate;
40+
2641
private Integer days;
42+
2743
private Long expireAt;
2844

2945
public static LoginUser create(Long userId,
30-
String userName,
31-
String nickName,
32-
String avatar,
33-
String deviceId,
34-
Boolean activate,
35-
Integer expireDays) {
46+
String userName,
47+
String nickName,
48+
String avatar,
49+
String deviceId,
50+
Integer days) {
3651
LoginUser login = new LoginUser();
3752
login.userId = userId;
3853
login.userName = userName;
3954
login.nickName = nickName;
4055
login.avatar = avatar;
56+
login.days = days;
57+
login.expireAt = System.currentTimeMillis() + days * 24 * 60 * 60 * 1000;
4158
login.deviceId = deviceId;
42-
login.activate = activate;
43-
login.days = expireDays;
44-
if (login.days == null) {
45-
login.days = 1;
46-
}
47-
if (expireDays > 0) {
48-
login.expireAt = System.currentTimeMillis() + 1000 * 60 * 60 * 24L * expireDays;
49-
} else {
50-
login.expireAt = 0L;
51-
}
5259
return login;
5360
}
5461

5562
public Long getUserId() {
5663
return userId;
5764
}
5865

59-
public void setUserId(Long userId) {
60-
this.userId = userId;
61-
}
62-
6366
public String getNickName() {
6467
return nickName;
6568
}
6669

67-
public void setNickName(String nickName) {
68-
this.nickName = nickName;
69-
}
70-
7170
public String getUserName() {
7271
return userName;
7372
}
7473

75-
public void setUserName(String userName) {
76-
this.userName = userName;
77-
}
78-
7974
public String getAvatar() {
8075
return avatar;
8176
}
8277

83-
public void setAvatar(String avatar) {
84-
this.avatar = avatar;
85-
}
86-
8778
public String getDeviceId() {
8879
return deviceId;
8980
}
9081

91-
public void setDeviceId(String deviceId) {
92-
this.deviceId = deviceId;
82+
public Integer getDays() {
83+
return days;
84+
}
85+
86+
public Long getExpireAt() {
87+
return expireAt;
9388
}
9489

95-
public Boolean getActivate() {
96-
return activate;
90+
public void setUserId(Long userId) {
91+
this.userId = userId;
9792
}
9893

99-
public void setActivate(Boolean activate) {
100-
this.activate = activate;
94+
public void setNickName(String nickName) {
95+
this.nickName = nickName;
10196
}
10297

103-
public Integer getDays() {
104-
return days;
98+
public void setUserName(String userName) {
99+
this.userName = userName;
105100
}
106101

107-
public void setDays(Integer days) {
108-
this.days = days;
102+
public void setAvatar(String avatar) {
103+
this.avatar = avatar;
109104
}
110105

111-
public Long getExpireAt() {
112-
return expireAt;
106+
public void setDeviceId(String deviceId) {
107+
this.deviceId = deviceId;
108+
}
109+
110+
public void setDays(Integer days) {
111+
this.days = days;
113112
}
114113

115114
public void setExpireAt(Long expireAt) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.sparrow.protocol;
19+
20+
public class LoginUserStatus {
21+
public static final Integer STATUS_NORMAL = 1;
22+
public static final Integer STATUS_FREEZE = 2;
23+
public static final Integer STATUS_DISABLE = 0;
24+
25+
26+
public LoginUserStatus(Integer status, Long expireAt) {
27+
this.status = status;
28+
this.expireAt = expireAt;
29+
}
30+
31+
/**
32+
* 用户状态 1:正常 2:冻结 0:禁用
33+
*/
34+
private Integer status;
35+
36+
/**
37+
* 过期时间
38+
*/
39+
private Long expireAt;
40+
41+
42+
public Integer getStatus() {
43+
return status;
44+
}
45+
46+
public void setStatus(Integer status) {
47+
this.status = status;
48+
}
49+
50+
public Long getExpireAt() {
51+
return expireAt;
52+
}
53+
54+
public void setExpireAt(Long expireAt) {
55+
this.expireAt = expireAt;
56+
}
57+
58+
}

Diff for: sparrow-protocol/src/main/java/com/sparrow/protocol/constant/Constant.java

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public class Constant {
4141
public static final String VALIDATE_CODE = "validate_code";
4242
public static final String IMAGE_EXTENSION = ".jpg|.jpeg|.gif|.png";
4343

44-
public static final String CHARSET_UTF_8 = "UTF-8";
45-
public static final String CHARSET_GBK = "GBK";
46-
public static final String CHARSET_ISO_8859_1 = "ISO-8859-1";
47-
4844
public static final String CONTENT_TYPE_FORM = "application/x-www-form-urlencoded";
4945
public static final String CONTENT_TYPE_MS_DOWNLOAD = "application/x-msdownload";
5046

Diff for: sparrow-protocol/src/main/java/com/sparrow/protocol/constant/SparrowError.java

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public enum SparrowError implements ErrorSupport {
8282
GLOBAL_PARAMETER_IS_ILLEGAL(true, GlobalModule.GLOBAL, "28", "parameter is illegal"),
8383
GLOBAL_SMS_SEND_ERROR(true, GlobalModule.GLOBAL, "29", "short message service error"),
8484
USER_NOT_LOGIN(true, GlobalModule.GLOBAL, "34", "user not login"),
85+
86+
USER_DISABLE(true, GlobalModule.GLOBAL, "34", "user disable"),
87+
8588
IMAGE_EXTENSION_NOT_FOUND(true, GlobalModule.GLOBAL, "35", "image extension not found");
8689

8790
private boolean system;

Diff for: sparrow/src/main/java/com/sparrow/constant/ConfigKeyLanguage.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ public class ConfigKeyLanguage {
5151
public static final String EFFECTIVE = "effective";
5252
public static final String INEFFECTIVE = "ineffective";
5353
public static final String MODIFY_PASSWORD_SUCCESS = "user_password_modify_success";
54-
public static final String USER_DEFAULT_NICKNAME = "default_user_name";
5554
public static final String USER_MODIFY_SUCCESS = "user_modify_success";
5655
public static final String USER_EMAIL_SUBJECT = "user_email_subject";
5756
public static final String USER_EMAIL_CONTENT = "user_email_content";
5857
public static final String USER_DISABLE = "user_disable";
5958
public static final String USER_NOT_ACTIVE = "user_not_active";
60-
public static final String USER_VISITOR = "user_visitor";
59+
public static final String USER_VISITOR_NAME = "visitor_user_name";
60+
61+
public static final String USER_VISITOR_NICKNAME = "visitor_nick_name";
62+
6163
public static final String SYSTEM_SERVER_ERROR = "system_server_error";
6264
public static final String SUCCESS = "success";
6365
public static final String USER_STATUS_PREFIX = "user_status_";

0 commit comments

Comments
 (0)