Skip to content

Commit

Permalink
mz-g-0.3.2015.0924
Browse files Browse the repository at this point in the history
1、重构privilege部分的代码。为shiro做准备,把shiro的基础类准备好
2、调整品类代码,包括数据库
3、调整配置文件位置及内容
  • Loading branch information
wukonggg committed Sep 24, 2015
1 parent afc55ee commit 5ead6ae
Show file tree
Hide file tree
Showing 23 changed files with 260 additions and 70 deletions.
10 changes: 9 additions & 1 deletion VERSION.TXT
Expand Up @@ -14,11 +14,19 @@
- SkuModule //TODO FIXME 没有处理到异常。参考GoodsMoudle的save

+ TODO -NEXT
- 给SKU增加一个备注字段
- 增加根据产品信息查询订单的功能,查询某个产品在哪几个订单销售过
- 增加订单号
- 重构order模块。把jsp和module中return "done"全部改成return "ok"。和其他模块统一起来
- 把deploy脚本中sku_prop_type的数据补全
- 增加quratz定时调度任务。
- 增加根据产品信息查询订单的功能,查询某个产品在哪几个订单销售过


mz-g-0.3.2015.0924
==============================================
1、重构privilege部分的代码。为shiro做准备,把shiro的基础类准备好
2、调整品类代码,包括数据库
3、调整配置文件位置及内容


mz-g-0.3.2015.0913
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz</artifactId>
<version>1.b.53-SNAPSHOT</version>
<version>1.b.53</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
Expand Down Expand Up @@ -99,8 +99,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
106 changes: 90 additions & 16 deletions sql/mz-g-deploy.sql
Expand Up @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS `t_cart` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=1 COMMENT='购物车';

-- 正在导出表 mz-g.t_cart 的数据:~1 rows (大约)
-- 正在导出表 mz-g.t_cart 的数据:~2 rows (大约)
DELETE FROM `t_cart`;
/*!40000 ALTER TABLE `t_cart` DISABLE KEYS */;
INSERT INTO `t_cart` (`id`, `user_id`, `cust_id`, `sku_more_id`, `count`) VALUES
Expand Down Expand Up @@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS `t_goods` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COMMENT='商品表。 TODO -OPT 以后扩展:供应商,厂家,品牌等';

-- 正在导出表 mz-g.t_goods 的数据:~7 rows (大约)
-- 正在导出表 mz-g.t_goods 的数据:~6 rows (大约)
DELETE FROM `t_goods`;
/*!40000 ALTER TABLE `t_goods` DISABLE KEYS */;
INSERT INTO `t_goods` (`id`, `cate_code`, `gname`, `words`, `img`, `ctime`, `utime`, `state`) VALUES
Expand Down Expand Up @@ -173,7 +173,7 @@ CREATE TABLE IF NOT EXISTS `t_order` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_order 的数据:~8 rows (大约)
-- 正在导出表 mz-g.t_order 的数据:~6 rows (大约)
DELETE FROM `t_order`;
/*!40000 ALTER TABLE `t_order` DISABLE KEYS */;
INSERT INTO `t_order` (`id`, `user_id`, `cust_id`, `dtime`) VALUES
Expand All @@ -188,12 +188,60 @@ INSERT INTO `t_order` (`id`, `user_id`, `cust_id`, `dtime`) VALUES
/*!40000 ALTER TABLE `t_order` ENABLE KEYS */;


