wangyj18 9 anos atrás
pai
commit
f6307adf54

+ 5 - 0
multiple-server/etc/server-data.xml

3
	<!-- 获取首页数据 -->
3
	<!-- 获取首页数据 -->
4
	<action name="IndexBean.getAppDatas" class="com.ai.server.multiple.bean.IndexBean" method="getAppDatas" verify="false"></action>
4
	<action name="IndexBean.getAppDatas" class="com.ai.server.multiple.bean.IndexBean" method="getAppDatas" verify="false"></action>
5

5

6
	<!-- 登陆初始化 -->
7
	<action name="LoginBean.init" class="com.ai.server.multiple.bean.LoginBean" method="init" verify="false"></action>
8
	<action name="LoginBean.refreshVerifyCode" class="com.ai.server.multiple.bean.LoginBean" method="refreshVerifyCode" verify="false"></action>
6
	<!-- 登陆 -->
9
	<!-- 登陆 -->
7
	<action name="LoginBean.login" class="com.ai.server.multiple.bean.LoginBean" method="login" verify="false"></action>
10
	<action name="LoginBean.login" class="com.ai.server.multiple.bean.LoginBean" method="login" verify="false"></action>
8

11

9
	<!-- 登陆应用 -->
12
	<!-- 登陆应用 -->
10
	<action name="LoginBean.loginApp" class="com.ai.server.multiple.bean.LoginBean" method="loginApp" verify="false"></action>
13
	<action name="LoginBean.loginApp" class="com.ai.server.multiple.bean.LoginBean" method="loginApp" verify="false"></action>
14
	
15
	<action name="LoginBean.initAppConfig" class="com.ai.server.multiple.bean.LoginBean" method="initAppConfig" verify="false"></action>
11
</datas>
16
</datas>

+ 1 - 1
multiple-server/etc/server-page.xml

1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<pages>
2
<pages>
3
    <!-- 工作台 -->
3
    <!-- 工作台 -->
4
    <action name="Login" template="template/webapp/Login.html"></action>
4
    <action name="Login" template="template/webapp/Login.html" data="LoginBean.init"></action>
5
 	<action name="Index" template="template/webapp/Index.html" data="IndexBean.getAppDatas"></action>
5
 	<action name="Index" template="template/webapp/Index.html" data="IndexBean.getAppDatas"></action>
6
 	
6
 	
7
 	<action name="WelcomeDisplay" template="template/webapp/welcome/welcome-display.html"></action>
7
 	<action name="WelcomeDisplay" template="template/webapp/welcome/welcome-display.html"></action>

+ 80 - 12
multiple-server/src/com/ai/server/multiple/bean/LoginBean.java

1
package com.ai.server.multiple.bean;
1
package com.ai.server.multiple.bean;
2

2

3
import java.awt.image.BufferedImage;
4

3
import com.ai.server.multiple.core.bean.MultipleBean;
5
import com.ai.server.multiple.core.bean.MultipleBean;
4
import com.ai.server.multiple.core.config.AppConfig;
6
import com.ai.server.multiple.core.config.AppConfig;
5
import com.ai.server.multiple.core.context.MultipleContextData;
7
import com.ai.server.multiple.core.context.MultipleContextData;
6
import com.ai.server.multiple.core.session.MultipleSessionManager;
8
import com.ai.server.multiple.core.session.MultipleSessionManager;
7
import com.ai.server.multiple.util.Constant;
9
import com.ai.server.multiple.util.Constant;
10
import com.ai.server.multiple.util.ImageVerify;
8
import com.ailk.common.data.IData;
11
import com.ailk.common.data.IData;
9
import com.ailk.common.data.impl.DataMap;
12
import com.ailk.common.data.impl.DataMap;
10
import com.ailk.mobile.util.MobileUtility;
13
import com.ailk.mobile.util.MobileUtility;
11

14

12
/**
15
/**
13
 * @author huangbo
14
 * 登录相关逻辑
16
 * @author huangbo 登录相关逻辑
15
 */
17
 */
