Skip to content

Commit 033118d

Browse files
committed
添加login功能-1
1 parent 7671dd2 commit 033118d

File tree

24 files changed

+226
-55
lines changed

24 files changed

+226
-55
lines changed

lion-api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</dependency>
6464
</dependencies>
6565
<build>
66-
<finalName>lion-api</finalName>
66+
<finalName>lion-api-${env}</finalName>
6767
<filters>
6868
<filter>src/main/filters/config-${env}.properties</filter>
6969
</filters>

lion-api/src/main/java/com/dianping/lion/api/http/AbstractLionServlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public abstract class AbstractLionServlet extends HttpServlet {
6363
public static final String PARAM_PUSH = "p"; //配置变更是否实时推送到app
6464
public static final String PARAM_CORRECT = "c"; //设置registerpoint是否正确
6565

66-
public static final String SUCCESS_CODE = "0"; //正确返回码
66+
public static final String SUCCESS_CODE = "0|"; //正确返回码
6767
public static final String ERROR_CODE = "1|"; //错误返回码
6868

6969
protected ApplicationContext applicationContext;

lion-api/src/main/java/com/dianping/lion/api/http/GetConfigServlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void doService(HttpServletRequest req, HttpServletResponse resp) throw
6868
} catch (RegisterRelatedException e) {
6969
throw new RuntimeBusinessException("get config value from zk failed.");
7070
}
71-
writer.print(SUCCESS_CODE + "|" + resultJson.toString());
71+
writer.print(SUCCESS_CODE + resultJson.toString());
7272
}
7373

7474
}

lion-api/src/main/java/com/dianping/lion/api/http/RollbackConfigsServlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected void doService(HttpServletRequest req, HttpServletResponse resp) throw
5959
}
6060
hasRollbacked = true;
6161
}
62-
resp.getWriter().print(SUCCESS_CODE + "|" + (hasRollbacked ? "1|" + keysNotRemoved : "0"));
62+
resp.getWriter().print(SUCCESS_CODE + (hasRollbacked ? "1|" + keysNotRemoved : "0"));
6363
}
6464

6565
}

lion-api/src/main/java/com/dianping/lion/api/http/TakeEffectConfigsServlet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected void doService(HttpServletRequest req, HttpServletResponse resp) throw
5454
checkConfigKeys(projectName, keys);
5555
configReleaseService.executeSetTask(project.getId(), environment.getId(), features, keys, PUSH_TO_APP.equals(push2App));
5656

57-
resp.getWriter().write(SUCCESS_CODE + "|" + snapshotId);
57+
resp.getWriter().write(SUCCESS_CODE + snapshotId);
5858
} else {
5959
resp.getWriter().write(SUCCESS_CODE);
6060
}

lion-api/src/main/java/com/dianping/lion/db/DataSourceFetcher.java

-19
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@
1515
*/
1616
package com.dianping.lion.db;
1717

18-
import java.io.BufferedReader;
19-
import java.io.File;
20-
import java.io.FileReader;
21-
import java.net.URL;
22-
2318
import org.apache.commons.httpclient.HttpClient;
2419
import org.apache.commons.httpclient.methods.GetMethod;
2520
import org.apache.log4j.Logger;
2621

