Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
RedKale committed Mar 18, 2016
1 parent b82ed6a commit e40c1a8
Show file tree
Hide file tree
Showing 12 changed files with 555 additions and 463 deletions.
22 changes: 4 additions & 18 deletions conf/application.xml
@@ -1,25 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<application port="5001" lib="${APP_HOME}/dist/*" address="127.0.0.1">
<application port="5001">

<resources>
<group name="GROUP-A">
<node addr="127.0.0.1" port="7001"/>
<node addr="127.0.0.1" port="7002"/>
</group>
<group name="GROUP-B">
<node addr="127.0.0.1" port="7011"/>
<node addr="127.0.0.1" port="7012"/>
</group>
<group name="USERSESSION">
<node addr="127.0.0.1" port="4001"/>
</group>
<properties>
<property name="system.property.convert.json.tiny" value="true"/>
</properties>
</resources>

<server protocol="HTTP" host="0.0.0.0" port="6001">
<server protocol="HTTP" port="6001">
<request>
<remoteaddr value="request.headers.X-RemoteAddress"/>
</request>
Expand All @@ -34,8 +20,8 @@
</servlets>
</server>
<!-- SNCP 监听 Server -->
<server protocol="SNCP" host="0.0.0.0" port="7001">
<services autoload="true" groups="GROUP-A;GROUP-B">
<server protocol="SNCP" port="7001">
<services autoload="true">
<!--
<service name="usersessions" value="org.redkale.service.CacheSourceService" groups="USERSESSION">
<property name="key-type" value="java.lang.String"/>
Expand Down
4 changes: 2 additions & 2 deletions conf/persistence.xml
Expand Up @@ -2,10 +2,10 @@
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

<persistence-unit name="reduser" transaction-type="RESOURCE_LOCAL">
<persistence-unit name="red_demo" transaction-type="RESOURCE_LOCAL">
<shared-cache-mode>ALL</shared-cache-mode>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/center?autoReconnect=true&amp;characterEncoding=utf8"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/red_demo?autoReconnect=true&amp;characterEncoding=utf8"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="1234"/>
Expand Down
48 changes: 48 additions & 0 deletions root/test/ajax.html
@@ -0,0 +1,48 @@

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Redkale接口测试页面</title>
<style>
ul {list-style: none;}
li {margin: 10px 0 10px 0;vertical-align: middle;}
</style>
</head>

<body>
<br/>
<br/>
<ul>
<li>当前用户: <input id="myname" value="" style="width: 200px;" readonly=""></li>
<li>请求 URL: <input id="url" value="/pipes/" style="width: 600px;"> <button id="btn" style="margin-left: 50px;padding:5px 20px 5px 20px;">发送</button></li>
<li>请求参数: <textarea id="data" style="width: 600px;height: 300px;"></textarea></li>
<li>返回结果: <textarea id="result" style="width: 600px;height: 300px;"></textarea></li>
</ul>
<br/>
<script src="/pipes/user/js/myinfo"></script>
<script src="zepto.min.js"></script>
<script>
if (userself) $('#myname').val(userself.username);
$('#btn').click(function () {
var data = JSON.parse(($('#data').val() || "{}").replace(/\n/g, " "));
var params = {};
for (var key in data) {
params[key] = JSON.stringify(data[key]);
}
$.ajax({
cache: false,
url: $('#url').val(),
data: params,
error: function () {//请求失败处理函数
alert("请求失败");
},
success: function (data) {
$('#result').val(data);
}
});
});
</script>
</body>

</html>
4 changes: 4 additions & 0 deletions root/test/zepto.min.js

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions src/org/redkale/demo/base/RetCodes.java
@@ -0,0 +1,138 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.redkale.demo.base;

import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;
import org.redkale.service.RetResult;