16
public class LoginBean extends MultipleBean {
18
public class LoginBean extends MultipleBean {
19

20
	private static final String VERIFY_CODE_ERROR = "VERIFY_CODE_ERROR";
21

22
	/**
23
	 * 登录页面初始化
24
	 * 
25
	 * @param param
26
	 * @return
27
	 * @throws Exception
28
	 */
29
	public IData init(IData param) throws Exception {
30
		IData result = new DataMap();
31

32
		// 获取验证码
33
		String verifyCode = ImageVerify.getVerifyCode(4, 2);
34
		BufferedImage image = ImageVerify.getImageVerify(verifyCode);
35
		String imageVerifyCode = ImageVerify.getImageBase64(image);
36

37
		// 创建session
38
		MultipleContextData contextData = new MultipleContextData();
39
		String sessionId = MultipleSessionManager.getInstance().createSession(
40
				contextData);
41
		contextData.setVerifyCode(verifyCode);
42

43
		result.put("VERIFY_IMG", imageVerifyCode);
44
		result.put(Constant.Session.SESSION_ID, sessionId);
45
		return result;
46
	}
47

48
	/**
49
	 * 刷新验证码
50
	 * 
51
	 * @param prama
52
	 * @return
53
	 * @throws Exception
54
	 */
55
	public IData refreshVerifyCode(IData prama) throws Exception {
56
		IData result = new DataMap();
57

58
		// 获取验证码
59
		String verifyCode = ImageVerify.getVerifyCode(4, 2);
60
		BufferedImage image = ImageVerify.getImageVerify(verifyCode);
61
		String imageVerifyCode = ImageVerify.getImageBase64(image);
62
		getContextData().setVerifyCode(verifyCode);
63

64
		result.put("VERIFY_IMG", imageVerifyCode);
65
		return result;
66
	}
67

17
	/**
68
	/**
18
	 * 登陆逻辑
69
	 * 登陆逻辑
19
	 */
70
	 */
20
	@SuppressWarnings("unchecked")
21
	public IData login(IData param) throws Exception{
71
	public IData login(IData param) throws Exception {
72
		IData result = new DataMap();
73

74
//		// 校验验证码
75
//		String verifyCode = getContextData().getVerifyCode();
76
//		String clientVerifyCode = param.getString("VARIFY_CODE");
77
//		if (clientVerifyCode == null) {
78
//			result.put("LOGIN_STATUS", VERIFY_CODE_ERROR);
79
//			return result;
80
//		} else if (!clientVerifyCode.equalsIgnoreCase(verifyCode)) {
81
//			result.put("LOGIN_STATUS", VERIFY_CODE_ERROR);
82
//			return result;
83
//		}
84

22
		String account = param.getString("ACCOUNT");
85
		String account = param.getString("ACCOUNT");
23
		//判断账号密码校验
24
		if(!checkLogin(param)){
86
		// 判断账号密码校验
87
		if (!checkLogin(param)) {
25
			MobileUtility.error("登陆校验失败!请重新登陆");
88
			MobileUtility.error("登陆校验失败!请重新登陆");
26
		}
89
		}
27
		
28
		MultipleContextData multipleContextData = new MultipleContextData(account);
29
		String sessionId = MultipleSessionManager.getInstance().createSession(multipleContextData);
90

91
		getContextData().setAccount(account);
92

93
		result.putAll(AppConfig.getConfig());// 加载应用配置信息
94
		return result;
95
	}
96
	
97
	public IData initAppConfig(IData param) throws Exception {
30
		IData result = new DataMap();
98
		IData result = new DataMap();
31
		result.put(Constant.Session.SESSION_ID, sessionId);
32
		result.putAll(AppConfig.getConfig());//加载应用配置信息
99
		result.putAll(AppConfig.getConfig());// 加载应用配置信息
33
		return result;
100
		return result;
34
	}
101
	}
35

102

103

36
	/**
104
	/**
37
	 * 校验账号密码
105
	 * 校验账号密码
38
	 */
106
	 */
39
	private boolean checkLogin(IData param) {
107
	private boolean checkLogin(IData param) {
40
		// TODO Auto-generated method stub
108
		// TODO Auto-generated method stub
41
		/*需要补充实现逻辑:调用接口或者数据库校验*/
109
		/* 需要补充实现逻辑:调用接口或者数据库校验 */
42
		return true;
110
		return true;
43
	}
111
	}
44
}
112
}