27-
import com.dianping.lion.api.db.JsonParserTest;
28-
2922
/**
3023
* DataSourceFetcher
3124
* @author youngphy.yang
@@ -73,16 +66,4 @@ public void setPath(String path) {
7366
this.path = path;
7467
}
7568

76-
public String testDS() throws Exception {
77-
URL url = JsonParserTest.class.getClassLoader().getResource("dbjson.txt");
78-
File f = new File(url.getPath());
79-
FileReader fr = new FileReader(f);
80-
BufferedReader br = new BufferedReader(fr);
81-
StringBuffer sb = new StringBuffer();
82-
String line = null;
83-
while((line = br.readLine()) != null)
84-
sb.append(line);
85-
String content = sb.toString();
86-
return content;
87-
}
8869
}

lion-api/src/test/java/com/dianping/lion/api/db/JsonParserTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class JsonParserTest {
4848
private static String content = null;
4949
@BeforeClass
5050
public static void setup() throws Exception {
51-
URL url = JsonParserTest.class.getClassLoader().getResource("dbjson.txt");
51+
URL url = JsonParserTest.class.getResource("/dbjson.txt");
5252
File f = new File(url.getPath());
5353
FileReader fr = new FileReader(f);
5454
BufferedReader br = new BufferedReader(fr);

lion-api/src/test/java/com/dianping/lion/api/db/StoragerTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
import org.junit.Test;
2525

2626
import com.dianping.lion.db.Storager;
27-
import com.dianping.lion.support.AbstractDaoTestSupport;
2827
import com.dianping.lion.util.JsonParser;
2928

3029
/**
3130
* StoragerTest
3231
* @author youngphy.yang
3332
*
3433
*/
35-
public class StoragerTest extends AbstractDaoTestSupport{
34+
public class StoragerTest {
35+
3636
private static String content = null;
37+
3738
@BeforeClass
3839
public static void setup() throws Exception {
39-
URL url = JsonParserTest.class.getClassLoader().getResource("dbjson.txt");
40+
URL url = JsonParserTest.class.getResource("/dbjson.txt");
4041
File f = new File(url.getPath());
4142
FileReader fr = new FileReader(f);
4243
BufferedReader br = new BufferedReader(fr);
File renamed without changes.

lion-console/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</dependency>
8989
</dependencies>
9090
<build>
91-
<finalName>lion-console</finalName>
91+
<finalName>lion-console-${env}</finalName>
9292
<filters>
9393
<filter>src/main/filters/config-${env}.properties</filter>
9494
</filters>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
*
3+
*/
4+
package com.dianping.lion.web.action.common;
5+
6+
/**
7+
* @author danson.liu
8+
*
9+
*/
10+
public class LoginAction extends AbstractLionAction {
11+
12+
/**
13+
*
14+
*/
15+
private static final long serialVersionUID = 6916064814214305113L;
16+
17+
private String loginName;
18+
19+
private String passwd;
20+
21+
@Override
22+
public String execute() throws Exception {
23+
// TODO Auto-generated method stub
24+
if ("jian.liu".equals(loginName) && "liujian".equals(passwd)) {
25+
createSuccessStreamResponse();
26+
} else {
27+
createErrorStreamResponse("ID/密码错误!");
28+
}
29+
return SUCCESS;
30+
}
31+
32+
/**
33+
* @return the loginName
34+
*/
35+
public String getLoginName() {
36+
return loginName;
37+
}
38+
39+
/**
40+
* @param loginName the loginName to set
41+
*/
42+
public void setLoginName(String loginName) {
43+
this.loginName = loginName;
44+
}
45+
46+
/**
47+
* @return the passwd
48+
*/
49+
public String getPasswd() {
50+
return passwd;
51+
}
52+
53+
/**
54+
* @param passwd the passwd to set
55+
*/
56+
public void setPasswd(String passwd) {
57+
this.passwd = passwd;
58+
}
59+
60+
}

lion-console/src/main/resources/config/struts/struts.xml

+3
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,8 @@
6969
<action name="navigate" class="com.dianping.lion.web.action.common.NavigationAction">
7070
<result name="success" type="redirect">${redirectUrl}</result>
7171
</action>
72+
<action name="loginAjax" class="com.dianping.lion.web.action.common.LoginAction">
73+
<result name="success" type="stream"/>
74+
</action>
7275
</package>
7376
</struts>

lion-console/src/main/webapp/WEB-INF/decorators/main.ftl

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<script type="text/javascript" src="<@s.url value="/js/bootstrap.js"/>"></script>
2020
<script type="text/javascript" src="<@s.url value="/js/json2.js"/>"></script>
2121
<script type="text/javascript" src="<@s.url value="/js/my97/WdatePicker.js"/>"></script>
22+
<script type="text/javascript" src="<@s.url value="/js/biz/system/login.js"/>"></script>
2223
<#include "/WEB-INF/pages/common/common.ftl">
2324
<style type="text/css">
2425
body {
@@ -45,7 +46,7 @@
4546
<@lion.SubNav/>
4647
</ul>
4748
<ul class="nav pull-right">
48-
<li><a href="#">登录</a></li>
49+
<li><a href="#" id="login_link">登录</a></li>
4950
</ul>
5051
<ul class="nav pull-right">
5152
<@lion.MainNav/>
@@ -64,5 +65,6 @@
6465
<div class="container">
6566
<footer class="footer"><center>©2012 Dianping平台架构, Mail: <a href="mailto:[email protected]">[email protected]</a></center></footer>
6667
</div>
68+
<#include "/WEB-INF/pages/common/login-modal.ftl">
6769
</body>
6870
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div id="login-modal" class="modal hide">
2+
<div class="modal-header">
3+
<a class="close" data-dismiss="modal" >&times;</a>
4+
<font class="lion-h3">用户登陆</font>
5+
<span style="margin-left:83px;" id="login-msg"></span>
6+
</div>
7+
<div class="modal-body">
8+
<form class="form-horizontal">
9+
<fieldset>
10+
<div class="control-group">
11+
<label class="control-label" for="loginName">工号/邮箱:</label>
12+
<div class="controls">
13+
<input type="text" class="input-xlarge" id="loginName">
14+
<span class="help-inline hide message">必填!</span>
15+
</div>
16+
</div>
17+
<div class="control-group">
18+
<label class="control-label" for="loginPasswd">密码:</label>
19+
<div class="controls">
20+
<input type="password" class="input-xlarge" id="loginPasswd">
21+
<span class="help-inline hide message">必填!</span>
22+
</div>
23+
</div>
24+
</fieldset>
25+
</form>
26+
</div>
27+
<div class="modal-footer" style="text-align:center;">
28+
<input id="login-btn" type="button" class="btn btn-primary" value=" 登陆 ">&nbsp;&nbsp;&nbsp;&nbsp;
29+
<input id="login-close-btn" type="button" class="btn" data-dismiss="modal" value=" 关闭 ">
30+
</div>
31+
</div>

lion-console/src/main/webapp/css/lion.css

+10
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ table.lion input[type="radio"], input[type="checkbox"] {
202202
margin : 0 0;
203203
}
204204

205+
.lion-h3 {
206+
margin: 0;
207+
font-family: inherit;
208+
font-weight: bold;
209+
color: inherit;
210+
text-rendering: optimizelegibility;
211+
font-size: 18px;
212+
line-height: 27px;
213+
}
214+
205215
.nohover tbody tr:hover td,
206216
.nohover tbody tr:hover th {
207217
background-color: white !important;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
$(function(){
2+
$("#login-modal").on("hidden", function() {
3+
$("input[type='text'],input[type='password']").val("");
4+
$("#login-error-msg").html("");
5+
resetLoginFormValidation();
6+
});
7+
8+
$("#login_link").click(function() {
9+
$("#login-modal").modal({
10+
backdrop : "static",
11+
keyboard : true
12+
});
13+
return false;
14+
});
15+
16+
var formSubmitHandler = function(event) {
17+
$("#login-error-msg").html("");
18+
if (validateLoginForm()) {
19+
$.ajax("/loginAjax.vhtml".prependcontext(), {
20+
data : $.param({
21+
"loginName" : $("#loginName").val().trim(),
22+
"passwd" : $("#loginPasswd").val()
23+
}, true),
24+
dataType : "json",
25+
success : function(result) {
26+
if (result.code == Res_Code_Success) {
27+
$("#login-msg").html("<font color='green'>登陆成功, 载入中...</font>");
28+
window.location.reload();
29+
} else if (result.code == Res_Code_Error) {
30+
$("#login-msg").html("<font color='red'>" + result.msg + "</font>");
31+
}
32+
}
33+
});
34+
}
35+
return false;
36+
};
37+
38+
$("input[type='text'],input[type='password']").keypress(function(e) {
39+
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
40+
if (keyCode == 13) {
41+
formSubmitHandler(e);
42+
}
43+
});
44+
45+
$("#login-btn").click(formSubmitHandler);
46+
47+
function validateLoginForm() {
48+
var checkPass = true;
49+
resetLoginFormValidation();
50+
$("#loginName, #loginPasswd").each(function() {
51+
if ($(this).val().isBlank()) {
52+
setValidateError($(this));
53+
checkPass = false;
54+
}
55+
});
56+
return checkPass;
57+
}
58+
59+
function resetLoginFormValidation() {
60+
$(".control-group").removeClass("error");
61+
$(".message").hide();
62+
}
63+
64+
function setValidateError($element) {
65+
$element.parents(".control-group").addClass("error");
66+
$element.next(".message").show();
67+
}
68+
});

lion-service/pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
<dependency>
5757
<groupId>net.sf.ehcache</groupId>
5858
<artifactId>ehcache-core</artifactId>
59-
<version>2.5.2</version>
6059
</dependency>
6160
<dependency>
6261
<groupId>net.sf.ehcache</groupId>
@@ -111,5 +110,10 @@
111110
<artifactId>commons-httpclient</artifactId>
112111
<version>3.1</version>
113112
</dependency>
113+
<dependency>
114+
<groupId>asm</groupId>
115+
<artifactId>asm</artifactId>
116+
<version>3.1</version>
117+
</dependency>
114118
</dependencies>
115119
</project>

lion-service/src/main/java/com/dianping/lion/util/SecurityUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class SecurityUtils {
2525

2626
private static ThreadLocal<User> currentUser = new InheritableThreadLocal<User>();
2727

28+
// public static boolean hasPrivilege(int userId, String resource) {
29+
//
30+
// }
31+
2832
public static User getCurrentUser() {
2933
User user = currentUser.get();
3034
if (user != null) {

0 commit comments

Comments
 (0)