/**
*
* @author zhangjx
*/
public abstract class RetCodes {

private RetCodes() {
}

//------------------------------------- 用户模块 -----------------------------------------
@RetInfo("未登陆")
public static final int RET_USER_UNLOGIN = 1010001;

@RetInfo("用户登录失败")
public static final int RET_USER_LOGIN_FAIL = 1010002;

@RetInfo("用户或密码错误")
public static final int RET_USER_ACCOUNT_PWD_ILLEGAL = 1010003;

@RetInfo("密码设置无效")
public static final int RET_USER_PASSWORD_ILLEGAL = 1010004;

@RetInfo("用户不存在")
public static final int RET_USER_NOTEXISTS = 1010008;

@RetInfo("用户状态异常")
public static final int RET_USER_STATUS_ILLEGAL = 1010009;

@RetInfo("用户注册参数无效")
public static final int RET_USER_SIGNUP_ILLEGAL = 1010011;

@RetInfo("用户性别参数无效")
public static final int RET_USER_GENDER_ILLEGAL = 1010021;

@RetInfo("验证码无效")
public static final int RET_USER_RANDCODE_ILLEGAL = 1010101; //邮件或者短信验证码

@RetInfo("验证码已过期")
public static final int RET_USER_RANDCODE_EXPIRED = 1010102; //邮件或者短信验证码

@RetInfo("验证码错误或失效")
public static final int RET_USER_CAPTCHA_ILLEGAL = 1010171; //图片验证码

@RetInfo("用户名无效")
public static final int RET_USER_USERNAME_ILLEGAL = 1010201;

@RetInfo("用户账号无效")
public static final int RET_USER_ACCOUNT_ILLEGAL = 1010301;

@RetInfo("用户账号已存在")
public static final int RET_USER_ACCOUNT_EXISTS = 1010302;

@RetInfo("手机号码无效")
public static final int RET_USER_MOBILE_ILLEGAL = 1010401;

@RetInfo("手机号码已存在")
public static final int RET_USER_MOBILE_EXISTS = 1010402;

@RetInfo("手机验证码发送过于频繁")
public static final int RET_USER_MOBILE_SMSFREQUENT = 1010406;

@RetInfo("邮箱地址无效")
public static final int RET_USER_EMAIL_ILLEGAL = 1010501;

@RetInfo("邮箱地址已存在")
public static final int RET_USER_EMAIL_EXISTS = 1010502;

@RetInfo("微信绑定号无效")
public static final int RET_USER_WXID_ILLEGAL = 1010601;

@RetInfo("微信绑定号已存在")
public static final int RET_USER_WXID_EXISTS = 1010602;

@RetInfo("绑定微信号失败")
public static final int RET_USER_WXID_BIND_FAIL = 1010603;

@RetInfo("QQ绑定号无效")
public static final int RET_USER_QQID_ILLEGAL = 1010701;

@RetInfo("QQ绑定号已存在")
public static final int RET_USER_QQID_EXISTS = 1010702;

@RetInfo("绑定QQ号失败")
public static final int RET_USER_QQID_BIND_FAIL = 1010703;

@RetInfo("获取绑定QQ信息失败")
public static final int RET_USER_QQID_INFO_FAIL = 1010704;

//----------------------------------------------------------------------------------------------------
private static final Map<Integer, String> rets = new HashMap<>();

static {
for (Field field : RetCodes.class.getFields()) {
if (!Modifier.isStatic(field.getModifiers())) continue;
if (field.getType() != int.class) continue;
RetInfo info = field.getAnnotation(RetInfo.class);
if (info == null) continue;
int value;
try {
value = field.getInt(null);
} catch (Exception ex) {
ex.printStackTrace();
continue;
}
rets.put(value, info.value());
}

}

public static RetResult create(int retcode) {
if (retcode == 0) return RetResult.SUCCESS;
return new RetResult(retcode, getRetInfo(retcode));
}

public static String getRetInfo(int retcode) {
if (retcode == 0) return "成功";
return rets.getOrDefault(retcode, "未知错误");
}

@Target(value = {ElementType.FIELD})
@Retention(value = RetentionPolicy.RUNTIME)
protected @interface RetInfo {

String value();
}
}
76 changes: 33 additions & 43 deletions src/org/redkale/demo/base/UserInfo.java
Expand Up @@ -5,11 +5,10 @@
*/
package org.redkale.demo.base;

import java.security.*;
import javax.persistence.*;
import javax.persistence.Id;
import org.redkale.convert.*;
import org.redkale.source.*;
import org.redkale.util.*;
import org.redkale.source.VirtualEntity;
import org.redkale.util.Reproduce;