+ 12 - 0
multiple-server/src/com/ai/server/multiple/core/context/MultipleContextData.java

11
	private Map<String,String> tokenIds;
11
	private Map<String,String> tokenIds;
12
	private Map<String,Map<String,String>> accountMapping;
12
	private Map<String,Map<String,String>> accountMapping;
13
	
13
	
14
	public MultipleContextData() {
15
		
16
	}
17
	
14
	public MultipleContextData(String account) {
18
	public MultipleContextData(String account) {
15
		// TODO Auto-generated constructor stub
19
		// TODO Auto-generated constructor stub
16
		getData().put(Constant.Context.ACCOUNT, account);
20
		getData().put(Constant.Context.ACCOUNT, account);
61
		// TODO Auto-generated method stub
65
		// TODO Auto-generated method stub
62
		return accountMapping.get(appId);
66
		return accountMapping.get(appId);
63
	}
67
	}
68

69
	public String getVerifyCode() {
70
		return getData().getString("VERIFY_CODE");
71
	}
72
	
73
	public void setVerifyCode(String verifyCode) {
74
		put("VERIFY_CODE", verifyCode);
75
	}
64
}
76
}

+ 88 - 0
multiple-server/src/com/ai/server/multiple/util/ImageVerify.java

1
package com.ai.server.multiple.util;
2

3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.Graphics2D;
6
import java.awt.image.BufferedImage;
7
import java.io.ByteArrayOutputStream;
8
import java.io.IOException;
9
import java.util.Random;
10

11
import javax.imageio.ImageIO;
12

13
import org.apache.commons.codec.binary.Base64;
14

15
/**
16
 * @author huangbo
17
 * 图片验证码类库
18
 */
19
public class ImageVerify {
20
	private static Random random = new Random();
21

22
	/**得到图片背景色*/
23
	private static Color getBack() {
24
		return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255));
25
	}
26

27
	/**生成颜色的反色*/
28
	private static Color getFront(Color c) {
29
		return new Color(255 - c.getRed(), 255 - c.getGreen(),
30
				255 - c.getBlue());
31
	}
32
	
33
	/**
34
	 * 图片转化成Base64编码
35
	 * @param filePath 文件过大可能内存溢出
36
	 */
37
	public static String getImageBase64(BufferedImage image) throws IOException {
38
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
39
		ImageIO.write(image, "jpg", baos);
40
		byte[] jpegData = baos.toByteArray();
41
		return new String(Base64.encodeBase64(jpegData), "utf-8");
42
	}
43
	
44
	/**
45
	 * 生成校验图片
46
	 */
47
	public static BufferedImage getImageVerify(String code) {
48
		int width = 100;
49
		int height = 45; // 验证图片的宽度,高度
50
		Color back = getBack();
51
		Color front = getFront(back);
52
		BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
53
		Graphics2D g = bi.createGraphics(); // 得到画布
54
		g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 20)); // 设置字体
55
		g.setColor(back);
56
		g.fillRect(0, 0, width, height); // 画背景
57
		g.setColor(front);
58
		g.drawString(code, 18, 20); // 画字符
59
		for (int i = 0, n = random.nextInt(20); i < n; i++) {
60
			g.fillRect(random.nextInt(width), random.nextInt(height), 1, 1);
61
		} // 产生至多20个噪点
62
		return bi;
63
	}
64

65
	/**
66
	 * 作用:获取六位随机码
67
	 */
68
	public static String getVerifyCode(int length, int verifyCodeType) throws Exception {
69
		String num = "0123456789";
70
		String ch = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";
71
		String vc = "";
72

73
		if (verifyCodeType == 0)
74
			vc = num;
75
		else if (verifyCodeType == 1)
76
			vc = ch;
77
		else
78
			vc = num + ch;
79

80
		char[] chs = vc.toCharArray();
81
		String code = "";
82
		for (int i = 0; i < length; i++) {
83
			code += chs[(int) (Math.random() * vc.length())];
84
		}
85
		
86
		return code;
87
	}
