| | |
| | | package com.qxueyou.scc.sys.action; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.Cookie; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.qxueyou.scc.base.util.*; |
| | | import com.qxueyou.scc.wx.service.IWechatService; |
| | | import freemarker.template.utility.StringUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.kafka.common.network.LoginType; |
| | | import org.apache.tomcat.util.net.openssl.ciphers.Authentication; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.util.DigestUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import com.qxueyou.scc.admin.teacher.service.ITeacherService; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | /** |
| | | * 注册controller 提供注册,登录,注销服务 |
| | | * 注册controller 提供注册,录,注销服务 |
| | | * |
| | | * @author 德虎 |
| | | * @history 2014-11-25 新建 夏德虎 |
| | | * @author 德虎 |
| | | * @history 2014-11-25 新建 夏德虎 |
| | | */ |
| | | @Api(tags="登入相关接口") |
| | | @Api(tags="入相关接口") |
| | | @Controller |
| | | @CrossOrigin(origins="*",maxAge=3600) |
| | | @EnableConfigurationProperties(SccConfig.class) |
| | |
| | | @Autowired |
| | | IStudentService studentService; |
| | | |
| | | @Resource |
| | | RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | private IOrganizationService organizationService; |
| | | |
| | | public static String UUNUMBER="QXYUUNUMBER"; |
| | | /** |
| | | * 小程序appID |
| | | */ |
| | | @Value("${wx.appId}") |
| | | private String appId; |
| | | |
| | | @ApiOperation(value = "登入接口", notes = "") |
| | | |
| | | /** |
| | | * 小程序secret |
| | | */ |
| | | @Value("${wx.secret}") |
| | | private String secret; |
| | | |
| | | /** |
| | | * 公众号appID |
| | | */ |
| | | @Value("${wx.app.appId}") |
| | | private String wxappId; |
| | | |
| | | |
| | | /** |
| | | * 公众号secret |
| | | */ |
| | | @Value("${wx.app.secret}") |
| | | private String wxsecret; |
| | | |
| | | public static String UUNUMBER="QXYUUNUMBER"; |
| | | |
| | | @Autowired |
| | | IWechatService wechatService; |
| | | |
| | | /** |
| | | * 微信录 |
| | | * |
| | | * @param uid |
| | | * @throws IOException |
| | | */ |
| | | |
| | | @PostMapping("/wxAccountsLogin") |
| | | @ApiOperation("微信公众号录") |
| | | @ResponseBody |
| | | public Result wxAccountsLogin(String code) { |
| | | JSONObject gettoken = wechatService.gettoken(wxappId, wxsecret); |
| | | JSONObject OpenId = wechatService.getSessionKeyOrOpenId(code); |
| | | JSONObject user = wechatService.getUser(gettoken.get("access_token").toString(), OpenId.get("openid").toString()); |
| | | return new Result(true,"成功",user); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/wxlogin") |
| | | @ApiOperation("微信小程序录") |
| | | @ResponseBody |
| | | public Result wechatLogin(String code,String number) { |
| | | JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code); |
| | | JSONObject gettoken = wechatService.gettoken(appId, secret); |
| | | Result phone = wechatService.getNumber(gettoken.get("access_token").toString(), number); |
| | | if(phone.getSuccess()){ |
| | | String hql = "from User where deleteFlag is false and mobilePhone = ? "; |
| | | System.out.println(phone.getData()); |
| | | List<Object> params = CollectionUtils.newList(phone.getData()); |
| | | User user = commonDAO.findUnique(hql,params, User.class); |
| | | if(user==null){ |
| | | //新增用户 |
| | | User user1=new User(); |
| | | user1.setMobilePhone(phone.getData().toString()); |
| | | user1.setOpenId(sessionKeyOrOpenId.get("openid").toString()); |
| | | commonDAO.save(user1); |
| | | //新增关联学员 |
| | | String addUserSql = "from User where deleteFlag is false and mobilePhone = ? "; |
| | | List<Object> newParams = CollectionUtils.newList(phone.getData()); |
| | | User newUser = commonDAO.findUnique(addUserSql,newParams, User.class); |
| | | StuStudent stuStudent=new StuStudent(); |
| | | stuStudent.setStatus(StuStudent.STATUS_REGISTER); |
| | | stuStudent.setUserId(newUser.getUserId()); |
| | | stuStudent.setMobilePhone(newUser.getMobilePhone()); |
| | | commonDAO.save(stuStudent); |
| | | } |
| | | if(StringUtils.isEmpty(user.getOpenId())){ |
| | | user.setOpenId(sessionKeyOrOpenId.get("openid").toString()); |
| | | commonDAO.saveOrUpdate(user); |
| | | } |
| | | String studentSql = "from StuStudent where deleteFlag is false and userId = ? "; |
| | | List<Object> stuParams = CollectionUtils.newList(user.getUserId()); |
| | | StuStudent stuStudent = commonDAO.findUnique(studentSql, stuParams, StuStudent.class); |
| | | CacheParamters param = new CacheParamters(); |
| | | param.setUserId(user.getUserId()); |
| | | param.setCustomRoleValue(user.getEmail()); |
| | | param.setCustomOrgId(user.getImei()); |
| | | param.setCacheIpFlag(true); |
| | | // 缓存到请求线程 |
| | | UserInfoWrapper wrapper = cacheUserInfo(param, null); |
| | | // 存到redis |
| | | redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); |
| | | return new Result(true,"授权成功",CollectionUtils.newObjectMap("user",user,"ClassId",stuStudent.getClassId())); |
| | | } |
| | | return phone; |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "入接口", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value = "beforeLogin", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public Result beforeLogin(@RequestParam("account") String account, @RequestParam("password") String password, |
| | | HttpServletRequest request, HttpServletResponse response) { |
| | | if(StringUtils.isEmpty(account)||StringUtils.isEmpty(password)) { |
| | | return new Result(false, "用户账号密码不能为空"); |
| | | return new Result(false, "用户账号密码不能为空"); |
| | | } |
| | | // 查询用户信息 |
| | | // 查询用户信息 |
| | | String uuNumber=null; |
| | | String uuReNumber=null; |
| | | String hql = "from User where deleteFlag is false and account = ? and password = ? "; |
| | | String hql = "from User where deleteFlag is false and account = ? and password= ?"; |
| | | List<Object> params = CollectionUtils.newList(account,password); |
| | | User user = commonDAO.findUnique(hql,params, User.class); |
| | | if (user == null ) { |
| | | return new Result(false, "用户账户、密码错误"); |
| | | return new Result(false, "用户账户、密码错误"); |
| | | } |
| | | if (user.getSource() == null || "".equals(user.getSource())) { |
| | | return new Result(false, "没有权限"); |
| | | return new Result(false, "没有权限"); |
| | | } |
| | | if("exam".equals(user.getSource())){ |
| | | // //获取Session存入uuNumber |
| | | // //获取Session存入uuNumber |
| | | // uuNumber = UUIDUtils.generateSpecialUuid(8)+account; |
| | | // HttpSession session = request.getSession(); |
| | | // //设置session自动过期时间 60分钟 |
| | | // //设置session自动过期时间 60分钟 |
| | | // session.setMaxInactiveInterval(60*60); |
| | | // session.setAttribute("uuNumber", uuNumber); |
| | | //uuNumber使用固定 |
| | | //uuNumber使用固定 |
| | | uuNumber=UUNUMBER; |
| | | }else if("reExam".equals(user.getSource())){ |
| | | //获取Session存入uuNumber |
| | | //获取Session存入uuNumber |
| | | uuReNumber = UUIDUtils.generateSpecialUuid(8)+account; |
| | | HttpSession session = request.getSession(); |
| | | //设置session自动过期时间 60分钟 |
| | | //设置session自动过期时间 60分钟 |
| | | session.setMaxInactiveInterval(60*60); |
| | | session.setAttribute("uuReNumber", uuReNumber); |
| | | }else { |
| | | return new Result(false, "没有权限"); |
| | | return new Result(false, "没有权限"); |
| | | } |
| | | // 插入日志 |
| | | // 插入日志 |
| | | insertLoginLog(request, user, account, "SYS-LOGIN"); |
| | | // 返回 |
| | | return new Result(true, "验证成功",CollectionUtils.newObjectMap("uuNumber",uuNumber,"uuReNumber",uuReNumber)); |
| | | String salt = user.getSalt(); |
| | | String newPassword= DigestUtils.md5DigestAsHex((salt+password).getBytes()); |
| | | //比较用户输入的密码加密后的字符串是否跟注册时填写的加密密码相同 |
| | | if (!newPassword.equals(user.getPassword())) { |
| | | return new Result(false, "用户账户、密码错误或缺少凭证"); |
| | | } |
| | | // 返回 |
| | | return new Result(true, "验证成功",CollectionUtils.newObjectMap("uuNumber",uuNumber,"uuReNumber",uuReNumber)); |
| | | } |
| | | |
| | | @ApiOperation(value = "登入接口", notes = "") |
| | | @ApiOperation(value = "入接口", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "uuNumber", value = "uuNumber", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "uuReNumber", value = "uuReNumber", required = true, paramType="query", dataType = "String"), |
| | |
| | | public Result examLogin(String uuNumber,String uuReNumber, |
| | | HttpServletRequest request, HttpServletResponse response) { |
| | | if(StringUtils.isEmpty(uuNumber)&&StringUtils.isEmpty(uuReNumber)){ |
| | | return new Result(false, "验证失败"); |
| | | return new Result(false, "验证失败"); |
| | | } |
| | | if (StringUtils.isNotEmpty(uuNumber)) { |
| | | //有uunumber |
| | | //有uunumber |
| | | String uu=ClientUtils.getUserInfo().getInfo("email"); |
| | | if(StringUtils.isEmpty(uu)||!uuNumber.equals(uu)){ |
| | | return new Result(false, "uuNumber验证失败"); |
| | | return new Result(false, "uuNumber验证失败"); |
| | | } |
| | | } else { |
| | | //有uurenumber |
| | | //有uurenumber |
| | | HttpSession session = request.getSession(); |
| | | String uu=(String) session.getAttribute("uuReNumber"); |
| | | if(StringUtils.isEmpty(uu)||!uuReNumber.equals(uu)){ |
| | | return new Result(false, "uuReNumber验证失败"); |
| | | return new Result(false, "uuReNumber验证失败"); |
| | | } |
| | | //验证后删除 |
| | | //验证后删除 |
| | | request.getSession().removeAttribute("uuReNumber"); |
| | | // String uu=ClientUtils.getUserInfo().getInfo("email"); |
| | | // if(StringUtils.isEmpty(uu)||!uuReNumber.equals(uu)){ |
| | | // return new Result(false, "uuReNumber验证失败"); |
| | | // return new Result(false, "uuReNumber验证失败"); |
| | | // } |
| | | } |
| | | // 返回 |
| | | return new Result(true, "验证成功"); |
| | | // 返回 |
| | | return new Result(true, "验证成功"); |
| | | } |
| | | |
| | | @ApiOperation(value = "登入接口", notes = "") |
| | | @ApiOperation(value = "入接口", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "uuNumber", value = "uuNumber", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "uuReNumber", value = "uuReNumber", required = true, paramType="query", dataType = "String"), |
| | |
| | | @ResponseBody |
| | | public Result examssLogin(String uuNumber,String uuReNumber, |
| | | HttpServletRequest request, HttpServletResponse response) { |
| | | //两个都为空,表示没有参数 |
| | | //两个都为空,表示没有参数 |
| | | if(StringUtils.isEmpty(uuNumber)&&StringUtils.isEmpty(uuReNumber)){ |
| | | return new Result(false, "验证失败"); |
| | | return new Result(false, "验证失败"); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(uuNumber)) { |
| | | //有uunumber |
| | | //有uunumber |
| | | // HttpSession session = request.getSession(); |
| | | // String uu=(String) session.getAttribute("uuNumber"); |
| | | String uu=UUNUMBER; |
| | | if(StringUtils.isEmpty(uu)||!uuNumber.equals(uu)){ |
| | | return new Result(false, "uuNumber验证失败"); |
| | | return new Result(false, "uuNumber验证失败"); |
| | | } |
| | | } else { |
| | | //有uurenumber |
| | | //有uurenumber |
| | | HttpSession session = request.getSession(); |
| | | String uu=(String) session.getAttribute("uuReNumber"); |
| | | if(StringUtils.isEmpty(uu)||!uuReNumber.equals(uu)){ |
| | | return new Result(false, "uuReNumber验证失败"); |
| | | return new Result(false, "uuReNumber验证失败"); |
| | | } |
| | | } |
| | | // 返回 |
| | | return new Result(true, "验证成功"); |
| | | // 返回 |
| | | return new Result(true, "验证成功"); |
| | | } |
| | | |
| | | //退出登录 清除session |
| | | @RequestMapping(value = "khdloginout", method = RequestMethod.POST) |
| | | //退出录 清除session |
| | | @RequestMapping(value = "release", method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public void khdloginout(HttpServletRequest request, HttpServletResponse response) { |
| | | System.out.println("清除session"); |
| | | HttpSession session = request.getSession(); |
| | | System.out.println(session.getAttribute("userId")); |
| | | System.out.println(session.getAttribute("classId")); |
| | | session.invalidate(); |
| | | public void release(HttpServletRequest request, HttpServletResponse response) { |
| | | // System.out.println("清除session"); |
| | | // HttpSession session = request.getSession(); |
| | | // redisTemplate.delete(UserInfoWrapper.SESSION_USER_INFO_KEY); |
| | | // System.out.println(session.getAttribute("userId")); |
| | | // System.out.println(session.getAttribute("classId")); |
| | | doRelease(request, response); |
| | | // session.invalidate(); |
| | | } |
| | | |
| | | /** |
| | | * 学员端登录 |
| | | * 学员端录 |
| | | * |
| | | * @param account 账户 |
| | | * @param password 密码 |
| | | * @param account 账户 |
| | | * @param password 密码 |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "登入接口", notes = "") |
| | | @ApiOperation(value = "入接口", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "organizationId", value = "机构id", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "platForm", value = "登入平台(app,web,qLive,pc,weixin)", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "logType", value = "登入type(study学员,teacher教师,否则为后台)", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "organizationId", value = "机构id", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "platForm", value = "入平台(app,web,qLive,pc,weixin)", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "logType", value = "入type(study学员,teacher教师,否则为后台)", required = true, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value = "studentLogin", method = RequestMethod.POST) |
| | | @ResponseBody |
| | |
| | | List<Object> params = null; |
| | | hql = "from User where deleteFlag is false and userId = ?"; |
| | | params = CollectionUtils.newList(userId); |
| | | // 查询用户信息 |
| | | // 查询用户信息 |
| | | User user = commonDAO.findUnique(hql,params, User.class); |
| | | CacheParamters param = new CacheParamters(); |
| | | param.setUserId(user.getUserId()); |
| | |
| | | param.setCacheIpFlag(true); |
| | | param.setPlatForm(StringUtils.isEmpty(platForm) ? Constants.LOGIN_PLATFORM_WEB : platForm); |
| | | param.setIp(RequestClientUtils.getRemoteIP(request)); |
| | | // 缓存到请求线程 |
| | | // 缓存到请求线程 |
| | | UserInfoWrapper wrapper = cacheUserInfo(param, null); |
| | | // 存到redis |
| | | redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); |
| | | request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); |
| | | |
| | | return new Result(true, "success", |
| | | CollectionUtils.newObjectMap("userId", user.getUserId(), "userName", user.getName(), "imgPath", |
| | | user.getImgPath(), "orgName", ClientUtils.getOrgName(),"orgId", ClientUtils.getOrgId(), "orgLogo", |
| | |
| | | } |
| | | |
| | | /** |
| | | * 后台登录 |
| | | * 后台录 |
| | | * |
| | | * @param account 账户 |
| | | * @param password 密码 |
| | | * @param account 账户 |
| | | * @param password 密码 |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "登入接口", notes = "") |
| | | @ApiOperation(value = "入接口", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "organizationId", value = "机构id", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "platForm", value = "登入平台(app,web,qLive,pc,weixin)", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "logType", value = "登入type(study学员,teacher教师,否则为后台)", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "account", value = "账号", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "organizationId", value = "机构id", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "platForm", value = "入平台(app,web,qLive,pc,weixin)", required = true, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "logType", value = "入type(study学员,teacher教师,否则为后台)", required = true, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value = "platformLogin", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public Result platformLogin(@RequestParam("account") String account, @RequestParam("password") String password,String uuNumber,String uuReNumber, |
| | | HttpServletRequest request, HttpServletResponse response, String logType,String organizationId, String platForm) { |
| | | // response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | if(StringUtils.isEmpty(account)) { |
| | | return new Result(false, "用户账号不能为空"); |
| | | } |
| | | if (StringUtils.isEmpty(account)) { |
| | | return new Result(false, "用户账号不能为空"); |
| | | } |
| | | // System.out.println(account+password); |
| | | // System.out.println("-------------------------"+organizationId+"--------------"+platForm+"-----------"+logType); |
| | | String hql = null; |
| | | List<Object> params = null; |
| | | String hql = null; |
| | | List<Object> params = null; |
| | | // boolean flag=true; |
| | | if("study".equals(logType)){ |
| | | hql = "from User where deleteFlag is false and account = ? and password = ? "; |
| | | params = CollectionUtils.newList(account,password); |
| | | }else{ |
| | | if ("study".equals(logType)) { |
| | | hql = "from User where deleteFlag is false and account = ?"; |
| | | params = CollectionUtils.newList(account); |
| | | }else if("portal".equals(logType)){ |
| | | hql = "from User where deleteFlag is false and email = ?"; |
| | | params = CollectionUtils.newList(account); |
| | | }else if("zhyly".equals(logType)){ |
| | | hql = "from User where deleteFlag is false and mobilePhone = ?"; |
| | | params = CollectionUtils.newList(account); |
| | | }else{ |
| | | if(StringUtils.isEmpty(password)) { |
| | | return new Result(false, "用户密码不能为空"); |
| | | return new Result(false, "用户密码不能为空"); |
| | | } |
| | | hql = "from User where deleteFlag is false and account = ? and password = ? "; |
| | | params = CollectionUtils.newList(account,password); |
| | | hql = "from User where deleteFlag is false and account = ?"; |
| | | params = CollectionUtils.newList(account); |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(organizationId)){ |
| | |
| | | params.add(organizationId); |
| | | } |
| | | |
| | | // 查询用户信息 |
| | | User user = commonDAO.findUnique(hql,params, User.class); |
| | | // 查询用户信息 |
| | | User user = commonDAO.findUnique(hql,params, User .class); |
| | | |
| | | if(uuNumber!=null&&!"".equals(uuNumber)&&!"null".equals(uuNumber)){ |
| | | //登录成功存入user里,删除session里的uuNumber,下个人无法使用 |
| | | //录成功存入user里,删除session里的uuNumber,下个人无法使用 |
| | | user.setEmail(uuNumber); |
| | | // request.getSession().removeAttribute("uuNumber"); |
| | | } |
| | | // if(uuReNumber!=null&&!"".equals(uuReNumber)&&!"null".equals(uuReNumber)){ |
| | | // //登录成功存入user里,删除session里的uuReNumber,下个人无法使用 |
| | | // //录成功存入user里,删除session里的uuReNumber,下个人无法使用 |
| | | // user.setImei(uuReNumber); |
| | | // request.getSession().removeAttribute("uuReNumber"); |
| | | // } |
| | | |
| | | // 插入日志 |
| | | if (user == null) { |
| | | return new Result(false, "用户账户不存在"); |
| | | } |
| | | // 插入日志 |
| | | insertLoginLog(request, user, account, "SYS-LOGIN"); |
| | | String salt = user.getSalt(); |
| | | String newPassword= DigestUtils.md5DigestAsHex((salt+password).getBytes()); |
| | | //比较用户输入的密码加密后的字符串是否跟注册时填写的加密密码相同 |
| | | if("study".equals(logType) || "portal".equals(logType) || "adminis".equals(logType)){ |
| | | if (!newPassword.equals(user.getPassword())) { |
| | | return new Result(false, "密码错误"); |
| | | } |
| | | } |
| | | |
| | | //考试登录会控制flag变量 其他登录不会 默认true |
| | | if (user == null) { |
| | | return new Result(false, "用户账户、密码错误或缺少凭证"); |
| | | } |
| | | |
| | | // 返回用户基本信息 |
| | | // 返回用户基本信息 |
| | | return this.loginValidate(user, 1, request, response, logType, platForm, organizationId); |
| | | } |
| | | |
| | | /** |
| | | * 登入验证 |
| | | * 入验证 |
| | | * @param user |
| | | * @param type |
| | | * @param request |
| | |
| | | private Result loginValidate(User user, int type, HttpServletRequest request, HttpServletResponse response, |
| | | String logType, String platForm, String organizationId) { |
| | | HttpSession session = request.getSession(); |
| | | // 缓存用户信息 |
| | | // 缓存用户信息 |
| | | CacheParamters param = new CacheParamters(); |
| | | param.setUserId(user.getUserId()); |
| | | param.setCustomRoleValue(user.getEmail()); |
| | |
| | | param.setCacheIpFlag(true); |
| | | param.setPlatForm(StringUtils.isEmpty(platForm) ? Constants.LOGIN_PLATFORM_WEB : platForm); |
| | | param.setIp(RequestClientUtils.getRemoteIP(request)); |
| | | // 缓存到请求线程 |
| | | // 缓存到请求线程 |
| | | UserInfoWrapper wrapper = cacheUserInfo(param, null); |
| | | // 存到redis |
| | | redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); |
| | | request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); |
| | | if ("study".equals(logType)) { |
| | | if ("study".equals(logType) || "portal".equals(logType) || "zhyly".equals(logType)) { |
| | | /*if (StringUtils.isEmpty(ClientUtils.getClassId()) && user.getRoles() == null) { |
| | | return new Result(false, "该用户未加入任何班级或未激活,请联系班主任"); |
| | | return new Result(false, "该用户未加入任何班级或未激活,请联系班主任"); |
| | | }*/ |
| | | |
| | | if (StringUtils.isEmpty(user.getOrganizationId())) { |
| | | return new Result(false, "该用户不属于任何机构,无法登入"); |
| | | return new Result(false, "该用户不属于任何机构,无法入"); |
| | | } |
| | | if (StringUtils.isNoneBlank(organizationId) && !user.getOrganizationId().equals(organizationId)) { |
| | | return new Result(false, "选择的机构错误,请确认"); |
| | | return new Result(false, "选择的机构错误,请确认"); |
| | | } |
| | | |
| | | //判断是否为学生,如果是学生,判断是否已冻结或移除,冻结或移除的学生不让登录 |
| | | //判断是否为学生,如果是学生,判断是否已冻结或移除,冻结或移除的学生不让录 |
| | | StuStudent stu = this.studentService.getStudentByUserId(user.getUserId()); |
| | | if(stu!=null && (stu.getDeleteFlag() || stu.getStatus().equalsIgnoreCase(StuStudent.STATUS_DEACTIVE))){ |
| | | return new Result(false, "用户账户已经被冻结或移除"); |
| | | return new Result(false, "用户账户已经被冻结或移除"); |
| | | } |
| | | |
| | | /*if(StringUtils.isEmpty(wrapper.getInfo(UserInfoWrapper.INF_CLASS_ID))) { |
| | | return new Result(false, "该用户未加入任何班级,无法登入"); |
| | | return new Result(false, "该用户未加入任何班级,无法入"); |
| | | }*/ |
| | | // 保存到session中 |
| | | // 保存到session中 |
| | | return new Result(true, "success", |
| | | CollectionUtils.newObjectMap("userId", user.getUserId(), "userName", user.getName(), "imgPath", |
| | | user.getImgPath(), "orgName", ClientUtils.getOrgName(),"orgId", ClientUtils.getOrgId(), "orgLogo", |
| | |
| | | }else if("teacher".equals(logType)) { |
| | | String teacherId = teacherService.getTeacherIdByUserId(user.getUserId()); |
| | | if (StringUtils.isEmpty(teacherId)) { |
| | | return new Result(false, "该账户不是老师角色,无法登入"); |
| | | return new Result(false, "该账户不是老师角色,无法入"); |
| | | } |
| | | if (StringUtils.isEmpty(user.getOrganizationId())) { |
| | | return new Result(false, "该用户不属于任何机构,无法登入"); |
| | | return new Result(false, "该用户不属于任何机构,无法入"); |
| | | } |
| | | if (StringUtils.isNoneBlank(organizationId) && !user.getOrganizationId().equals(organizationId)) { |
| | | return new Result(false, "选择的机构错误,请确认"); |
| | | return new Result(false, "选择的机构错误,请确认"); |
| | | } |
| | | |
| | | //获取用户对应的sessionId是否与保存在redis中的一致,如果不一致则跳转到登录页面 |
| | | //获取用户对应的sessionId是否与保存在redis中的一致,如果不一致则跳转到录页面 |
| | | // stringRedisTemplate.opsForHash().put(UserInfoWrapper.REDIS_USER_ONLINE_MAP_KEY, user.getUserId(), request.getSession().getId()); |
| | | return new Result(true, "success", |
| | | CollectionUtils.newObjectMap("userId", user.getUserId(), "userName", user.getName(), "imgPath", |
| | |
| | | }else { |
| | | Result result = privilegeService.getMenus(user); |
| | | Integer roleType = result.getDataT("roleType"); |
| | | // 保存管理员特殊角色信息 |
| | | |
| | | // 保存管理员特殊角色信息 |
| | | if (UserRole.ROLE_TYPE_ADMIN.equals(roleType)) { |
| | | // boolean a=true; |
| | | // wrapper.setAdmin(true); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 后台:退出登录,后台系统 |
| | | * |
| | | * @param account 账户 |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "退出后台系统操作", notes = "") |
| | | @RequestMapping(value = "release", method = RequestMethod.GET) |
| | | public String release(HttpServletRequest httpRequest, HttpServletResponse response) { |
| | | doRelease(httpRequest, response); |
| | | return "redirect:/web/admin/index.html#login"; |
| | | } |
| | | * 后台:退出录,后台系统 |
| | | // * |
| | | // * @param account 账户 |
| | | // * @return |
| | | // */ |
| | | // @ApiOperation(value = "退出后台系统操作", notes = "") |
| | | // @RequestMapping(value = "release", method = RequestMethod.GET) |
| | | // public String release(HttpServletRequest httpRequest, HttpServletResponse response) { |
| | | // doRelease(httpRequest, response); |
| | | // return "redirect:/web/admin/index.html#login"; |
| | | // } |
| | | |
| | | /** |
| | | * 后台:退出登录,后台系统 |
| | | * 后台:退出录,后台系统 |
| | | * |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "退出app系统操作", notes = "") |
| | | @ApiOperation(value = "退出app系统操作", notes = "") |
| | | @RequestMapping(value = "loginOut", method = RequestMethod.GET) |
| | | public @ResponseBody Result loginOut(HttpServletRequest httpRequest, HttpServletResponse response) { |
| | | doRelease(httpRequest, response); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 缓存用户信息(班主任 、 学员 角色 缓存后台clientUtils信息) |
| | | * 缓存用户信息(班主任 、 学员 角色 缓存后台clientUtils信息) |
| | | * |
| | | * @param userId |
| | | * @param cookieValue |
| | |
| | | } |
| | | |
| | | /** |
| | | * 插入登录日志 |
| | | * 插入录日志 |
| | | * |
| | | * @param request |
| | | * @param lstUser |
| | |
| | | } |
| | | |
| | | /** |
| | | * 退出后台系统操作 |
| | | * 退出后台系统操作 |
| | | * |
| | | * @param account 账户 |
| | | * @param account 账户 |
| | | * @return |
| | | */ |
| | | private void doRelease(HttpServletRequest httpRequest, HttpServletResponse response) { |
| | | HttpSession se = httpRequest.getSession(); |
| | | se.removeAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY); |
| | | redisTemplate.delete(UserInfoWrapper.SESSION_USER_INFO_KEY); |
| | | se.invalidate(); |
| | | } |
| | | |
| | | /** |
| | | * 用户修改密码 |
| | | * 用户修改密码 |
| | | */ |
| | | @ApiOperation(value = "修改密码", notes = "") |
| | | @ApiOperation(value = "修改密码", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "usedPass", value = "老密码", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "pass", value = "新密码", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "usedPass", value = "老密码", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "pass", value = "新密码", required = false, paramType=" query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value = "updatePassword", method = RequestMethod.POST) |
| | | @ResponseBody |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取当前用户 |
| | | * 获取当前用户 |
| | | */ |
| | | @ApiOperation(value = "获取当前用户", notes = "") |
| | | @ApiOperation(value = "获取当前用户", notes = "") |
| | | @RequestMapping(value = "getCurrUser", method = RequestMethod.POST) |
| | | @ResponseBody |
| | | public Result getCurrUser() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取当前用户 |
| | | * 获取当前用户 |
| | | */ |
| | | @ApiOperation(value = "获取当前教师信息", notes = "") |
| | | @ApiOperation(value = "获取当前教师信息", notes = "") |
| | | @RequestMapping(value = "getCurrTeacher", method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public Result getCurrTeacher() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 用户修改密码 |
| | | * 用户修改密码 |
| | | */ |
| | | @ApiOperation(value = "修改头像", notes = "") |
| | | @ApiOperation(value = "修改头像", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "headPath", value = "头像地址", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "headPath", value = "头像地址", required = false, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value = "updateUserHead", method = RequestMethod.POST) |
| | | @ResponseBody |
| | |
| | | } |
| | | |
| | | /** |
| | | * 修改用户其他数据 |
| | | * 修改用户其他数据 |
| | | */ |
| | | @ApiOperation(value = "修改用户其他数据", notes = "") |
| | | @ApiOperation(value = "修改用户其他数据", notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "mobilePhone", value = "老密码", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "mobilePhone", value = "老密码", required = false, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value = "updateUserInfo", method = RequestMethod.POST) |
| | | @ResponseBody |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取系统当前时间 |
| | | * 获取系统当前时间 |
| | | */ |
| | | @RequestMapping(value = "currentTime", method = RequestMethod.GET) |
| | | @ResponseBody |
| | |
| | | return System.currentTimeMillis(); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取机构列表", notes = "") |
| | | @ApiOperation(value = "获取机构列表", notes = "") |
| | | @RequestMapping(value = "getOrgLst", method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public Result getOrgLst() { |
| | |
| | | return new Result(true, "success", orgLst); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取机构的信息", notes = "包含基本信息和banner图和app信息") |
| | | @ApiOperation(value = "获取机构的信息", notes = "包含基本信息和banner图和app信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "appCode", value = "appcode(android:androidTeacherApp,androidTeacherH5,androidStudentApp, androidStudentH5" |
| | | + "IOS:IosTeacherApp,IosStudentApp)", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "orgId", value = "机构id", required = false, paramType="query", dataType = "String") |
| | | @ApiImplicitParam(name = "appCode", value = "appcode(android:androidTeacherApp,androidTeacherH5,androidStudentApp, androidStudentH5" |
| | | + "IOS:IosTeacherApp,IosStudentApp)", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "orgId", value = "机构id", required = false, paramType="query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "getOrgInfo", method = RequestMethod.GET) |
| | | @ResponseBody |
| | |
| | | } |
| | | |
| | | /** |
| | | * APP2.0: 获取android APP版本 |
| | | * APP2.0: 获取android APP版本 |
| | | * |
| | | * @return| |
| | | */ |
| | | @ApiOperation(value = "获取android APP版本") |
| | | @ApiOperation(value = "获取android APP版本") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "appName", value = "app名称(android:teacherApp,teacherH5,studentApp, studentH5)", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "appName", value = "app名称(android:teacherApp,teacherH5,studentApp, studentH5)", required = false, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value="getAndroidAppVersion",method=RequestMethod.GET) |
| | | public @ResponseBody Result getAppVersion(String appName) { |
| | | |
| | | // 版本号 |
| | | // 版本号 |
| | | String versionName = ""; |
| | | String versionTips = ""; |
| | | String versionCode = ""; |
| | |
| | | |
| | | |
| | | /** |
| | | * APP2.0: 获取ios APP版本 |
| | | * APP2.0: 获取ios APP版本 |
| | | * |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "获取ios APP版本") |
| | | @ApiOperation(value = "获取ios APP版本") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "appName", value = "app名称(ios:teacherApp,studentApp)", required = false, paramType="query", dataType = "String"), |
| | | @ApiImplicitParam(name = "appName", value = "app名称(ios:teacherApp,studentApp)", required = false, paramType="query", dataType = "String"), |
| | | }) |
| | | @RequestMapping(value="getIosAppVersion",method=RequestMethod.GET) |
| | | public @ResponseBody Result getIOSAppVersion(String appName) { |
| | | // 版本号 |
| | | // 版本号 |
| | | String versionCode = ""; |
| | | String versionNo = ""; |
| | | String versionTips = ""; |
| | |
| | | } |
| | | |
| | | /** |
| | | * APP2.0: 获取ios 版本 |
| | | * APP2.0: 获取ios 版本 |
| | | * |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "获取ios菜单") |
| | | @ApiOperation(value = "获取ios菜单") |
| | | @RequestMapping(value="getIosMenu",method=RequestMethod.GET) |
| | | public @ResponseBody Result getIOSAppVersion() { |
| | | //"课件","考试","作业","直播" |
| | | return new Result(true, "", new String[]{"课件","直播","考试","作业"}); |
| | | //"课件","考试","作业","直播" |
| | | return new Result(true, "", new String[]{"课件","直播","考试","作业"}); |
| | | } |
| | | |
| | | |