/**
*
Expand All @@ -31,18 +30,6 @@ public class UserInfo extends BaseEntity {
//女
public static final short GENDER_FEMALE = 4;

protected static final MessageDigest sha1;

static {
MessageDigest d = null;
try {
d = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
sha1 = d;
}

//平台的虚拟用户ID
public static final int USERID_SYSTEM = 100000000;

Expand All @@ -62,6 +49,8 @@ public class UserInfo extends BaseEntity {

protected String password = ""; //密码(前端不可见) 数据库存放的密码规则为: HEX-SHA1( HEX-MD5( HEX-MD5(明文)+"-REDKALE" ) +"-REDKALE" )

protected String account = ""; //用户账号(前端不可见)

protected String mobile = ""; //手机号码(前端不可见)

protected String email = ""; //邮箱 (前端不可见)
Expand All @@ -73,11 +62,11 @@ public class UserInfo extends BaseEntity {
protected String apptoken = ""; //APP的设备ID (前端不可见) 通常用于IOS的APNS推送

protected short status; //状态 (前端不可见) 值见BaseEntity的STATUS常量

protected long infotime; //用户可见资料的更新时间 通常用于客户端判断用户资料是否已修改便于主动拉取新资料

protected short gender; //性别; 2:男; 4:女; 值见BaseEntity的GENDER常量

protected long infotime; //用户可见资料的更新时间 通常用于客户端判断用户资料是否已修改便于主动拉取新资料

@Override
public int hashCode() {
return this.userid;
Expand All @@ -97,21 +86,6 @@ public UserInfo copyTo(UserInfo dest) {
return reproduce.copy(dest, this);
}

/**
* 校验密码是否正确
*
* @param passwordtwicemd5
* @return
*/
public boolean checkPassword(String passwordtwicemd5) {
if (this.password.isEmpty() && passwordtwicemd5.isEmpty()) return true;
byte[] bytes = (passwordtwicemd5.trim() + "-REDKALE").getBytes();
synchronized (sha1) {
bytes = sha1.digest(bytes);
}
return this.password.equals(new String(Utility.binToHex(bytes)));
}

//用户是否处于正常状态
@ConvertColumn(ignore = true, type = ConvertType.BSON)
public boolean isNormal() {
Expand All @@ -130,10 +104,10 @@ public boolean isFrobid() {
return this.status == STATUS_FREEZE;
}

//是否绑定了APP设备
@ConvertColumn(ignore = true, type = ConvertType.ALL)
public boolean isHasapptoken() {
return this.apptoken != null && !this.apptoken.isEmpty();
//是否绑定了手机号码
@ConvertColumn(ignore = true, type = ConvertType.BSON)
public boolean isMb() {
return this.mobile != null && !this.mobile.isEmpty();
}

//是否绑定了邮箱
Expand All @@ -142,12 +116,6 @@ public boolean isEm() {
return this.email != null && !this.email.isEmpty();
}

//是否绑定了手机号码
@ConvertColumn(ignore = true, type = ConvertType.BSON)
public boolean isMb() {
return this.mobile != null && !this.mobile.isEmpty();
}

//是否绑定了微信
@ConvertColumn(ignore = true, type = ConvertType.BSON)
public boolean isWx() {
Expand All @@ -160,6 +128,18 @@ public boolean isQq() {
return this.qqopenid != null && !this.qqopenid.isEmpty();
}

//是否有用户账号
@ConvertColumn(ignore = true, type = ConvertType.ALL)
public boolean isAc() {
return this.account != null && !this.account.isEmpty();
}

//是否绑定了APP设备
@ConvertColumn(ignore = true, type = ConvertType.ALL)
public boolean isAp() {
return this.apptoken != null && !this.apptoken.isEmpty();
}

public long getInfotime() {
return infotime;
}
Expand All @@ -180,6 +160,16 @@ public void setUserid(int userid) {
this.userid = userid;
}

//用户帐号不允许输出给外部接口
@ConvertColumn(ignore = true, type = ConvertType.JSON)
public String getAccount() {
return account;
}

public void setAccount(String account) {
if (account != null) this.account = account.trim();
}

public String getUsername() {
return username;
}
Expand Down

0 comments on commit e40c1a8

Please sign in to comment.