Commit 9407336e by 丁伟

1、取消qq邮箱无法注册的问题。

2、增加“是否购买CDCS/CSDG考前培训”
parent a37736f7
......@@ -44,10 +44,10 @@ public class BaseDao<T> implements IDao<T> {
boolean success;
try {
hibernateTemplate.saveOrUpdate(t);
success=true;
}catch (Exception e){
success=false;
throw new RuntimeException("save failed",e);
success = true;
} catch (Exception e) {
success = false;
throw new RuntimeException("save failed", e);
}
return success;
}
......@@ -103,10 +103,10 @@ public class BaseDao<T> implements IDao<T> {
boolean success;
try {
hibernateTemplate.delete(t);
success=true;
}catch (Exception e){
success=false;
throw new RuntimeException("save failed",e);
success = true;
} catch (Exception e) {
success = false;
throw new RuntimeException("save failed", e);
}
return success;
}
......@@ -121,13 +121,13 @@ public class BaseDao<T> implements IDao<T> {
boolean success = false;
try {
T t = queryById(id);
if (t!=null){
if (t != null) {
hibernateTemplate.delete(t);
success=true;
success = true;
}
}catch (Exception e){
success=false;
throw new RuntimeException("save failed",e);
} catch (Exception e) {
success = false;
throw new RuntimeException("save failed", e);
}
return success;
}
......@@ -146,10 +146,10 @@ public class BaseDao<T> implements IDao<T> {
for (int i = 0; i < ts.size(); i++) {
hibernateTemplate.saveOrUpdate(ts.get(i));
}
success=true;
}catch (Exception e){
success=false;
throw new RuntimeException("save failed",e);
success = true;
} catch (Exception e) {
success = false;
throw new RuntimeException("save failed", e);
}
return success;
}
......@@ -168,10 +168,10 @@ public class BaseDao<T> implements IDao<T> {
for (int i = 0; i < ts.size(); i++) {
hibernateTemplate.delete(ts.get(i));
}
success=true;
}catch (Exception e){
success=false;
throw new RuntimeException("save failed",e);
success = true;
} catch (Exception e) {
success = false;
throw new RuntimeException("save failed", e);
}
return success;
......
......@@ -11,51 +11,66 @@ import java.util.List;
public interface IDao<T> {
/**
* 实例化一个实体
*
* @param t
*/
public boolean save(T t);
/**
* 实例化所有实体
*
* @param t
*/
public boolean saveAll(List<T> list);
/**
* 删除一个实体
*
* @param t
*/
public boolean delete(T t);
/**
* 删除一个实体
*
* @param id
*/
public boolean deleteById(long id);
/**
* 删除所有实体
*
* @param t
*/
public boolean deleteAll(List<T> list);
/**
* 查询实体
*
* @param t
*/
public List<T> query(final String hql, final Object... params);
/**
* 查询所有
*
* @param t
*/
public List<T> queryAll();
/**
* 分页查询
*
* @param pageRequest
* @param hql
* @param values
* @return
*/
public Page findPage(PageRequest pageRequest, String hql, Object[] values);
/**
* 获取实体的Class
*
* @param t
*/
public Class getEntityClass();
......
package org.ccpit.base.modol;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.lang.annotation.Inherited;
/**
* Created by Administrator on 2015/8/13.
*/
public class BaseEntity implements IEntity,Serializable {
public class BaseEntity implements IEntity, Serializable {
/**
* Serializable ID
*/
......
......@@ -7,7 +7,9 @@ import java.util.List;
*/
public interface IRole {
public String getRoleName();
public List<RoleUrl> getUrlPerfixs();
public long getId();
}
package org.ccpit.base.role;
import org.ccpit.base.modol.BaseEntity;
import org.hibernate.annotations.*;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import java.util.ArrayList;
import java.util.List;
......@@ -25,18 +23,18 @@ public class Role extends BaseEntity implements IRole {
public long getId() {
return super.getId();
}
@Override
public String getRoleName() {
return roleName;
}
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
@Override
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@Override
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
public List<RoleUrl> getUrlPerfixs() {
return urlPerfixs;
}
......@@ -55,19 +53,19 @@ public class Role extends BaseEntity implements IRole {
@Override
public int hashCode() {
return ("role"+getId()).hashCode();
return ("role" + getId()).hashCode();
}
@Override
public boolean equals(Object o) {
if(o == null){
if (o == null) {
return false;
}
if(o == this){
if (o == this) {
return true;
}
if(o.getClass() == Role.class){
return o.hashCode()==this.hashCode();
if (o.getClass() == Role.class) {
return o.hashCode() == this.hashCode();
}
return false;
}
......
......@@ -9,8 +9,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public class RoleDao extends BaseDao<Role> {
public Role getRoleByUrl(String url){
Role role = findUnique("select r from "+Role.class.getName()+" as r left join r.urlPerfixs as p where p.url = ?",new String[]{url});
public Role getRoleByUrl(String url) {
Role role = findUnique("select r from " + Role.class.getName() + " as r left join r.urlPerfixs as p where p.url = ?", new String[]{url});
return role;
}
}
......@@ -5,14 +5,15 @@ import org.ccpit.base.controller.Convert;
import org.ccpit.base.controller.Page;
import org.ccpit.base.controller.PageBo;
import org.ccpit.base.controller.PageRequest;
import org.ccpit.base.user.UserDao;
import org.ccpit.base.utils.UrlRolesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2015/9/6.
......@@ -25,7 +26,7 @@ public class RoleService {
@Autowired
private UrlRolesMapper mapper;
public boolean addRole(String roleName, String url,String description) {
public boolean addRole(String roleName, String url, String description) {
Role role = new Role();
role.setRoleName(roleName);
role.setDescription(description);
......@@ -46,16 +47,16 @@ public class RoleService {
return result;
}
public boolean editRole(long id,String roleName,String urlPrefixs,String description) {
public boolean editRole(long id, String roleName, String urlPrefixs, String description) {
Role role = roleDao.queryById(id);
urlPrefixs = getPriId(urlPrefixs);
if (role!=null){
if(null != roleName && !"".equals(roleName)){
role.setRoleName(roleName);
}
if(null != roleName && !"".equals(description)){
role.setDescription(description);
}
if (role != null) {
if (null != roleName && !"".equals(roleName)) {
role.setRoleName(roleName);
}
if (null != roleName && !"".equals(description)) {
role.setDescription(description);
}
List<RoleUrl> urlList = new ArrayList<RoleUrl>();
for (String u : urlPrefixs.split(",")) {
RoleUrl ru = new RoleUrl();
......@@ -85,8 +86,8 @@ public class RoleService {
public Page<Role> getAll(PageRequest pr) {
return roleDao.findPage(pr, "from " + Role.class.getName(), null);
}
public Page<Role> getAll(PageRequest pr,String hql) {
public Page<Role> getAll(PageRequest pr, String hql) {
return roleDao.findPage(pr, hql, null);
}
......@@ -95,27 +96,27 @@ public class RoleService {
}
public List<Role> getAllRoles(){
return roleDao.queryAll();
public List<Role> getAllRoles() {
return roleDao.queryAll();
}
public Map<String,Object> convertToMap(Role role){
Map<String,Object> map = new HashMap<String, Object>();
if (role==null)
public Map<String, Object> convertToMap(Role role) {
Map<String, Object> map = new HashMap<String, Object>();
if (role == null)
return map;
List<String> urls = new ArrayList<String>();
for (RoleUrl roleUrl:role.getUrlPerfixs()){
for (RoleUrl roleUrl : role.getUrlPerfixs()) {
urls.add(roleUrl.getUrl());
}
map.put("urlPrefixs", StringUtils.join(urls,","));
map.put("roleName",role.getRoleName());
map.put("id",role.getId());
map.put("urlPerfixs",urls);
map.put("description",role.getDescription());
map.put("urlPrefixs", StringUtils.join(urls, ","));
map.put("roleName", role.getRoleName());
map.put("id", role.getId());
map.put("urlPerfixs", urls);
map.put("description", role.getDescription());
return map;
}
public PageBo<Role> convert(Page<Role> page){
public PageBo<Role> convert(Page<Role> page) {
return new PageBo<Role>(page, new Convert<Role>() {
@Override
public Map<String, Object> convert(Role obj) {
......@@ -126,31 +127,32 @@ public class RoleService {
/**
* 根据url查找role
*
* @param url
* @return
*/
public Role findRoleByUrl(String url){
public Role findRoleByUrl(String url) {
return roleDao.getRoleByUrl(url);
}
//去掉重复priId
private String getPriId(String priIds){
List list = new ArrayList();
String[] str = priIds.split(",");
if(null != str && !"".equals(str)){
for(int i=0; i<str.length;i++){
if(!list.contains(str[i])){
list.add(str[i]);
}
}
}
String priId = "";
if(null != list && list.size()>0){
for(int j=0;j<list.size();j++){
String id = (String) list.get(j);
priId += id + ",";
}
}
return priId.substring(0, priId.length()-1);
}
private String getPriId(String priIds) {
List list = new ArrayList();
String[] str = priIds.split(",");
if (null != str && !"".equals(str)) {
for (int i = 0; i < str.length; i++) {
if (!list.contains(str[i])) {
list.add(str[i]);
}
}
}
String priId = "";
if (null != list && list.size() > 0) {
for (int j = 0; j < list.size(); j++) {
String id = (String) list.get(j);
priId += id + ",";
}
}
return priId.substring(0, priId.length() - 1);
}
}
package org.ccpit.base.role;
import org.ccpit.base.modol.BaseEntity;
import org.hibernate.annotations.*;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import javax.persistence.Entity;
/**
* 角色 地址 映射表
......
......@@ -2,12 +2,9 @@ package org.ccpit.base.security;
import org.ccpit.base.controller.BaseController;
import org.ccpit.base.user.User;
import org.ccpit.base.user.UserService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
......@@ -16,14 +13,14 @@ import javax.servlet.jsp.tagext.TagSupport;
/**
* Created by Administrator on 2015/9/8.
*/
public class CmsTagSupport extends TagSupport implements ApplicationContextAware{
public class CmsTagSupport extends TagSupport implements ApplicationContextAware {
static String SPLIT = ",";
static ApplicationContext ac;
public User getUser(){
public User getUser() {
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
Object obj = req.getSession().getAttribute(BaseController.USER_IN_SESSION);
if (obj==null)
if (obj == null)
return null;
return (User) obj;
// UserService userService = ac.getBean(UserService.class);
......@@ -33,21 +30,24 @@ public class CmsTagSupport extends TagSupport implements ApplicationContextAware
@Override
public int doStartTag() throws JspException {
if (getUser()==null)
if (getUser() == null)
return SKIP_BODY;
return validate()?EVAL_PAGE:SKIP_BODY;
return validate() ? EVAL_PAGE : SKIP_BODY;
}
/**
* validate the security return the result
*
* @return
*/
public boolean validate(){
public boolean validate() {
return false;
};
}
;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ac=applicationContext;
ac = applicationContext;
}
}
......@@ -3,15 +3,10 @@ package org.ccpit.base.security;
import org.apache.commons.lang.StringUtils;
import org.ccpit.base.controller.BaseController;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.jstl.sql.Result;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -19,7 +14,7 @@ import java.util.List;
/**
* 用户登录Filter 拦截后台所有请求
*
* <p>
* Created by sqp on 2015/9/30.
*/
public class LoginFilter implements Filter {
......@@ -27,6 +22,7 @@ public class LoginFilter implements Filter {
private List<String> exceptPaths = new ArrayList<String>();
//拦截之后重定向的url
private String redirectPath = "";
@Override
public void init(FilterConfig filterConfig) throws ServletException {
......@@ -43,16 +39,16 @@ public class LoginFilter implements Filter {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
if (exceptPaths.contains(request.getRequestURI())){
filterChain.doFilter(request,servletResponse);
if (exceptPaths.contains(request.getRequestURI())) {
filterChain.doFilter(request, servletResponse);
return;
}
if (request.getSession().getAttribute(BaseController.USER_IN_SESSION) == null&&request.getSession().getAttribute("registerInfo")==null) {
if (request.getSession().getAttribute(BaseController.USER_IN_SESSION) == null && request.getSession().getAttribute("registerInfo") == null) {
response.sendRedirect(redirectPath);
return;
}
filterChain.doFilter(request,servletResponse);
filterChain.doFilter(request, servletResponse);
}
@Override
......
package org.ccpit.base.security;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.ccpit.base.role.Role;
import org.ccpit.base.user.UserService;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
......@@ -19,21 +16,21 @@ public class SecurityAllRoleTag extends CmsTagSupport {
@Override
public boolean validate() {
if (roles==null||roles.isEmpty())
if (roles == null || roles.isEmpty())
return true;
String[] roles = getRoles().split(SPLIT);
List<Role> tagRoles = new ArrayList<Role>();
for (String roleId:roles){
Role r =new Role();
for (String roleId : roles) {
Role r = new Role();
if (StringUtils.isNumeric(roleId))
r.setId(Long.parseLong(roleId));
tagRoles.add(r);
}
Set<Role> userRoles = ac.getBean(UserService.class).getUserRolesIncludeGroup(getUser());
boolean can = true;
for (Role r:tagRoles){
if (!userRoles.contains(r)){
for (Role r : tagRoles) {
if (!userRoles.contains(r)) {
can = false;
break;
}
......
......@@ -16,23 +16,23 @@ import java.util.Set;
* Created by Administrator on 2015/9/7.
*/
public class SecurityAnyRoleTag extends CmsTagSupport {
private String roles;
private String roles;
@Override
public boolean validate() {
if (roles==null||roles.isEmpty())
if (roles == null || roles.isEmpty())
return true;
String[] roles = getRoles().split(SPLIT);
List<Role> tagRoles = new ArrayList<Role>();
for (String roleId:roles){
Role r =new Role();
for (String roleId : roles) {
Role r = new Role();
if (StringUtils.isNumeric(roleId))
r.setId(Long.parseLong(roleId));
tagRoles.add(r);
}
Set<Role> userRoles = ac.getBean(UserService.class).getUserRolesIncludeGroup(getUser());
return CollectionUtils.containsAny(tagRoles,userRoles);
return CollectionUtils.containsAny(tagRoles, userRoles);
}
public String getRoles() {
......
package org.ccpit.base.security;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.collections.CollectionUtils;
import org.ccpit.base.role.Role;
import org.ccpit.base.utils.UrlRolesMapper;
import org.ccpit.base.utils.UserRolesUtil;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.Set;
/**
* 自定义标签 判断用户权限
* Created by Administrator on 2015/9/7.
*/
@Component
public class SecurityUriTag extends CmsTagSupport{
/** Uri to check */
public class SecurityUriTag extends CmsTagSupport {
/**
* Uri to check
*/
private String uri;
@Override
public boolean validate() {
Set<Role> roles = ac.getBean(UrlRolesMapper.class).getRoles(getUri());
if (roles==null || roles.isEmpty()){
return false;
if (roles == null || roles.isEmpty()) {
return false;
}
UserRolesUtil userRolesUtil = ac.getBean(UserRolesUtil.class);
Set<Role> roleSet = userRolesUtil.getAllRoles((HttpServletRequest) pageContext.getRequest());
if (roleSet.isEmpty()){
return false;
if (roleSet.isEmpty()) {
return false;
}
return CollectionUtils.containsAny(roles,roleSet);
return CollectionUtils.containsAny(roles, roleSet);
}
public String getUri() {
......
......@@ -5,6 +5,8 @@ package org.ccpit.base.user;
*/
public interface IUser {
public String getUsername();
public String getLoginName();
public long getId();
}
package org.ccpit.base.user;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import org.ccpit.base.modol.BaseEntity;
import org.ccpit.base.role.Role;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* Created by Administrator on 2015/9/2.
*/
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User extends BaseEntity implements IUser,Serializable{
/**
* serialVersionUID:TODO(用一句话描述这个变量表示什么).
* @since JDK 1.6
*/
private static final long serialVersionUID = 1L;
/**
* 用户名
*/
public class User extends BaseEntity implements IUser, Serializable {
/**
* serialVersionUID:TODO(用一句话描述这个变量表示什么).
*
* @since JDK 1.6
*/
private static final long serialVersionUID = 1L;
/**
* 用户名
*/
private String username;
/**
* 密码
......@@ -61,26 +61,26 @@ public class User extends BaseEntity implements IUser,Serializable{
*/
private String telphone;
/**
* 创建人
*/
private String creator;
/**
* 创建人Id
*/
private long creatorId;
/**
* 创建时间
*/
private Date createTime;
/**
* 登录次数
*/
* 创建人
*/
private String creator;
/**
* 创建人Id
*/
private long creatorId;
/**
* 创建时间
*/
private Date createTime;
/**
* 登录次数
*/
private Integer loginCount;
/**
* 用户类型 (back | front)
*/
private String userType;
private Set<Role> roles = new HashSet<Role>();
@Override
......@@ -89,16 +89,17 @@ public class User extends BaseEntity implements IUser,Serializable{
public long getId() {
return super.getId();
}
@Override
public String getUsername() {
return username;
}
return username;
}
public void setUsername(String username) {
this.username = username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
public String getPassword() {
return password;
}
......@@ -117,26 +118,27 @@ public class User extends BaseEntity implements IUser,Serializable{
@Override
public int hashCode() {
return ("user"+getId()).hashCode();
return ("user" + getId()).hashCode();
}
@Override
public boolean equals(Object o) {
if(o == null){
if (o == null) {
return false;
}
if(o == this){
if (o == this) {
return true;
}
if(o.getClass() == User.class){
return o.hashCode()==this.hashCode();
if (o.getClass() == User.class) {
return o.hashCode() == this.hashCode();
}
return false;
}
@ManyToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "user_Roles",
joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName ="id")})
inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")})
public Set<Role> getRoles() {
return roles;
}
......@@ -144,71 +146,93 @@ public class User extends BaseEntity implements IUser,Serializable{
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getCountStatus() {
return countStatus;
}
public void setCountStatus(Integer countStatus) {
this.countStatus = countStatus;
}
public String getTelphone() {
return telphone;
}
public void setTelphone(String telphone) {
this.telphone = telphone;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public long getCreatorId() {
return creatorId;
}
public void setCreatorId(long creatorId) {
this.creatorId = creatorId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getLoginCount() {
return loginCount;
}
public void setLoginCount(Integer loginCount) {
this.loginCount = loginCount;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getCountStatus() {
return countStatus;
}
public void setCountStatus(Integer countStatus) {
this.countStatus = countStatus;
}
public String getTelphone() {
return telphone;
}
public void setTelphone(String telphone) {
this.telphone = telphone;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public long getCreatorId() {
return creatorId;
}
public void setCreatorId(long creatorId) {
this.creatorId = creatorId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getLoginCount() {
return loginCount;
}
public void setLoginCount(Integer loginCount) {
this.loginCount = loginCount;
}
}
package org.ccpit.base.user;
import java.util.Set;
import org.ccpit.base.dao.BaseDao;
import org.ccpit.base.role.Role;
import org.ccpit.base.usergroup.UserGroupDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.Set;
/**
* 用户实体操作类
* Created by sqp on 2015/9/5.
*/
@Repository
public class UserDao extends BaseDao<User>{
public class UserDao extends BaseDao<User> {
@Autowired
private UserGroupDao userGroupDao;
public User getUserByLoginName(String loginName){
String hql = "from User where loginName = ?";
User user = super.findUnique(hql, new String[]{loginName});
return user;
public User getUserByLoginName(String loginName) {
String hql = "from User where loginName = ?";
User user = super.findUnique(hql, new String[]{loginName});
return user;
}
/**
......@@ -30,20 +30,21 @@ public class UserDao extends BaseDao<User>{
* @param role
* @return
*/
public boolean canUserOrInGroup(User user,Role role){
public boolean canUserOrInGroup(User user, Role role) {
boolean can = canUser(user, role);
if (!can){
can = userGroupDao.canUserInGroup(user,role);
if (!can) {
can = userGroupDao.canUserInGroup(user, role);
}
return can;
}
/**
* 获取一个用户所拥有的所有角色,包括用户所在的组拥有的角色
*
* @param user
* @return
*/
public Set<Role> getUserRolesIncludeGroup(User user){
public Set<Role> getUserRolesIncludeGroup(User user) {
Set<Role> roles = user.getRoles();
Set<Role> rolesInGroup = userGroupDao.getRolesForUser(user);
roles.addAll(rolesInGroup);
......@@ -52,11 +53,12 @@ public class UserDao extends BaseDao<User>{
/**
* 判断用户是否具有某个角色
*
* @param user
* @param role
* @return
*/
public boolean canUser(User user,Role role){
public boolean canUser(User user, Role role) {
return user.getRoles().contains(role);
}
......
package org.ccpit.base.user;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.transaction.Transactional;
import org.ccpit.base.controller.Convert;
import org.ccpit.base.controller.Page;
import org.ccpit.base.controller.PageBo;
......@@ -18,49 +9,54 @@ import org.ccpit.base.role.RoleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Created by sqp on 2015/9/5.
*/
@Repository
@Transactional
public class UserService {
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd MM:hh:ss");
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd MM:hh:ss");
@Autowired
private UserDao userDao;
@Autowired
private RoleDao roleDao;
public List<User> getAllUsers(){
public List<User> getAllUsers() {
return userDao.queryAll();
}
public User getUserByLoginName(String loginName){
return userDao.getUserByLoginName(loginName);
public User getUserByLoginName(String loginName) {
return userDao.getUserByLoginName(loginName);
}
public boolean addUser(User user){
public boolean addUser(User user) {
return userDao.save(user);
}
public boolean updateUser(User user){
public boolean updateUser(User user) {
return userDao.update(user);
}
public boolean deleteUser(long id){
public boolean deleteUser(long id) {
return userDao.deleteById(id);
}
public Page<User> queryPage(PageRequest pr){
public Page<User> queryPage(PageRequest pr) {
Page<User> page = userDao.findPage(pr, "from " + User.class.getName(), new String[]{});
return page;
}
public Page<User> queryPage(PageRequest pr,String hql){
public Page<User> queryPage(PageRequest pr, String hql) {
Page<User> page = userDao.findPage(pr, hql, new String[]{});
return page;
}
public User getUser(long id){
public User getUser(long id) {
return userDao.queryById(id);
}
......@@ -71,80 +67,84 @@ public class UserService {
* @param role
* @return
*/
public boolean canUserOrInGroup(User user,Role role){
return userDao.canUserOrInGroup(user, role);
public boolean canUserOrInGroup(User user, Role role) {
return userDao.canUserOrInGroup(user, role);
}
/**
* 获取一个用户的所有角色
*
* @param user
* @return
*/
public Set<Role> getUserRoles(User user){
public Set<Role> getUserRoles(User user) {
User user1 = userDao.queryById(user.getId());
return user1.getRoles();
}
/**
* 获取一个用户所拥有的所有角色,包括用户所在的组拥有的角色
*
* @param user
* @return
*/
public Set<Role> getUserRolesIncludeGroup(User user){
public Set<Role> getUserRolesIncludeGroup(User user) {
return userDao.getUserRolesIncludeGroup(user);
}
public boolean saveUserRoles(User user,Long[] ids){
public boolean saveUserRoles(User user, Long[] ids) {
Set<Role> roles = new HashSet<Role>();
for (long id:ids){
for (long id : ids) {
roles.add(roleDao.queryById(id));
}
return saveUserRoles(user, roles);
}
public boolean saveUserRoles(User user,Set<Role> roleSet){
public boolean saveUserRoles(User user, Set<Role> roleSet) {
boolean success = false;
try {
user.getRoles().clear();
boolean b = userDao.update(user);
if(b){
User user1 = userDao.queryById(user.getId());
user1.setRoles(roleSet);
success = userDao.save(user1);
if (b) {
User user1 = userDao.queryById(user.getId());
user1.setRoles(roleSet);
success = userDao.save(user1);
}
}catch (Exception e){
} catch (Exception e) {
success = false;
}
return success;
}
public Map<String,Object> convertToMap(User User){
Map<String,Object> map = new HashMap<String, Object>();
if (User==null){
return map;
public Map<String, Object> convertToMap(User User) {
Map<String, Object> map = new HashMap<String, Object>();
if (User == null) {
return map;
}
Set<Role> roleSet = User.getRoles();
Set<Role> roleSet = User.getRoles();
String roles = "";
if(null != roleSet){
if(roleSet.size()>0){
for(Role role : roleSet){
roles += role.getRoleName()+",";
}
roles = roles.substring(0, roles.length()-1);
}
if (null != roleSet) {
if (roleSet.size() > 0) {
for (Role role : roleSet) {
roles += role.getRoleName() + ",";
}
roles = roles.substring(0, roles.length() - 1);
}
}
map.put("id",User.getId());
map.put("createTime",null == User.getCreateTime()? "": sdf.format(User.getCreateTime()));
map.put("id", User.getId());
map.put("createTime", null == User.getCreateTime() ? "" : sdf.format(User.getCreateTime()));
map.put("creator", User.getCreator());
map.put("username",User.getUsername());
map.put("loginName",User.getLoginName());
map.put("countStatus", 1 == User.getCountStatus()?"有效":"无效");
map.put("loginCount", User.getLoginCount());
map.put("username", User.getUsername());
map.put("loginName", User.getLoginName());
map.put("countStatus", 1 == User.getCountStatus() ? "有效" : "无效");
map.put("loginCount", User.getLoginCount());
map.put("company", User.getCompany());
map.put("userType","back".equals(User.getUserType())?"后台用户":"非后台用户");
map.put("userType", "back".equals(User.getUserType()) ? "后台用户" : "非后台用户");
map.put("roles", roles);
return map;
}
public PageBo<User> convert(Page<User> page){
public PageBo<User> convert(Page<User> page) {
return new PageBo<User>(page, new Convert<User>() {
@Override
public Map<String, Object> convert(User obj) {
......
package org.ccpit.base.utils;
import java.security.MessageDigest;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
/**
* @Description �����㷨
* @Description �����㷨
* @Version V0.1
* @Author zmc
* @Date 2015��4��3�� ����3:07:18 JDK�汾��sun jdk 1.6
* ���¼�¼****************************** �汾�� <�汾��> �޸����ڣ� <����> �޸��ˣ� <�޸�������>
* �޸����ݣ� <�޸���������>
**********************************************************************
*
* ���¼�¼****************************** �汾�� <�汾��> �޸����ڣ� <����> �޸��ˣ� <�޸�������>
* �޸����ݣ� <�޸���������>
* *********************************************************************
*/
public class CryptUtil {
private static String DES_Algorithm = "DESede";
private static String MD5_Algorithm = "MD5";
private static KeyGenerator keygen;
private static SecretKey deskey;
public static SecretKey genDESKey(byte[] keyByte) throws Exception {
SecretKey k = null;
k = new SecretKeySpec(keyByte, DES_Algorithm);
return k;
}
public static SecretKey genDESKey(String keyStr) throws Exception {
SecretKey k = null;
k = new SecretKeySpec(keyStr.getBytes(), DES_Algorithm);
return k;
}
public static SecretKey genDESKey() throws Exception {
if (keygen == null) {
keygen = KeyGenerator.getInstance(DES_Algorithm);
deskey = keygen.generateKey();
}
return deskey;
}
public static byte[] desEncrypt(SecretKey key, byte[] src) throws Exception {
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(1, key);
return cipher.doFinal(src);
}
public static String desEncrypt(SecretKey key, String src) throws Exception {
return new String(desEncrypt(key, src.getBytes()));
}
public static byte[] desEncrypt(byte[] src) throws Exception {
if (keygen == null) {
keygen = KeyGenerator.getInstance(DES_Algorithm);
deskey = keygen.generateKey();
}
Cipher cipher = Cipher.getInstance(DES_Algorithm);
cipher.init(1, deskey);
return cipher.doFinal(src);
}
public static String desEncrypt(String src) throws Exception {
return new String(desEncrypt(src.getBytes()));
}
public static byte[] desDecrypt(SecretKey key, byte[] crypt)
throws Exception {
Cipher cipher = Cipher.getInstance(DES_Algorithm);
cipher.init(2, key);
return cipher.doFinal(crypt);
}
public static String desDecrypt(SecretKey key, String crypt)
throws Exception {
return new String(desDecrypt(key, crypt.getBytes()));
}
public static byte[] desDecrypt(byte[] crypt) throws Exception {
if (keygen == null) {
keygen = KeyGenerator.getInstance(DES_Algorithm);
deskey = keygen.generateKey();
}
Cipher cipher = Cipher.getInstance(DES_Algorithm);
cipher.init(2, deskey);
return cipher.doFinal(crypt);
}
public static String desDecrypt(String crypt) throws Exception {
return new String(desDecrypt(crypt.getBytes()));
}
public static String md5Encrypt(String src) throws Exception {
byte[] md5 = md5Digest(src.getBytes("utf-8"));
return encodeHex(md5);
}
private static String md5Digest(String src) throws Exception {
return new String(md5Digest(src.getBytes("utf-8")));
}
private static byte[] md5Digest(byte[] src) throws Exception {
MessageDigest alg = MessageDigest.getInstance(MD5_Algorithm);
return alg.digest(src);
}
private static byte[] md5Digest(byte[] src, byte[] key) throws Exception {
MessageDigest alg = MessageDigest.getInstance(MD5_Algorithm);
alg.update(key);
return alg.digest(src);
}
private static String encodeHex(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if ((bytes[i] & 0xFF) < 16) {
buf.append("0");
}
buf.append(Long.toString(bytes[i] & 0xFF, 16));
}
return buf.toString();
}
private static String DES_Algorithm = "DESede";
private static String MD5_Algorithm = "MD5";
private static KeyGenerator keygen;
private static SecretKey deskey;
public static SecretKey genDESKey(byte[] keyByte) throws Exception {
SecretKey k = null;
k = new SecretKeySpec(keyByte, DES_Algorithm);
return k;
}
public static SecretKey genDESKey(String keyStr) throws Exception {
SecretKey k = null;
k = new SecretKeySpec(keyStr.getBytes(), DES_Algorithm);
return k;
}
public static SecretKey genDESKey() throws Exception {
if (keygen == null) {
keygen = KeyGenerator.getInstance(DES_Algorithm);
deskey = keygen.generateKey();
}
return deskey;
}
public static byte[] desEncrypt(SecretKey key, byte[] src) throws Exception {
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(1, key);
return cipher.doFinal(src);
}
public static String desEncrypt(SecretKey key, String src) throws Exception {
return new String(desEncrypt(key, src.getBytes()));
}
public static byte[] desEncrypt(byte[] src) throws Exception {
if (keygen == null) {
keygen = KeyGenerator.getInstance(DES_Algorithm);
deskey = keygen.generateKey();
}
Cipher cipher = Cipher.getInstance(DES_Algorithm);
cipher.init(1, deskey);
return cipher.doFinal(src);
}
public static String desEncrypt(String src) throws Exception {
return new String(desEncrypt(src.getBytes()));
}
public static byte[] desDecrypt(SecretKey key, byte[] crypt)
throws Exception {
Cipher cipher = Cipher.getInstance(DES_Algorithm);
cipher.init(2, key);
return cipher.doFinal(crypt);
}
public static String desDecrypt(SecretKey key, String crypt)
throws Exception {
return new String(desDecrypt(key, crypt.getBytes()));
}
public static byte[] desDecrypt(byte[] crypt) throws Exception {
if (keygen == null) {
keygen = KeyGenerator.getInstance(DES_Algorithm);
deskey = keygen.generateKey();
}
Cipher cipher = Cipher.getInstance(DES_Algorithm);
cipher.init(2, deskey);
return cipher.doFinal(crypt);
}
public static String desDecrypt(String crypt) throws Exception {
return new String(desDecrypt(crypt.getBytes()));
}
public static String md5Encrypt(String src) throws Exception {
byte[] md5 = md5Digest(src.getBytes("utf-8"));
return encodeHex(md5);
}
private static String md5Digest(String src) throws Exception {
return new String(md5Digest(src.getBytes("utf-8")));
}
private static byte[] md5Digest(byte[] src) throws Exception {
MessageDigest alg = MessageDigest.getInstance(MD5_Algorithm);
return alg.digest(src);
}
private static byte[] md5Digest(byte[] src, byte[] key) throws Exception {
MessageDigest alg = MessageDigest.getInstance(MD5_Algorithm);
alg.update(key);
return alg.digest(src);
}
private static String encodeHex(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if ((bytes[i] & 0xFF) < 16) {
buf.append("0");
}
buf.append(Long.toString(bytes[i] & 0xFF, 16));
}
return buf.toString();
}
/*public static String base64Encode(String src) {
BASE64Encoder encoder = new BASE64Encoder();
......
......@@ -6,7 +6,6 @@ package org.ccpit.base.utils;
import org.apache.commons.lang.StringUtils;
import org.ccpit.base.modol.EscapeHTML;
import org.ccpit.base.modol.EscapeSql;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
......@@ -65,12 +64,13 @@ public class HtmlEscapeUtil<T> {
/**
* Escape the Sql with the annotation
*
* @param t
* @return
*/
public T escape(T t){
public T escape(T t) {
EscapeHTML annotation = t.getClass().getAnnotation(EscapeHTML.class);
if (annotation!=null){
if (annotation != null) {
encode(t);
except(annotation.except());
execute();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package org.ccpit.base.utils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.ccpit.base.user.User;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
......@@ -26,8 +24,8 @@ public class MailSender {
public static String HOST;
private static final Logger logger = Logger.getLogger(MailSender.class);
static{
Map<String,String> configMap = ReadConfigUtil.getPlatformConfig();
static {
Map<String, String> configMap = ReadConfigUtil.getPlatformConfig();
USERNAME = configMap.get("email.name");
PASSWORD = configMap.get("email.password");
HOST = configMap.get("email.host");
......@@ -35,18 +33,20 @@ public class MailSender {
/**
* 发送邮件
*
* @param targetAddress 收件人
* @param subject 主题
* @param body 内容
* @param subject 主题
* @param body 内容
* @return 发送成功
*/
public static boolean send(String targetAddress,String subject,String body){
public static boolean send(String targetAddress, String subject, String body) {
EmailBody emailBody = new EmailBody();
emailBody.setContent(body);
emailBody.setSubject(subject);
emailBody.setSentDate(new Date());
return send(targetAddress,emailBody);
return send(targetAddress, emailBody);
}
/**
* 发送邮件
*
......@@ -56,7 +56,7 @@ public class MailSender {
* @param: @param mimeDTO 邮件部分参数
* @return: boolean
*/
public static boolean send(String targetAddress, EmailBody body){
public static boolean send(String targetAddress, EmailBody body) {
Properties props = new Properties();
props.put("mail.pop.host", HOST);
props.setProperty("mail.pop.auth", "true");
......@@ -64,7 +64,7 @@ public class MailSender {
props.put("mail.pop.password", PASSWORD);
props.put("mail.pop.starttls.enable", "true");
props.put("mail.transport.protocol", "POP3");
props.put("mail.pop.port",465);
props.put("mail.pop.port", 465);
Session session = Session.getInstance(props, new PopupAuthenticator(USERNAME, PASSWORD));
boolean success = false;
......@@ -87,7 +87,7 @@ public class MailSender {
logger.info("成功发送了邮件到" + targetAddress + " 主题:[" + body.getSubject() + "] 内容[" + body.getContent() + "]");
} catch (Exception e) {
success = false;
logger.warn("到"+targetAddress+"的邮件发送失败,"+e);
logger.warn("到" + targetAddress + "的邮件发送失败," + e);
// throw new RuntimeException("email send error",e);
}
return success;
......
......@@ -17,6 +17,7 @@ public class PopupAuthenticator extends Authenticator {
this.username = user;
this.password = pass;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
......
package org.ccpit.base.utils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @Description TODO【用一句话描述该文件做什么】
* @Author dingwei
......@@ -42,7 +42,7 @@ public class ReadConfigUtil {
}
if (properties != null)
for (Enumeration en = properties.propertyNames(); en
.hasMoreElements();) {
.hasMoreElements(); ) {
String key = (String) en.nextElement();
String value = properties.getProperty(key);
......
......@@ -8,7 +8,6 @@ import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.ccpit.base.modol.EscapeSql;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
......@@ -103,18 +102,20 @@ public class SqlEscapeUtil<T> {
/**
* Escape the Sql with the annotation
*
* @param t
* @return
*/
public T escape(T t){
public T escape(T t) {
EscapeSql annotation = t.getClass().getAnnotation(EscapeSql.class);
if (annotation!=null){
if (annotation != null) {
encode(t);
except(annotation.except());
execute();
}
return t;
}
/**
* 过滤方法
*
......
......@@ -11,7 +11,6 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Repository;
import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
......@@ -68,7 +67,7 @@ public class UserRolesUtil implements ApplicationContextAware {
public Set<Role> getRoles(HttpServletRequest request, String scope) {
Set<Role> roles = new HashSet<Role>();
Object object = request.getSession().getAttribute(scope);
if(object==null) {
if (object == null) {
initOrReload(request);
object = request.getSession().getAttribute(scope);
}
......
package org.ccpit.base.utils;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import javax.imageio.ImageIO;
/**
* 验证码生成器
* @author dsna
*
* @author dsna
*/
public class ValidateCode {
// 图片的宽度。
private int width = 160;
// 图片的高度。
private int height = 40;
// 验证码字符个数
private int codeCount = 4;
// 验证码干扰线数
private int lineCount = 80;
// 验证码
private String code = null;
// 验证码图片Buffer
private BufferedImage buffImg=null;
// 图片的宽度。
private int width = 160;
// 图片的高度。
private int height = 40;
// 验证码字符个数
private int codeCount = 4;
// 验证码干扰线数
private int lineCount = 80;
// 验证码
private String code = null;
// 验证码图片Buffer
private BufferedImage buffImg = null;
private char[] codeSequence = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8'};
public ValidateCode() {
this.createCode();
}
/**
* @param width 图片宽
* @param height 图片高
*/
public ValidateCode(int width, int height) {
this.width = width;
this.height = height;
this.createCode();
}
/**
* @param width 图片宽
* @param height 图片高
* @param codeCount 字符个数
* @param lineCount 干扰线条数
*/
public ValidateCode(int width, int height, int codeCount, int lineCount) {
this.width = width;
this.height = height;
this.codeCount = codeCount;
this.lineCount = lineCount;
this.createCode();
}
public void createCode() {
int x = 0, fontHeight = 0, codeY = 0;
int red = 0, green = 0, blue = 0;
x = width / (codeCount + 2);//每个字符的宽度
fontHeight = height - 2;//字体的高度
codeY = height - 4;
// 图像buffer
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
// 生成随机数
Random random = new Random();
// 将图像填充为白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
// 创建字体
ImgFontByte imgFont = new ImgFontByte();
Font font = imgFont.getFont(fontHeight);
g.setFont(font);
for (int i = 0; i < lineCount; i++) {
int xs = random.nextInt(width);
int ys = random.nextInt(height);
int xe = xs + random.nextInt(width / 8);
int ye = ys + random.nextInt(height / 8);
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);
g.setColor(Color.white);
g.drawLine(xs, ys, xe, ye);
}
// randomCode记录随机产生的验证码
StringBuffer randomCode = new StringBuffer();
// 随机产生codeCount个字符的验证码。
for (int i = 0; i < codeCount; i++) {
String strRand = String.valueOf(codeSequence[random.nextInt(codeSequence.length)]);
// 产生随机的颜色值,让输出的每个字符的颜色值都将不同。
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);
g.setColor(Color.black);
g.drawString(strRand, (i + 1) * x, codeY);
// 将产生的四个随机数组合在一起。
randomCode.append(strRand);
}
// 将四位数字的验证码保存到Session中。
code = randomCode.toString();
}
public void write(String path) throws IOException {
OutputStream sos = new FileOutputStream(path);
this.write(sos);
}
private char[] codeSequence = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8' };
public void write(OutputStream sos) throws IOException {
ImageIO.write(buffImg, "png", sos);
sos.close();
}
public ValidateCode() {
this.createCode();
}
public BufferedImage getBuffImg() {
return buffImg;
}
/**
*
* @param width 图片宽
* @param height 图片高
*/
public ValidateCode(int width,int height) {
this.width=width;
this.height=height;
this.createCode();
}
/**
*
* @param width 图片宽
* @param height 图片高
* @param codeCount 字符个数
* @param lineCount 干扰线条数
*/
public ValidateCode(int width,int height,int codeCount,int lineCount) {
this.width=width;
this.height=height;
this.codeCount=codeCount;
this.lineCount=lineCount;
this.createCode();
}
public void createCode() {
int x = 0,fontHeight=0,codeY=0;
int red = 0, green = 0, blue = 0;
x = width / (codeCount +2);//每个字符的宽度
fontHeight = height - 2;//字体的高度
codeY = height - 4;
// 图像buffer
buffImg = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImg.createGraphics();
// 生成随机数
Random random = new Random();
// 将图像填充为白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
// 创建字体
ImgFontByte imgFont=new ImgFontByte();
Font font =imgFont.getFont(fontHeight);
g.setFont(font);
for (int i = 0; i < lineCount; i++) {
int xs = random.nextInt(width);
int ys = random.nextInt(height);
int xe = xs+random.nextInt(width/8);
int ye = ys+random.nextInt(height/8);
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);
g.setColor(Color.white);
g.drawLine(xs, ys, xe, ye);
}
// randomCode记录随机产生的验证码
StringBuffer randomCode = new StringBuffer();
// 随机产生codeCount个字符的验证码。
for (int i = 0; i < codeCount; i++) {
String strRand = String.valueOf(codeSequence[random.nextInt(codeSequence.length)]);
// 产生随机的颜色值,让输出的每个字符的颜色值都将不同。
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);
g.setColor(Color.black);
g.drawString(strRand, (i + 1) * x, codeY);
// 将产生的四个随机数组合在一起。
randomCode.append(strRand);
}
// 将四位数字的验证码保存到Session中。
code=randomCode.toString();
}
public void write(String path) throws IOException {
OutputStream sos = new FileOutputStream(path);
this.write(sos);
}
public void write(OutputStream sos) throws IOException {
ImageIO.write(buffImg, "png", sos);
sos.close();
}
public BufferedImage getBuffImg() {
return buffImg;
}
public String getCode() {
return code;
}
public String getCode() {
return code;
}
}
......@@ -5,8 +5,7 @@
* Package Name:org.ccpit.base.utils.mailUtil
* Date:2015年11月19日上午10:50:34
* Copyright (c) 2015, dingwei@ccpit.org All Rights Reserved.
*
*/
*/
package org.ccpit.base.utils.mailUtil;
......@@ -17,131 +16,151 @@ import java.io.Serializable;
* Function: 邮件信息属性实体类. <br/>
* Reason: TODO ADD REASON. <br/>
* Date: 2015年11月19日 上午10:50:34 <br/>
* @author dingwei
* @version
* @since JDK 1.6
* @see
* @author dingwei
* @version
* @since JDK 1.6
* @see
*/
public class Mail implements Serializable{
/**
* serialVersionUID:TODO(用一句话描述这个变量表示什么).
* @since JDK 1.6
*/
private static final long serialVersionUID = 1L;
public static final String ENCODEING = "utf-8";
/**
* 邮件服务器地址
*/
private String host;
/**
* 协议
*/
private String protocol;
/**
* 发件人地址
*/
private String sender;
/**
* 收件人地址
*/
private String receiver;
/**
* 抄送人
*/
private String copyTo;
/**
* 发件人昵称
*/
private String name;
/**
* 发件人邮箱账号
*/
private String emailCount;
/**
* 发件人邮箱账号密码
*/
private String emailPassword;
/**
* 邮件主题
*/
private String mailTitle;
/**
* 邮件内容
*/
private String mailMessage;
//附件
private String affix;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmailCount() {
return emailCount;
}
public void setEmailCount(String emailCount) {
this.emailCount = emailCount;
}
public String getEmailPassword() {
return emailPassword;
}
public void setEmailPassword(String emailPassword) {
this.emailPassword = emailPassword;
}
public String getMailTitle() {
return mailTitle;
}
public void setMailTitle(String mailTitle) {
this.mailTitle = mailTitle;
}
public String getMailMessage() {
return mailMessage;
}
public void setMailMessage(String mailMessage) {
this.mailMessage = mailMessage;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getCopyTo() {
return copyTo;
}
public void setCopyTo(String copyTo) {
this.copyTo = copyTo;
}
public String getAffix() {
return affix;
}
public void setAffix(String affix) {
this.affix = affix;
}
public class Mail implements Serializable {
/**
* serialVersionUID:TODO(用一句话描述这个变量表示什么).
* @since JDK 1.6
*/
private static final long serialVersionUID = 1L;
public static final String ENCODEING = "utf-8";
/**
* 邮件服务器地址
*/
private String host;
/**
* 协议
*/
private String protocol;
/**
* 发件人地址
*/
private String sender;
/**
* 收件人地址
*/
private String receiver;
/**
* 抄送人
*/
private String copyTo;
/**
* 发件人昵称
*/
private String name;
/**
* 发件人邮箱账号
*/
private String emailCount;
/**
* 发件人邮箱账号密码
*/
private String emailPassword;
/**
* 邮件主题
*/
private String mailTitle;
/**
* 邮件内容
*/
private String mailMessage;
//附件
private String affix;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmailCount() {
return emailCount;
}
public void setEmailCount(String emailCount) {
this.emailCount = emailCount;
}
public String getEmailPassword() {
return emailPassword;
}
public void setEmailPassword(String emailPassword) {
this.emailPassword = emailPassword;
}
public String getMailTitle() {
return mailTitle;
}
public void setMailTitle(String mailTitle) {
this.mailTitle = mailTitle;
}
public String getMailMessage() {
return mailMessage;
}
public void setMailMessage(String mailMessage) {
this.mailMessage = mailMessage;
}
public String getProtocol() {
return protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public String getCopyTo() {
return copyTo;
}
public void setCopyTo(String copyTo) {
this.copyTo = copyTo;
}
public String getAffix() {
return affix;
}
public void setAffix(String affix) {
this.affix = affix;
}
}
......@@ -102,6 +102,7 @@ public class ExcelHelper {
cell22.setCellType(XSSFCell.CELL_TYPE_STRING);
cell23.setCellType(XSSFCell.CELL_TYPE_STRING);
cell24.setCellType(XSSFCell.CELL_TYPE_STRING);
cell25.setCellType(XSSFCell.CELL_TYPE_STRING);
//在单元格中输入数据
cell0.setCellValue("提交时间");
......@@ -129,6 +130,7 @@ public class ExcelHelper {
cell22.setCellValue("考试科目");
cell23.setCellValue("报名类型");
cell24.setCellValue("报名状态");
cell25.setCellValue("是否购买CDCS/CSDG考前培训");
cell0.setCellStyle(style);
//循环导出数据到excel中
for (int i = 0; i < newsInfoList.size(); i++) {
......@@ -159,6 +161,9 @@ public class ExcelHelper {
rowi.createCell(21).setCellValue(registerInfo.getCity_en()); //CITY SELECT
rowi.createCell(22).setCellValue(registerInfo.getSubject()); //考试科目
rowi.createCell(24).setCellValue(registerInfo.getRegisterStatus()); //报名状态
if(null != registerInfo.getIfBuyFee()){
rowi.createCell(25).setCellValue(1 == registerInfo.getIfBuyFee() ? "是":"否"); //是否购买CDCS/CSDG靠前培训
}
}
try {
book.write(os);
......
......@@ -25,9 +25,7 @@ import org.ccpit.base.user.User;
import org.ccpit.business.phase.Phase;
import org.ccpit.business.phase.PhaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
......
......@@ -26,7 +26,7 @@ import org.springframework.format.annotation.DateTimeFormat;
* Reason: TODO ADD REASON. <br/>
* Date: 2015年11月9日 下午5:33:37 <br/>
*
* @author sunqipeng
* @author dingwei
* @see
* @since JDK 1.6
*/
......@@ -95,6 +95,10 @@ public class RegisterInfo implements Serializable {
*/
private Integer invoiceType;
/**
* 是否购买CDCS/CSDG考前培训 1 表示 是 | 2 表示否
*/
private Integer ifBuyFee;
/**
* 省
*/
private String province;
......@@ -721,5 +725,13 @@ public class RegisterInfo implements Serializable {
public void setDistrict(String district) {
this.district = district;
}
public Integer getIfBuyFee() {
return ifBuyFee;
}
public void setIfBuyFee(Integer ifBuyFee) {
this.ifBuyFee = ifBuyFee;
}
}
# jdbc.X
jdbc.driverClassName=com.mysql.jdbc.Driver
# 生产环境 docker 环境下一定要注意 将localhost 换成mysql
jdbc.url=jdbc:mysql://mysql:3306/registration?createDatabaseIfNotExist=true&characterEncoding=utf-8
jdbc.user=root
jdbc.pass=root
#jdbc.url=jdbc:mysql://mysql:3306/registration?createDatabaseIfNotExist=true&characterEncoding=utf-8
#jdbc.user=root
#jdbc.pass=root
# 开发环境
#jdbc.url=jdbc:mysql://localhost:3306/registration_0611?createDatabaseIfNotExist=true&characterEncoding=utf-8
#jdbc.user=ccpit
#jdbc.pass=ccpit1516
jdbc.url=jdbc:mysql://localhost:3306/registration_0611?createDatabaseIfNotExist=true&characterEncoding=utf-8
jdbc.user=ccpit
jdbc.pass=ccpit1516
# hibernate.X
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
......
/* create by dingwei 20211212 start */
alter table reg_subjectinfo add province varchar(100) Null;
alter table reg_subjectinfo add chengshi varchar(100) Null;
alter table reg_subjectinfo add district varchar(100) Null;
alter table reg_subjectinfo
add province varchar(100) Null;
alter table reg_subjectinfo
add chengshi varchar(100) Null;
alter table reg_subjectinfo
add district varchar(100) Null;
/* create by dingwei 20211212 end */
/* create by dingwei 20210611 start */
delete from reg_subjectinfo where registerInfo_id = 12978;
delete from reg_subjectinfo where registerInfo_id = 12977;
delete from reg_subjectinfo where registerInfo_id = 12976;
delete from reg_subjectinfo where registerInfo_id = 12975;
delete from reg_subjectinfo where registerInfo_id = 12969;
delete from reg_subjectinfo where registerInfo_id = 12974;
delete from reg_subjectinfo where registerInfo_id = 12971;
delete from reg_subjectinfo where registerInfo_id = 12970;
delete from reg_subjectinfo where registerInfo_id = 12968;
delete from reg_subjectinfo where registerInfo_id = 12967;
delete from reg_subjectinfo where registerInfo_id = 12964;
delete from reg_subjectinfo where registerInfo_id = 12956;
delete from reg_subjectinfo where registerInfo_id = 12955;
delete from reg_subjectinfo where registerInfo_id = 12954;
delete from reg_subjectinfo where registerInfo_id = 12953;
delete
from reg_subjectinfo
where registerInfo_id = 12978;
delete
from reg_subjectinfo
where registerInfo_id = 12977;
delete
from reg_subjectinfo
where registerInfo_id = 12976;
delete
from reg_subjectinfo
where registerInfo_id = 12975;
delete
from reg_subjectinfo
where registerInfo_id = 12969;
delete
from reg_subjectinfo
where registerInfo_id = 12974;
delete
from reg_subjectinfo
where registerInfo_id = 12971;
delete
from reg_subjectinfo
where registerInfo_id = 12970;
delete
from reg_subjectinfo
where registerInfo_id = 12968;
delete
from reg_subjectinfo
where registerInfo_id = 12967;
delete
from reg_subjectinfo
where registerInfo_id = 12964;
delete
from reg_subjectinfo
where registerInfo_id = 12956;
delete
from reg_subjectinfo
where registerInfo_id = 12955;
delete
from reg_subjectinfo
where registerInfo_id = 12954;
delete
from reg_subjectinfo
where registerInfo_id = 12953;
/* create by dingwei 20210611 end */
/* create by dingwei 20210617 start */
set character set utf8;
update reg_subjectinfo set registerName = '邓默' where registerInfo_id = 12983;
update reg_subjectinfo set registerName = '丁伟' where registerInfo_id = 12979;
update reg_subjectinfo set registerName = '丁伟' where registerInfo_id = 12979;
set
character set utf8;
update reg_subjectinfo
set registerName = '邓默'
where registerInfo_id = 12983;
update reg_subjectinfo
set registerName = '丁伟'
where registerInfo_id = 12979;
update reg_subjectinfo
set registerName = '丁伟'
where registerInfo_id = 12979;
/* create by dingwei 20210617 end */
/* create by dingwei 20210702 start */
alter table reg_registerinfo modify taxIssue Integer;
alter table reg_subjectinfo modify taxIssue Integer;
alter table reg_registerinfo modify taxIssue Integer;
alter table reg_subjectinfo modify taxIssue Integer;
/* create by dingwei 20210702 end */
select id,name,whetherDelete from reg_registerinfo where taxpayerNum = '9142';
\ No newline at end of file
select id, name, whetherDelete
from reg_registerinfo
where taxpayerNum = '9142';
\ No newline at end of file
......@@ -270,6 +270,15 @@
</c:if>
</c:if>
<tr>
<td class="name">是否购买CDCS/CSDG</br>考前培训:</td>
<c:if test="${registerInfo.ifBuyFee == 1}">
<td></td>
</c:if>
<c:if test="${registerInfo.ifBuyFee == 2}">
<td></td>
</c:if>
</tr>
<tr>
<td class="name">Family Name:</td>
<td>${registerInfo.name_en}</td>
......@@ -312,11 +321,11 @@
<td class="name">COUNTRY:</td>
<td>中国</td>
</tr>
<tr>
<td class="title" background="/resource/front/img/dh.gif" height="24" colspan="3">
上传考生名片
</td>
</tr>
<%-- <tr>--%>
<%-- <td class="title" background="/resource/front/img/dh.gif" height="24" colspan="3">--%>
<%-- 上传考生名片--%>
<%-- </td>--%>
<%-- </tr>--%>
<%-- <tr>--%>
<%-- <td class="name">选择科目</td>--%>
<%-- <td align="left" width="30%">--%>
......@@ -331,34 +340,34 @@
<%-- </select>--%>
<%-- </td>--%>
<%-- </tr>--%>
<tr>
<td class="name">考生名片:</td>
<td align="left" width="30%">
<input id="imageUrlId1" class="PhotoUpload" type="file" name='file'/>
</td>
<td align="left">
<input data-target="imageUrlId1" class="PhotoUploadButton" type="button" value="上传"
name="upload" style="width:80px;height:20px">
</td>
</tr>
<tr>
<td></td>
<td>
<div><img data-target="imageUrlId1" id="img1" src="${registerInfo.img1}"
style="width:150px;height:100px"></div>
</td>
<td align="left" valign="top">
<p style="color: #000000">图片支持式为:bmp、gif、jpeg、jpg、png,图片大小不要超过1M</p>
<p style="color: red;font-size:16px">如开具增值税专用发票,请考生上传个人名片,</p>
<p style="color: red;font-size:16px">或其他可证明考生供职于发票抬头所在单位的证明文件,如工牌、入职证明书(拍照即可)等</p>
</td>
</tr>
<tr>
<td></td>
<td>
<Button id="saveCertificateId" style="width:80px;height:20px">保存照片</Button>
</td>
</tr>
<%-- <tr>--%>
<%-- <td class="name">考生名片:</td>--%>
<%-- <td align="left" width="30%">--%>
<%-- <input id="imageUrlId1" class="PhotoUpload" type="file" name='file'/>--%>
<%-- </td>--%>
<%-- <td align="left">--%>
<%-- <input data-target="imageUrlId1" class="PhotoUploadButton" type="button" value="上传"--%>
<%-- name="upload" style="width:80px;height:20px">--%>
<%-- </td>--%>
<%-- </tr>--%>
<%-- <tr>--%>
<%-- <td></td>--%>
<%-- <td>--%>
<%-- <div><img data-target="imageUrlId1" id="img1" src="${registerInfo.img1}"--%>
<%-- style="width:150px;height:100px"></div>--%>
<%-- </td>--%>
<%-- <td align="left" valign="top">--%>
<%-- <p style="color: #000000">图片支持式为:bmp、gif、jpeg、jpg、png,图片大小不要超过1M</p>--%>
<%-- <p style="color: red;font-size:16px">如开具增值税专用发票,请考生上传个人名片,</p>--%>
<%-- <p style="color: red;font-size:16px">或其他可证明考生供职于发票抬头所在单位的证明文件,如工牌、入职证明书(拍照即可)等</p>--%>
<%-- </td>--%>
<%-- </tr>--%>
<%-- <tr>--%>
<%-- <td></td>--%>
<%-- <td>--%>
<%-- <Button id="saveCertificateId" style="width:80px;height:20px">保存照片</Button>--%>
<%-- </td>--%>
<%-- </tr>--%>
<tr>
<td class="title" background="/resource/front/img/dh.gif" height="24" colspan="3">My LIBF 登录
......
......@@ -46,7 +46,7 @@
<tr id="trEmial" name="email33">
<td class="name" width="15%"><span style="color: red;">*</span><yh:yh id="1_Info_Email" english="E-mail:" isnotnull="1">邮箱:</yh:yh></td>
<td width="25%"><input name="email" value="" style="width:220px" onblur="this.value=this.value.toLowerCase().replace(/(^\s*)|(\s*$)/g,&quot;&quot;); " type="text"><input name="A_MAINID" type="hidden"><input name="A_LINK_ID" type="hidden"><input name="A_ROLEID" type="hidden"><input name="A_LANGID" type="hidden"><input name="A_CON_CNF_ID" type="hidden"><input name="A_STAT_ID" type="hidden"><input name="A_AUDITSTATE" type="hidden"><input name="D_LINK_ID" type="hidden"><input name="D_MAINID" type="hidden"></td>
<td width="50%"><span class="reg_body">必填:请勿使用QQ邮箱,邮箱会作为登录名,请如实填写</span></td>
<td width="50%"><span class="reg_body">必填:邮箱会作为登录名,请如实填写</span></td>
</tr>
<tr id="trPassWord" name="password33">
<td class="name"><span style="color: red;">*</span><yh:yh id="1_Info_Password" english="Password:" isnotnull="1">密码:</yh:yh></td>
......@@ -122,7 +122,14 @@
type="text"></textarea></td>
<td><span class="reg_body">必填:可以安全收到邮寄材料的地址</span></td>
</tr>
<tr id="trIfBuyFee" name="trIfBuyFee">
<td class="name"><span style="color: red;">*</span>是否购买CDCS/CSDG</br>考前培训:</td>
<td >
<input class="required" checked="checked" type="radio" name="ifBuyFee" value="1" width="40%"></input>&emsp;&emsp;
<input class="required" type="radio" name="ifBuyFee" value="2" width="40%"></input>
</td>
<td><span class="reg_body">必选</span></td>
</tr>
<tr>
<td class="name"><span style="color: red;">*</span><yh:yh id="1_customitem6" english="Custom Item6:" isnotnull="0">增值税发票:</yh:yh></td>
<td><select class="required" id="appreciationTaxTypeId" name="appreciationTaxType" style="width:225px">
......
......@@ -67,7 +67,7 @@
<tr id="trEmial" name="email33">
<td class="name" width="15%"><span style="color: red;">*</span><yh:yh id="1_Info_Email" english="E-mail:" isnotnull="1">邮箱:</yh:yh></td>
<td width="25%"><input name="email" value="" style="width:220px" onblur="this.value=this.value.toLowerCase().replace(/(^\s*)|(\s*$)/g,&quot;&quot;); " type="text"><input name="A_MAINID" type="hidden"><input name="A_LINK_ID" type="hidden"><input name="A_ROLEID" type="hidden"><input name="A_LANGID" type="hidden"><input name="A_CON_CNF_ID" type="hidden"><input name="A_STAT_ID" type="hidden"><input name="A_AUDITSTATE" type="hidden"><input name="D_LINK_ID" type="hidden"><input name="D_MAINID" type="hidden"></td>
<td width="50%"><span class="reg_body">请勿使用QQ邮箱,邮箱会作为登录名,请如实填写</span></td>
<td width="50%"><span class="reg_body">邮箱会作为登录名,请如实填写</span></td>
</tr>
<tr id="trPassWord" name="password33">
<td class="name"><span style="color: red;">*</span><yh:yh id="1_Info_Password" english="Password:" isnotnull="1">密码:</yh:yh></td>
......
......@@ -85,10 +85,10 @@ var REG = function () {
});
$("[name=email]").on("blur", function () {
var e = $("[name=email]").val();
if (new RegExp("^\\w+@qq\.com$").test(e)) {
showWarning($("[name=email]"), "请勿使用QQ邮箱注册!");
return;
}
// if (new RegExp("^\\w+@qq\.com$").test(e)) {
// showWarning($("[name=email]"), "请勿使用QQ邮箱注册!");
// return;
// }
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(e)) {
showWarning($("[name=email]"), "邮箱格式不正确!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment