Commit 07c037e3 by 唐功亮

【新增】 登录接口

parent 7220d44d
......@@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.Map;
import io.office.modules.app.annotation.Login;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -34,7 +33,13 @@ public class LogLoginController {
@Autowired
private LogLoginService logLoginService;
@RequestMapping("/api/test")
@Login
// @RequiresPermissions("manage:member:list")
public String test() throws Exception {
DES des = new DES();
return des.encrypt("t1476171348");
}
/**
* 用户登录
......@@ -43,8 +48,7 @@ public class LogLoginController {
@Login
// @RequiresPermissions("manage:member:list")
public R login(@RequestBody Map<String, Object> params, HttpServletRequest request, HttpServletResponse response){
logLoginService.login(params,request,response);
return R.ok();
return R.ok().put("loginInfo",logLoginService.login(params,request,response));
}
/**
......
......@@ -8,6 +8,15 @@ import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.io.*;
import java.security.SecureRandom;
import java.util.Scanner;
/**
* ${comments}
*
......@@ -24,6 +33,14 @@ public interface MemberDao extends BaseMapper<MemberEntity> {
@Update("UPDATE member SET pass = #{passWord} WHERE id = #{id}")
void updateByIdPassWord(@Param("id") Integer id,@Param("passWord") String passWord);
@Select("select b.code_agen as code_agen from member a left join MemAgent b on a.username=b.user_id where a.username=#{userName}")
Integer selectCode_agen(@Param("userName") String userName);
@Select("INSERT INTO useraccess (UserName,GroupId,rights) values (#{userName},1,'100,')")
void insertUserAccess(@Param("userName")String userName);
/*@Select("select * from member where username=#{userName} or firmcode=#{userName}")
MemberEntity selectByNameAndSn(@Param("userName") String userName);*/
}
package io.office.modules.manage.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import io.office.common.utils.PageUtils;
import io.office.modules.manage.entity.LogLoginEntity;
......@@ -19,6 +20,6 @@ public interface LogLoginService extends IService<LogLoginEntity> {
PageUtils queryPage(Map<String, Object> params);
void login(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response);
JSONObject login(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response);
}
package io.office.modules.manage.service.impl;
import com.alibaba.fastjson.JSONObject;
import io.office.common.exception.RRException;
import io.office.common.utils.IPUtils;
import io.office.modules.manage.dao.MemberDao;
......@@ -48,38 +49,71 @@ public class LogLoginServiceImpl extends ServiceImpl<LogLoginDao, LogLoginEntity
@Override
public void login(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
public JSONObject login(Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
String userName = String.valueOf(params.get("userName")==null?"":params.get("userName"));
String passWord = String.valueOf(params.get("passWord")==null?"":params.get("passWord"));
String verification = String.valueOf(params.get("verification")==null?"":params.get("verification"));//验证码
//session中获取验证码
//判断 验证码是否正确
int userType; //用户类型 1.业务大厅(手机号用户) 2.业务大厅(条码卡成员) 3.官网用户
Integer levels = null; //用户权限 空.代表普通用户 0.代表中心管理员,1.代表校验管理员 其他4位.代表分中心管理员
Integer isQY=2; //是否开通企业认证 1.开通 2.未开通
Integer isXT=2; //是否是业务大厅系统成员 1.是 2.否
//判断用户是否是手机号 是手机号调用 第三方接口登录 不是继续
int userType; //1.业务大厅 2.网站用户
if (matchPhoneNumber(userName)){
//TODO tgl 调用第三方登录接口
userType=1;
}else {
userType=2;
//查询Member表
MemberEntity memberEntity = memberDao.selectByName(userName);
if (memberEntity==null){
throw new RRException("用户不存在!");
}
//用户类型 www:为官网用户 条码卡:为条码卡用户
String source = memberEntity.getSource();
String applystate = memberEntity.getApplystate();// 未申请:普通用户 通过审核:完成厂商实名认证
if (!"条码卡".equals(source)){//官网用户
userType=3;
}else {//条码卡用户
userType=2;
}
}
//获取权限
levels=memberDao.selectCode_agen(userName);
if (levels==null){
if (userType==3){
//判断是否通过企业认证
if ("通过审核".equals(applystate)){
isQY=1;
}
//判断是否是系统成员
}else if (userType==2){
isXT=1;
}
}
MemberEntity user=memberDao.selectByName(userName);
if (user==null){
throw new RRException("用户不存在!");
}
String phone = user.getPhone();
String password = user.getPass();
String passwordMD5 = MD5Util.md5Encrypt32Upper(passWord);
//判断密码是否正确
if (!passwordMD5.equals(password)){
throw new RRException("密码不正确!");
}
//TODO tgl 参数不正确添加登录日志 log_login
logLoginDao.insert(new LogLoginEntity(1,userName,"用户来源","条码卡号",phone,new Date(), IPUtils.getIpAddr(request),request.getRequestURL().toString()));
MemberEntity user=memberDao.selectByName(userName);
String phone = user.getPhone();
String password = user.getPass();
String passwordMD5 = MD5Util.md5Encrypt32Upper(passWord);
//判断密码是否正确
if (!passwordMD5.equals(password)){
throw new RRException("密码不正确!");
}
//TODO tgl 参数不正确添加登录日志 log_login
logLoginDao.insert(new LogLoginEntity(1,userName,"用户来源","条码卡号",phone,new Date(), IPUtils.getIpAddr(request),request.getRequestURL().toString()));
JSONObject jsonObject = new JSONObject();
jsonObject.put("userType",userType);
jsonObject.put("levels",levels);
jsonObject.put("isQY",isQY);
jsonObject.put("isXT",isXT);
return jsonObject;
}
/**
......
......@@ -19,12 +19,14 @@ import io.office.common.utils.Query;
import io.office.modules.manage.dao.MemberDao;
import io.office.modules.manage.entity.MemberEntity;
import io.office.modules.manage.service.MemberService;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Service("memberService")
@Transactional
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {
@Autowired
......@@ -101,6 +103,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
memberEntity.setOicq("");
memberEntity.setRegisterip(IPUtils.getIpAddr(request));
memberDao.insert(memberEntity);
memberDao.insertUserAccess(userName);
}
/**
......
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