-- 导出 表 mz-g.t_permission 结构
CREATE TABLE IF NOT EXISTS `t_permission` (
`id` bigint(64) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`al` varchar(50) DEFAULT NULL,
`dt` varchar(500) DEFAULT NULL,
`ct` datetime DEFAULT NULL,
`ut` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_permission 的数据:~0 rows (大约)
DELETE FROM `t_permission`;
/*!40000 ALTER TABLE `t_permission` DISABLE KEYS */;
/*!40000 ALTER TABLE `t_permission` ENABLE KEYS */;


-- 导出 表 mz-g.t_role 结构
CREATE TABLE IF NOT EXISTS `t_role` (
`id` bigint(64) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`al` varchar(50) DEFAULT NULL,
`dt` varchar(500) DEFAULT NULL,
`ct` datetime DEFAULT NULL,
`ut` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_role 的数据:~0 rows (大约)
DELETE FROM `t_role`;
/*!40000 ALTER TABLE `t_role` DISABLE KEYS */;
/*!40000 ALTER TABLE `t_role` ENABLE KEYS */;


-- 导出 表 mz-g.t_role_permission 结构
CREATE TABLE IF NOT EXISTS `t_role_permission` (
`role_id` bigint(64) DEFAULT NULL,
`permission_id` bigint(64) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_role_permission 的数据:~0 rows (大约)
DELETE FROM `t_role_permission`;
/*!40000 ALTER TABLE `t_role_permission` DISABLE KEYS */;
/*!40000 ALTER TABLE `t_role_permission` ENABLE KEYS */;


-- 导出 表 mz-g.t_sku 结构
CREATE TABLE IF NOT EXISTS `t_sku` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sid` varchar(50) NOT NULL COMMENT 'sku_id。sku_xxx的唯一id,因为id可能在不同的sku_xxx表中重复',
`model` varchar(50) NOT NULL COMMENT '(一级分类)款型/颜色',
`type` varchar(50) NOT NULL COMMENT '(二级分类)分类。如尺码标准,对应t_sku_type表',
`type` varchar(50) NOT NULL COMMENT '(二级分类)分类。如尺码标准,对应t_sku_prop_type表',
`ptime` datetime NOT NULL COMMENT '入库日期',
`pprice` int(11) NOT NULL COMMENT '入库价格',
`sprice` int(11) NOT NULL COMMENT '零售价格',
Expand Down Expand Up @@ -402,23 +450,49 @@ INSERT INTO `t_sku_prop_type` (`cate_code`, `item`, `name`, `title`, `evalue`, `

-- 导出 表 mz-g.t_user 结构
CREATE TABLE IF NOT EXISTS `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`login_name` varchar(50) NOT NULL DEFAULT '0',
`pwd` varchar(50) NOT NULL DEFAULT '0' COMMENT '加密',
`state` int(1) unsigned NOT NULL DEFAULT '0' COMMENT '0:初始;1:正常;2:已删除',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='用户表。暂时没用到。';

-- 正在导出表 mz-g.t_user 的数据:~3 rows (大约)
`id` bigint(64) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`passwd` varchar(128) DEFAULT NULL,
`locked` tinyint(1) DEFAULT NULL,
`state` varchar(50) DEFAULT NULL,
`ct` datetime DEFAULT NULL,
`ut` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_user 的数据:~0 rows (大约)
DELETE FROM `t_user`;
/*!40000 ALTER TABLE `t_user` DISABLE KEYS */;
INSERT INTO `t_user` (`id`, `login_name`, `pwd`, `state`) VALUES
(1, 'Yolanda', '0', 1),
(2, 'Wukong', '0', 1),
(3, 'test', '0', 1);
INSERT INTO `t_user` (`id`, `name`, `passwd`, `locked`, `state`, `ct`, `ut`) VALUES
(1, 'admin', '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92', 0, '1', '2015-09-12 17:28:48', '2015-09-12 17:28:48');
/*!40000 ALTER TABLE `t_user` ENABLE KEYS */;


-- 导出 表 mz-g.t_user_permission 结构
CREATE TABLE IF NOT EXISTS `t_user_permission` (
`u_id` bigint(64) DEFAULT NULL,
`permission_id` bigint(64) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_user_permission 的数据:~0 rows (大约)
DELETE FROM `t_user_permission`;
/*!40000 ALTER TABLE `t_user_permission` DISABLE KEYS */;
/*!40000 ALTER TABLE `t_user_permission` ENABLE KEYS */;


-- 导出 表 mz-g.t_user_role 结构
CREATE TABLE IF NOT EXISTS `t_user_role` (
`u_id` bigint(64) DEFAULT NULL,
`role_id` bigint(64) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- 正在导出表 mz-g.t_user_role 的数据:~0 rows (大约)
DELETE FROM `t_user_role`;
/*!40000 ALTER TABLE `t_user_role` DISABLE KEYS */;
/*!40000 ALTER TABLE `t_user_role` ENABLE KEYS */;


-- 导出 视图 mz-g.v_cart 结构
-- 创建临时表以解决视图依赖性错误
CREATE TABLE `v_cart` (
Expand Down
Expand Up @@ -60,17 +60,16 @@ public Object login(@Param("name") String name, @Param("password") String passwo
}

@At(top = true)
@Ok("jsp:view.main")
@Fail("redirect:/entry.io")
public void main() {
}

@At
@Ok(">>:/") // 跟其他方法不同,这个方法完成后就跳转首页了
public void logout(HttpSession session) {
session.invalidate();
}

@At(top = true)
@Ok("jsp:view.main")
public void main() {
}

@At
@Ok("jsp:view.common.privilege.user_list")
public void index() {
Expand Down
31 changes: 8 additions & 23 deletions src/main/java/band/wukong/mz/g/category/SimpleCateConst.java
Expand Up @@ -33,9 +33,9 @@ public class SimpleCateConst {
public static final String CATE_CODE_E_WZ = "S-5";

/**
* 品类代码-F奶粉
* 品类代码-F零食
*/
public static final String CATE_CODE_F_NF = "S-6";
public static final String CATE_CODE_F_LS = "S-6";

/**
* 品类代码-G包包
Expand All @@ -48,33 +48,18 @@ public class SimpleCateConst {
public static final String CATE_CODE_H_MZ = "S-8";

/**
* 品类代码-I玩具
* 品类代码-I尿不湿
*/
public static final String CATE_CODE_I_WJ = "S-9";
public static final String CATE_CODE_I_NBS = "S-9";

/**
* 品类代码-J尿不湿
* 品类代码-J玩具
*/
public static final String CATE_CODE_J_NBS = "S-10";
public static final String CATE_CODE_J_WJ = "S-10";

/**
* 品类代码-K代购
* 品类代码-K文具
*/
public static final String CATE_CODE_K_DG = "S-11";

/**
* 品类代码-L杯子&奶瓶
*/
public static final String CATE_CODE_K_BZ = "S-12";

/**
* 品类代码-M妈妈
*/
public static final String CATE_CODE_M_MM = "S-13";

/**
* 品类代码-N文具
*/
public static final String CATE_CODE_N_WJ = "S-14";
public static final String CATE_CODE_K_WJ = "S-11";

}
@@ -1,4 +1,4 @@
package band.wukong.mz.nutz;
package band.wukong.mz.nutz.integration.druid;

import org.nutz.mvc.NutFilter;

Expand Down
115 changes: 115 additions & 0 deletions src/main/java/band/wukong/mz/nutz/integration/shiro/NutzDaoRealm.java
@@ -0,0 +1,115 @@
package band.wukong.mz.nutz.integration.shiro;

import band.wukong.mz.common.privilege.bean.Permission;
import band.wukong.mz.common.privilege.bean.Role;
import band.wukong.mz.common.privilege.bean.User;
import band.wukong.mz.util.Toolkit;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.integration.shiro.CaptchaUsernamePasswordToken;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.lang.Strings;
import org.nutz.mvc.Mvcs;

/**
* 用NutDao来实现Shiro的Realm
*
* @author wukong(wukonggg@139.com)
*/
public class NutzDaoRealm extends AuthorizingRealm {

@Inject
private Dao dao;

public NutzDaoRealm() {
this(null, null);
}

public NutzDaoRealm(CacheManager cacheManager) {
this(cacheManager, null);
}

public NutzDaoRealm(CredentialsMatcher matcher) {
this(null, matcher);
}

public NutzDaoRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
super(cacheManager, matcher);
setAuthenticationTokenClass(CaptchaUsernamePasswordToken.class);
}

public Dao dao() {
if (dao == null) {
dao = Mvcs.ctx().getDefaultIoc().get(Dao.class, "dao");
return dao;
}
return dao;
}

public void setDao(Dao dao) {
this.dao = dao;
}

public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//null usernames are invalid
if (principals == null) {
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
}
int userId = (Integer) principals.getPrimaryPrincipal();
User user = dao().fetch(User.class, userId);
if (user == null)
return null;
if (user.isLocked())
throw new LockedAccountException("Account [" + user.getName() + "] is locked.");

SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
user = dao().fetchLinks(user, null);
if (user.getRoles() != null) {
dao().fetchLinks(user.getRoles(), null);
for (Role role : user.getRoles()) {
auth.addRole(role.getName());
if (role.getPermissions() != null) {
for (Permission p : role.getPermissions()) {
auth.addStringPermission(p.getName());
}
}
}
}
if (user.getPermissions() != null) {
for (Permission p : user.getPermissions()) {
auth.addStringPermission(p.getName());
}
}
return auth;
}

public AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
CaptchaUsernamePasswordToken upToken = (CaptchaUsernamePasswordToken) token;

if (Strings.isBlank(upToken.getCaptcha()))
throw new AuthenticationException("验证码不能为空");
String _captcha = Strings.sBlank(SecurityUtils.getSubject().getSession(true).getAttribute(Toolkit.captcha_attr));
if (!upToken.getCaptcha().equalsIgnoreCase(_captcha))
throw new AuthenticationException("验证码错误");

User user = dao().fetch(User.class, Cnd.where("name", "=", upToken.getUsername()));
if (user == null)
return null;
if (user.isLocked())
throw new LockedAccountException("Account [" + upToken.getUsername() + "] is locked.");
SimpleAccount account = new SimpleAccount(user.getId(), user.getPassword(), getName());
account.setCredentialsSalt(ByteSource.Util.bytes(user.getSalt()));
return account;
}

}
@@ -1,4 +1,4 @@
package band.wukong.mz.nutz;
package band.wukong.mz.nutz.test;

import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.NutIoc;
Expand Down

0 comments on commit 5ead6ae

Please sign in to comment.