| | |
| | | package com.nq.controller; |
| | | |
| | | import cn.hutool.extra.qrcode.QrCodeUtil; |
| | | import cn.hutool.extra.qrcode.QrConfig; |
| | | import com.google.common.collect.Maps; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.pojo.SiteAdminIndex; |
| | | import com.nq.pojo.SiteSpread; |
| | | import com.nq.dao.SiteAdminMapper; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.service.impl.GoogleAuthenticator; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.redis.CookieUtils; |
| | | import com.nq.utils.redis.JsonUtil; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.validation.Valid; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | 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.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | @Controller |
| | | @RequestMapping({"/api/admin/"}) |
| | |
| | | |
| | | @Autowired |
| | | ISiteAdminService iSiteAdminService; |
| | | |
| | | @Autowired |
| | | SiteAdminMapper siteAdminMapper; |
| | | |
| | | @Autowired |
| | | ISiteSettingService iSiteSettingService; |
| | |
| | | //管理系统登录 |
| | | @RequestMapping({"login.do"}) |
| | | @ResponseBody |
| | | public ServerResponse login(@RequestParam("adminPhone") String adminPhone, @RequestParam("adminPwd") String adminPwd, @RequestParam("verifyCode") String verifyCode, HttpSession httpSession, HttpServletRequest request, HttpServletResponse response) { |
| | | ServerResponse serverResponse = this.iSiteAdminService.login(adminPhone, adminPwd, verifyCode, request); |
| | | public ServerResponse login(@RequestParam("adminPhone") String adminPhone, |
| | | @RequestParam("adminPwd") String adminPwd, |
| | | @RequestParam("verifyCode") String verifyCode, |
| | | @RequestParam(value = "googleAuthCode", required = false) Integer googleAuthCode, |
| | | HttpSession httpSession, HttpServletRequest request, |
| | | HttpServletResponse response) { |
| | | ServerResponse serverResponse = this.iSiteAdminService.login(adminPhone, adminPwd, verifyCode, googleAuthCode,request); |
| | | |
| | | return serverResponse; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取当前登录用户 |
| | | * @return |
| | | */ |
| | | @GetMapping("getAdmin") |
| | | @ResponseBody |
| | | public ServerResponse getAdmin(HttpServletRequest request) { |
| | | String cookie_name = PropertiesUtil.getProperty("admin.cookie.name"); |
| | | SiteAdmin siteAdmin = null; |
| | | if(StringUtils.isNotEmpty(cookie_name)){ |
| | | String logintoken = CookieUtils.readLoginToken(request, cookie_name); |
| | | String adminJson = RedisShardedPoolUtils.get(logintoken); |
| | | siteAdmin = (SiteAdmin) JsonUtil.string2Obj(adminJson, SiteAdmin.class); |
| | | siteAdmin = siteAdminMapper.selectById(siteAdmin.getId()); |
| | | } |
| | | return ServerResponse.createBySuccess(siteAdmin); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取谷歌验证码密钥 |
| | | * @return |
| | | */ |
| | | @GetMapping("getLoginGoogleAuthSecret") |
| | | @ResponseBody |
| | | public ServerResponse getLoginGoogleAuthSecret(HttpServletRequest request) { |
| | | GoogleAuthDto dto = iSiteAdminService.getGoogleAuth(request); |
| | | return ServerResponse.createBySuccess(dto); |
| | | } |
| | | |
| | | /** |
| | | * 绑定谷歌验证码 |
| | | */ |
| | | @PostMapping("bindGoogleAuth") |
| | | @ResponseBody |
| | | public ServerResponse updateGoogleAuth(@RequestParam("id") String id, |
| | | @RequestParam("googleAuthCode") String googleAuthCode, |
| | | @RequestParam("secret") String secret) { |
| | | SiteAdmin siteAdmin = siteAdminMapper.selectById(id); |
| | | if (siteAdmin == null) { |
| | | return ServerResponse.createByErrorMsg("当前用户未找到"); |
| | | } |
| | | long t = System.currentTimeMillis(); |
| | | GoogleAuthenticator ga = new GoogleAuthenticator(); |
| | | ga.setWindowSize(5); |
| | | if (siteAdmin.getGoogleAuthBind()) { |
| | | return ServerResponse.createByErrorMsg("谷歌验证码已绑定"); |
| | | } |
| | | boolean userFlag = ga.check_code(secret, Long.valueOf(googleAuthCode), t); |
| | | if (!userFlag) { |
| | | return ServerResponse.createByErrorMsg("谷歌验证码错误"); |
| | | } |
| | | siteAdmin.setGoogleAuthBind(true); |
| | | siteAdmin.setGoogleAuthSecret(secret); |
| | | siteAdminMapper.updateById(siteAdmin); |
| | | return ServerResponse.createBySuccess(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 解绑谷歌验证码 |
| | | * @param param |
| | | * @return |
| | | */ |
| | | @PostMapping("/unbindingGoogleAuth") |
| | | @ResponseBody |
| | | public ServerResponse unbindingGoogleAuth(@RequestParam("id") String id, |
| | | @RequestParam("rootGoogleAuthCode") String rootGoogleAuthCode) { |
| | | SiteAdmin siteAdmin = siteAdminMapper.selectById(id); |
| | | if (siteAdmin == null) { |
| | | return ServerResponse.createByErrorMsg("当前用户未找到"); |
| | | } |
| | | long t = System.currentTimeMillis(); |
| | | GoogleAuthenticator ga = new GoogleAuthenticator(); |
| | | ga.setWindowSize(5); |
| | | boolean flag = ga.check_code(siteAdmin.getGoogleAuthSecret(), Long.valueOf(rootGoogleAuthCode), t); |
| | | if (flag) { |
| | | if (!siteAdmin.getGoogleAuthBind()) { |
| | | return ServerResponse.createByErrorMsg("谷歌验证码未绑定,无需解绑!"); |
| | | |
| | | } |
| | | siteAdmin.setGoogleAuthBind(false); |
| | | siteAdmin.setGoogleAuthSecret(""); |
| | | siteAdminMapper.updateById(siteAdmin); |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("超级谷歌验证码错误"); |
| | | } |
| | | return ServerResponse.createBySuccess(); |
| | | } |
| | | |
| | | |
| | | |
| | | // //页面样式设置 |