Commit a7d0155a authored by zhouqian's avatar zhouqian

first login

parent f9413568
package cn.quantgroup.xyqb.controller.internal.user;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.IdCardInfo;
import cn.quantgroup.xyqb.model.IdType;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.util.ValidationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp;
import java.text.ParseException;
/**
* Created by Miraculous on 2017/1/3.
*/
@RestController
@RequestMapping("/user_detail")
public class UserDetailController implements IBaseController {
@Autowired
private IUserDetailService userDetailService;
@Autowired
private IIdCardService idCardService;
private static final Logger LOGGER = LoggerFactory.getLogger(UserDetailController.class);
@RequestMapping("/save")
public JsonResult saveUserdetail(String idNo, String name) {
try {
if (!ValidationUtil.validateChinese(name)) {
return JsonResult.buildErrorStateResult("姓名错误", null);
}
IdCardInfo info = idCardService.getIdCardInfo(idNo);
if (!info.isValid()) {
return JsonResult.buildErrorStateResult("身份证号码错误", null);
}
User user = getCurrentUser();
if (user == null) {
return JsonResult.buildErrorStateResult("系统错误", null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
UserDetail userDetail = new UserDetail();
userDetail.setIdNo(idNo);
userDetail.setPhoneNo(user.getPhoneNo());
userDetail.setUserId(user.getId());
userDetail.setCreatedAt(now);
userDetail.setUpdatedAt(now);
userDetail.setName(name);
userDetail.setGender(info.getGender());
userDetail.setEmail("");
userDetail.setIdType(IdType.ID_CARD);
userDetail.setIsAuthenticated(false);
userDetail.setQq("");
userDetailService.saveUserDetail(userDetail);
return JsonResult.buildSuccessResult("", null);
} catch (ParseException ex) {
LOGGER.error("身份证号错误, idNo: {}", idNo);
return JsonResult.buildErrorStateResult("身份证号码错误", null);
}
}
}
......@@ -39,6 +39,6 @@ public class Address implements Serializable{
private String address;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "update_at")
@Column(name = "updated_at")
private Timestamp updateAt;
}
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.entity.enumerate.Relation;
import lombok.Data;
import javax.persistence.*;
......@@ -26,9 +27,9 @@ public class Contact implements Serializable {
@Column(name = "phone_no")
private String phoneNo;
@Column(name = "relation")
private String relation;
@Column(name = "create_at")
private Relation relation;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "update_at")
@Column(name = "updated_at")
private Timestamp updateAt;
}
......@@ -47,7 +47,7 @@ public class UserExtInfo implements Serializable {
private boolean marryStatus;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "update_at")
@Column(name = "updated_at")
private Timestamp updateAt;
}
package cn.quantgroup.xyqb.entity.enumerate;
/**
* Created by Miraculous on 2017/1/3.
*/
public enum Relation {
PARENT("父母"),
CHILDREN("子女"),
BROTHER("兄弟姐妹"),
COLLEAGUE("同事"),
CLASSMATE("同学"),
FRIEND("朋友"),
SPOUSE("夫妻"),
SELF("本人"),
OTHER("其他");
String description;
Relation(String desc) {
description = desc;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("Relation{");
sb.append("description='").append(description).append('\'');
sb.append('}');
return sb.toString();
}
}
......@@ -63,7 +63,11 @@ public class RequestFilter implements Filter {
if (sessionStruct == null) {
return;
}
sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues());
try {
sessionService.persistSession(sessionStruct.getSid(), sessionStruct.getValues());
} finally {
XyqbSessionContextHolder.releaseSession();
}
}
private boolean isMatch(String path) {
......
......@@ -6,6 +6,7 @@ import cn.quantgroup.xyqb.function.OneArgFunction;
import cn.quantgroup.xyqb.model.session.SessionStruct;
import cn.quantgroup.xyqb.model.session.SessionValue;
import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.session.XyqbSessionContextHolder;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -52,4 +52,7 @@ public class XyqbSessionContextHolder {
}
}
public static void releaseSession() {
threadSession.remove();
}
}
......@@ -12,8 +12,10 @@ import java.util.regex.Pattern;
public class ValidationUtil {
private static String regExp = "^((13[0-9])|(14[0-9])|(15[0-9])|(17[37680])|(18[0-9]))\\d{8}$";
private static String chineseExp = "^[\u4e00-\u9fa5]+(\\.|·)?[\u4e00-\u9fa5]+$";
private static Pattern pattern = Pattern.compile(regExp);
private static Pattern phonePattern = Pattern.compile(regExp);
private static Pattern chinesePattern = Pattern.compile(chineseExp);
public static boolean validatePhoneNo(String phoneNo) {
......@@ -23,11 +25,19 @@ public class ValidationUtil {
return false;
}
Matcher matcher = pattern.matcher(phoneNo);
Matcher matcher = phonePattern.matcher(phoneNo);
return matcher.find();
}
public static boolean validateChinese(String chinese) {
if (StringUtils.isEmpty(chinese)) {
return false;
}
Matcher matcher = chinesePattern.matcher(chinese);
return matcher.find();
}
public static boolean validateChannelId(Long channelId) {
return channelId == 0L ? false : true;
}
......
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