88
}

+ 2 - 0
multiple-server/web/biz/js/common/biz-mobile.js

8
				execute("openIpuApp", [appName,param],err);
8
				execute("openIpuApp", [appName,param],err);
9
			},openNativeApp:function(packageName,className,param,err){ //打开ipu应用
9
			},openNativeApp:function(packageName,className,param,err){ //打开ipu应用
10
				execute("openNativeApp", [packageName,className,param],err);
10
				execute("openNativeApp", [packageName,className,param],err);
11
			},initAppConfig:function(err){ //初始化应用
12
				execute("initAppConfig", [],err);
11
			}
13
			}
12
		};
14
		};
13
	})();
15
	})();

+ 9 - 11
multiple-server/web/biz/js/index.js

4
	
4
	
5
	$("#app-menu li").each(function(index, item) {
5
	$("#app-menu li").each(function(index, item) {
6
		$(item).tap(function(item) {
6
		$(item).tap(function(item) {
7
			var appId = item.getAttribute("appId")
7
			var appId = item.getAttribute("appId");
8
			var appType = item.getAttribute("appType");
8
			var appType = item.getAttribute("appType");
9
			var loginData = new Wade.DataMap();
9
			var loginData = new Wade.DataMap();
10
			loginData.put("APP_TYPE",appType);
10
			loginData.put("APP_TYPE",appType);
11
			loginData.put("APP_ID",appId);
11
			loginData.put("APP_ID",appId);
12
			Common.callSvc("LoginBean.loginApp",loginData,function(result){
13
				if(appType=="I"){
14
					//alert("打开IPU应用"+appId);
15
					WadeMobile.openIpuApp(appId);
16
				}else if(appType=="N"){
17
					var param = new Wade.DataMap();
18
					param.put("TOKEN_ID",result.get("TOKEN_ID"));
19
					Mobile.openNativeApp(result.get("PACKAGE_NAME"),result.get("CLASS_NAME"),param);
20
				}
21
			});
12

13
			if(appType=="I"){
14
				//alert("打开IPU应用"+appId);
15
				WadeMobile.openIpuApp(appId);
16
			}else if(appType=="N"){
17
				var param = new Wade.DataMap();
18
				Mobile.openNativeApp(item.getAttribute("appId"), item.getAttribute("appId"), param);
19
			}
22
		},item);
20
		},item);
23
	});
21
	});
24
});
22
});

+ 36 - 4
multiple-server/web/biz/js/login.js

1
require(["common","mobile","util"], function(Common,Mobile) {
1
require(["common","mobile","wadeMobile","util"], function(Common,Mobile,WadeMobile) {
2
	//刷新页面以后存放图片验证码的sessionId
3
	var sessionId = $("#sessionId").val();
4
	if(sessionId){
5
		Common.put("SESSION_ID", sessionId);
6
	}else{
7
		Mobile.tip("验证码丢失,重新获取图片验证码。");
8
	}
9
	
2
	/*登陆*/
10
	/*登陆*/
3
	$("#doLogin").tap(function() {
11
	$("#loginBtn").tap(function() {
4
		var loginData = new Wade.DataMap();
12
		var loginData = new Wade.DataMap();
5
		loginData.put("ACCOUNT", "IpuAccount");
13
		loginData.put("ACCOUNT", $("#J_username").val());
14
		loginData.put("PASSWORD", $("#J_pwd").val());
15
		loginData.put("VARIFY_CODE", $("#J_ver").val());
6
		Common.callSvc("LoginBean.login", loginData, function(result) {
16
		Common.callSvc("LoginBean.login", loginData, function(result) {
17
			if(typeof(resultData) == "string" ){
18
				result = new Wade.DataMap(result);
19
			}
20
			
21
			if(result.get("LOGIN_STATUS") == "VERIFY_CODE_ERROR") {
22
				$("#J_ver").val("");
23
				$("#J_ver").focus();
24
				Mobile.tip("验证码错误,请重新输入!");
25
				return;
26
			}
7
			console.log("登陆成功:" + result);
27
			console.log("登陆成功:" + result);
8
			Common.put("SESSION_ID", result.get("SESSION_ID"));
28
			Common.put("ACCOUNT", sessionId);
29
			WadeMobile.initAppConfig();
9
			Mobile.openTemplate("Index", result);
30
			Mobile.openTemplate("Index", result);
10
		});
31
		});
11
	});
32
	});
33
	
34
	// 刷新验证码
35
	$("#J_ver_img").tap(function(){
36
		Common.callSvc("LoginBean.refreshVerifyCode", null, function(resultData){
37
			if(typeof(resultData) == "string" ){
38
				resultData = new Wade.DataMap(resultData);
39
			}
40
			$("#J_ver_img").attr("src", "data:image/png;base64, " + resultData.get("VERIFY_IMG"));
41
			$("#J_ver").val("");
42
		});
43
	})
12
});
44
});

+ 77 - 1
multiple-server/web/template/webapp/Login.html

7
{%>template/common/Head.html%}
7
{%>template/common/Head.html%}
8
<script type="text/javascript" src="biz/js/login.js"></script>
8
<script type="text/javascript" src="biz/js/login.js"></script>
9
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
9
<link href="biz/css/project.css" rel="stylesheet" type="text/css" />
10
<style>
11
.ui-input {
12
	padding: 6px 9px;
13
	line-height: 0.22rem;
14
    height: 0.4rem;
15
	width: 3rem;
16
	border: 1px solid #BBBBBB;
17
	font-size: 0.22rem;
18
    color: #777;
19
    background: transparent;
20
    font-size: 0.22rem;
21
}
22
.reg_form {
23
	background-color: #fff;
24
	font-size: 0.22rem;
25
	padding-top: 0.12rem;
26
    line-height: 1;
27
    overflow: hidden;
28
    background: #fff;
29
    margin-top: 1rem;
30
}
31
.reg_form .reg_table {
32
}
33
.reg_form .reg_table td {
34
	padding: 0 0 8px 0;
35
	height: 32px;
36
}
37
.reg_form .reg_table td label.des {
38
	text-align: right;
39
	display: table-cell;
40
    width: 1.5rem;
41
    padding: 0.16rem;
42
    line-height: 0.28rem;
43
}
44
.reg_form .reg_table .J_ver-wrap .ui-input {
45
	width: 2rem;
46
}
47
.J_ver_img {
48
	width: 1rem;
49
	height: 0.4rem;
50
}
51
#loginResult span {
52
	line-height: 0.4rem;
53
    height: 0.4rem;
54
}
55
</style>
10
</head>
56
</head>
11
<body>
57
<body>
12
<buttion id="doLogin">------------登陆-----------</buttion>
58
	<div id="content">
59
		<form class="reg_form">
60
			<table class="reg_table" cellpadding="0" cellspacing="0" border="0" width="100%" id="loginForm">
61
				<tbody>
62
					<tr>
63
						<td width="30%"><label class="des">用户名:</label></td>
64
						<td><input value="" type="text" id="J_username" name="J_username" class="ui-input ui-nt" maxlength="20" title="用户名"></td>
65
					</tr>
66
					<tr>
67
						<td><label class="des">密码:</label></td>
68
						<td><input value="" type="password" id="J_pwd" name="J_pwd" class="ui-input" maxlength="50" title="密码"></td>
69
					</tr>
70
					<tr>
71
						<td><label class="des">验证码:</label></td>
72
						<td class="J_ver-wrap">
73
							<input value="" type="text" id="J_ver" name="J_ver" class="ui-input" maxlength="4" require="true" title="验证码">
74
							<img src="data:image/png;base64, {%VERIFY_IMG%}" id="J_ver_img" class="J_ver_img">
75
						</td>
76
					</tr>
77
					<tr>
78
						<td>&nbsp;</td>
79
						<td>
80
							<button class="e_button-ok" id="loginBtn" onclick="javascript:return false;">登录</button>
81
						</td>
82
					</tr>
83
				</tbody>
84
			</table>
85
		</form>
86
	</div>
87
	
88
	<input type="hidden" id="sessionId" value="{%SESSION_ID%}">
13
</body>
89
</body>
14
</html>
90
</html>