Merge branch 'main' of https://dd3skj.picp.vip/zhengziru/zhgh_hrbnu
This commit is contained in:
@@ -13,7 +13,10 @@ import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
@@ -26,12 +29,15 @@ import java.net.URLEncoder;
|
||||
@IocBean
|
||||
public class WeChatUtils {
|
||||
|
||||
private static final String ALGORITHM = "AES";
|
||||
private static final String KEY = "4eXvXq1ZJmZj8z5z6yXvXq1ZJmZj8z5z";
|
||||
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
public static final String APPID = "wxf12fa6175ec7c75f";
|
||||
public static final String APPID = "wx0ad18b7f3c9ad6ab";
|
||||
|
||||
public static final String SECRET = "f65bbb41d3de4a93c8c93d8e2fd50369";
|
||||
public static final String SECRET = "306cd98e99b10f48cb4244da950376f8";
|
||||
|
||||
// 获取code
|
||||
public final static String CODE_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
|
||||
@@ -106,4 +112,20 @@ public class WeChatUtils {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
|
||||
public String encrypt(String data) throws Exception {
|
||||
SecretKeySpec keySpec = new SecretKeySpec(KEY.getBytes(), ALGORITHM);
|
||||
Cipher cipher = Cipher.getInstance(ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
|
||||
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
|
||||
return Base64.getEncoder().encodeToString(encryptedBytes);
|
||||
}
|
||||
|
||||
public String decrypt(String encryptedData) throws Exception {
|
||||
SecretKeySpec keySpec = new SecretKeySpec(KEY.getBytes(), ALGORITHM);
|
||||
Cipher cipher = Cipher.getInstance(ALGORITHM);
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec);
|
||||
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
|
||||
return new String(decryptedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.v.nutz.base.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.sys.models.Sys_log;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.sys.services.SysUserService;
|
||||
@@ -15,6 +16,7 @@ import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Times;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@@ -46,6 +48,19 @@ public class LoginUtil {
|
||||
* @param loginOrigin 登录起源
|
||||
*/
|
||||
public void doLogin(AuthenticationToken token, HttpServletRequest request, HttpSession session, LoginOrigin loginOrigin) {
|
||||
doLogin(token, request, session, loginOrigin, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 密码登录
|
||||
*
|
||||
* @param token 令牌
|
||||
* @param request 请求
|
||||
* @param session 会话
|
||||
* @param loginOrigin 登录起源
|
||||
*/
|
||||
public void doLogin(AuthenticationToken token, HttpServletRequest request, HttpSession session, LoginOrigin loginOrigin, String openid) {
|
||||
|
||||
//设置登录源
|
||||
PlatformCaptchaToken platformCaptchaToken = (PlatformCaptchaToken) token;
|
||||
@@ -61,6 +76,9 @@ public class LoginUtil {
|
||||
Sys_user user = (Sys_user) subject.getPrincipal();
|
||||
int count = user.getLoginCount() == null ? 0 : user.getLoginCount();
|
||||
org.nutz.dao.Chain userUpdateChain = Chain.make("loginIp", user.getLoginIp()).add("loginAt", Times.getTS()).add("loginCount", count + 1).add("userOnline", true).add("loginSessionId", session.getId());
|
||||
if (StrUtil.isNotBlank(openid)) {
|
||||
userUpdateChain.add("openId", openid).add("weAppLoginCount", user.getWeAppLoginCount() + 1);
|
||||
}
|
||||
sysUserService.update(userUpdateChain, Cnd.where("id", "=", user.getId()));
|
||||
Sys_log sysLog = new Sys_log();
|
||||
sysLog.setType("info");
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package io.v.nutz.base.utils;
|
||||
|
||||
import com.antherd.smcrypto.sm2.Sm2;
|
||||
import com.antherd.smcrypto.sm3.Sm3;
|
||||
import com.antherd.smcrypto.sm4.Sm4;
|
||||
import com.antherd.smcrypto.sm4.Sm4Options;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
/**
|
||||
* 为老兼容老的密码加密方式
|
||||
*
|
||||
* @author wizzer@qq.com
|
||||
*/
|
||||
@Slf4j
|
||||
public class PwdUtil {
|
||||
|
||||
/** 公钥 */
|
||||
private static final String PUBLIC_KEY = "04298364ec840088475eae92a591e01284d1abefcda348b47eb324bb521bb03b0b2a5bc393f6b71dabb8f15c99a0050818b56b23f31743b93df9cf8948f15ddb54";
|
||||
|
||||
/** 私钥 */
|
||||
private static final String PRIVATE_KEY = "3037723d47292171677ec8bd7dc9af696c7472bc5f251b2cec07e65fdef22e25";
|
||||
|
||||
/** SM4的对称秘钥(生产环境需要改成自己使用的) 16 进制字符串,要求为 128 比特 */
|
||||
private static final String KEY = "0123456789abcdeffedcba9876543210";
|
||||
|
||||
public static String getPassword(String passowrd, String salt) {
|
||||
byte[] bytes = hash(passowrd.getBytes(), salt.getBytes(), 1024);
|
||||
if (bytes != null) {
|
||||
return Lang.fixedHexString(bytes);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static byte[] hash(byte[] bytes, byte[] salt, int hashIterations) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
if (salt != null) {
|
||||
digest.reset();
|
||||
digest.update(salt);
|
||||
}
|
||||
|
||||
byte[] hashed = digest.digest(bytes);
|
||||
int iterations = hashIterations - 1;
|
||||
|
||||
for (int i = 0; i < iterations; ++i) {
|
||||
digest.reset();
|
||||
hashed = digest.digest(hashed);
|
||||
}
|
||||
return hashed;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密方法
|
||||
* 如果采用加密机的方法,用try catch 捕捉异常,返回原文值即可
|
||||
* @param str 密文
|
||||
* @return 解密后的明文
|
||||
*/
|
||||
public static String doSm2Decrypt(String str) {
|
||||
// 解密
|
||||
return Sm2.doDecrypt(str, PRIVATE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密方法
|
||||
* @param str 待加密数据
|
||||
* @return 加密后的密文
|
||||
*/
|
||||
public static String doSm4CbcEncrypt(String str) {
|
||||
// SM4 加密 cbc模式
|
||||
Sm4Options sm4Options4 = new Sm4Options();
|
||||
sm4Options4.setMode("cbc");
|
||||
sm4Options4.setIv("fedcba98765432100123456789abcdef");
|
||||
return Sm4.encrypt(str, KEY, sm4Options4);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密方法
|
||||
* 如果采用加密机的方法,用try catch 捕捉异常,返回原文值即可
|
||||
* @param str 密文
|
||||
* @return 解密后的明文
|
||||
*/
|
||||
public static String doSm4CbcDecrypt(String str) {
|
||||
// 解密,cbc 模式,输出 utf8 字符串
|
||||
Sm4Options sm4Options8 = new Sm4Options();
|
||||
sm4Options8.setMode("cbc");
|
||||
sm4Options8.setIv("fedcba98765432100123456789abcdef");
|
||||
String docString = Sm4.decrypt(str, KEY, sm4Options8);
|
||||
if ("".equals(docString)) {
|
||||
log.warn(">>> 字段解密失败,返回原文值:{}", str);
|
||||
return str;
|
||||
} else {
|
||||
return docString;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 纯签名
|
||||
* @param str 待签名数据
|
||||
* @return 签名结果
|
||||
*/
|
||||
public static String doSignature(String str) {
|
||||
return Sm2.doSignature(str, PRIVATE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过杂凑算法取得hash值,用于做数据完整性保护
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return hash 值
|
||||
*/
|
||||
public static String doHashValue(String str) {
|
||||
return Sm3.sm3(str);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String pwd = "123456";
|
||||
// String dbPwd = PwdUtil.doHashValue(pwd);
|
||||
// String s = PwdUtil.doHashValue(PwdUtil.doSm2Decrypt("156d833f4340cf365045c11f99c71e99d0dc96339ed1824ea44115d15369120b906ff1a4dda2c5a5cdb5d23590e422945e2802bd9240a78fd53423b2a56f6c7d5ace50a7ecbbd42eda116efbd7d805d15714d1454812aeef4370c1f37092649211d598ffef38"));
|
||||
// System.out.println(dbPwd);
|
||||
// System.out.println(s);
|
||||
|
||||
String pwd = "123456";
|
||||
String dbPwd = PwdUtil.doSm4CbcEncrypt(pwd);
|
||||
System.out.println(dbPwd);
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,40 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.socket.SocketUtil;
|
||||
import io.v.nutz.base.payment.wxpay.util.WeChatUtils;
|
||||
import io.v.nutz.base.result.Result;
|
||||
import io.v.nutz.base.utils.LoginUtil;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.sys.services.SysUserService;
|
||||
import io.v.nutz.web.commons.base.Globals;
|
||||
import io.v.nutz.web.commons.shiro.exception.CaptchaEmptyException;
|
||||
import io.v.nutz.web.commons.shiro.exception.CaptchaIncorrectException;
|
||||
import io.v.nutz.web.commons.slog.SLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.jasig.cas.client.util.AbstractCasFilter;
|
||||
import org.jasig.cas.client.validation.Assertion;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Attr;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -40,6 +46,7 @@ import java.util.Optional;
|
||||
* @author jug
|
||||
* @date 2023/07/06
|
||||
*/
|
||||
@Slf4j
|
||||
@IocBean
|
||||
@At("/platform/wechat")
|
||||
public class SysWechatController {
|
||||
@@ -49,7 +56,7 @@ public class SysWechatController {
|
||||
// 哈师大公众号appid
|
||||
private static final String APPID = "wx0ad18b7f3c9ad6ab";
|
||||
// 哈师大公众号app_secret 还未修改
|
||||
private static final String SECRET = "f65bbb41d3de4a93c8c93d8e2fd50369";
|
||||
private static final String SECRET = "306cd98e99b10f48cb4244da950376f8";
|
||||
|
||||
|
||||
@Inject
|
||||
@@ -73,7 +80,8 @@ public class SysWechatController {
|
||||
@At
|
||||
@Ok("re")
|
||||
public String oauth(@Param("redirectUrl") String redirectUrl) {
|
||||
String redirect = Globals.AppDomain + "/platform/wechat/getCode";
|
||||
// String redirect = Globals.AppDomain + "platform/wechat/getCode";
|
||||
String redirect = "http://zhgh.hrbnu.edu.cn/platform/wechat/getCode";
|
||||
if (StrUtil.isNotBlank(redirectUrl)) {
|
||||
redirect += "?redirect=" + redirectUrl;
|
||||
}
|
||||
@@ -109,11 +117,24 @@ public class SysWechatController {
|
||||
Sys_user sysUser = dao.fetch(Sys_user.class, Cnd.where("openId", "=", openid));
|
||||
|
||||
if (sysUser == null) {
|
||||
String s = Globals.AppDomain + "/platform/wechat/doLogin?openid=" + openid;
|
||||
if (StrUtil.isNotBlank(redirect)) {
|
||||
s += "&redirect=" + URLEncoder.encode(redirect, StandardCharsets.UTF_8);
|
||||
// String s = Globals.AppDomain + "/platform/wechat/doLogin?openid=" + openid;
|
||||
//// String s = "http://zhgh.hrbnu.edu.cn/sso/login?openid=" + openid;
|
||||
// if (StrUtil.isNotBlank(redirect)) {
|
||||
// s += "&redirect=" + URLEncoder.encode(redirect, StandardCharsets.UTF_8);
|
||||
// }
|
||||
// return ">>:" + Globals.CasAddress + "/login?service=" + URLEncoder.encode(s, StandardCharsets.UTF_8);
|
||||
//// return ">>:" + Globals.CasAddress + "/login;
|
||||
String encrypt = null;
|
||||
try {
|
||||
encrypt = weChatUtils.encrypt(openid);
|
||||
} catch (Exception e) {
|
||||
log.error(">>> openid 加密失败:{}", openid);
|
||||
}
|
||||
try {
|
||||
return ">>:" + Globals.AppDomain + "mobile/login?state=" + URLEncoder.encode(encrypt, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(">>> 请求转发失败:{}", openid);
|
||||
}
|
||||
return ">>:" + Globals.CasAddress + "/login?service=" + URLEncoder.encode(s, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
String loginName = Optional.ofNullable(sysUser).map(Sys_user::getLoginname).orElse(null);
|
||||
@@ -142,42 +163,32 @@ public class SysWechatController {
|
||||
|
||||
@At
|
||||
@Ok("re")
|
||||
public String doLogin(HttpSession session,
|
||||
@Param("redirect") String redirect,
|
||||
@Param("openid") String openid,
|
||||
HttpServletRequest request) {
|
||||
|
||||
Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
if (assertion == null) {
|
||||
return ">>:" + Globals.AppDomain + "/platform/home/UnknownAccountError";
|
||||
}
|
||||
|
||||
String principal = assertion.getPrincipal().toString();
|
||||
|
||||
//工号 手机号 身份证
|
||||
Sys_user user = dao.fetch(Sys_user.class, Cnd.NEW().and("loginname", "=", principal).or("mobile", "=", principal).or("idcard", "=", principal));
|
||||
String loginName = Optional.ofNullable(user).map(Sys_user::getLoginname).orElse(null);
|
||||
public Result doLogin(@Attr("platformLoginToken") AuthenticationToken token, HttpServletRequest request, HttpSession session, @Param("state") String state) {
|
||||
|
||||
System.out.println(state);
|
||||
int errCount = NumberUtils.toInt(Strings.sNull(SecurityUtils.getSubject().getSession(true).getAttribute("platformErrCount")));
|
||||
try {
|
||||
loginUtil.doLogin(loginName, request, session, LoginUtil.LoginOrigin.WEI_XIN);
|
||||
//绑定openId
|
||||
if (StrUtil.isNotBlank(openid)) {
|
||||
dao.update(Sys_user.class, Chain.make("openId", openid), Cnd.where("loginName", "=", loginName));
|
||||
}
|
||||
if (StrUtil.isNotBlank(redirect)) {
|
||||
return ">>:" + redirect;
|
||||
}
|
||||
return ">>:" + Globals.AppDomain + "/mobile/index";
|
||||
String decrypt = weChatUtils.decrypt(state);
|
||||
loginUtil.doLogin(token, request, session, LoginUtil.LoginOrigin.WEI_XIN, decrypt);
|
||||
return Result.success("login.success");
|
||||
} catch (CaptchaIncorrectException e) {
|
||||
return Result.error(1, "login.error.captcha");
|
||||
} catch (CaptchaEmptyException e) {
|
||||
return Result.error(2, "验证码为空");
|
||||
} catch (LockedAccountException e) {
|
||||
request.setAttribute("errMsg", "帐号被锁定,请5分钟后再试");
|
||||
return ">>:" + Globals.AppDomain + "/platform/home/LockedAccountError";
|
||||
return Result.error(3, "login.error.locked");
|
||||
} catch (UnknownAccountException e) {
|
||||
request.setAttribute("errMsg", "系统中没有此用户");
|
||||
return ">>:" + Globals.AppDomain + "/platform/home/UnknownAccountError";
|
||||
errCount++;
|
||||
SecurityUtils.getSubject().getSession(true).setAttribute("platformErrCount", errCount);
|
||||
return Result.error(4, "login.error.user");
|
||||
} catch (AuthenticationException e) {
|
||||
errCount++;
|
||||
SecurityUtils.getSubject().getSession(true).setAttribute("platformErrCount", errCount);
|
||||
return Result.error(5, "login.error.user");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
request.setAttribute("errMsg", "用户名或密码错误");
|
||||
return ">>:" + Globals.AppDomain + "/platform/home/500";
|
||||
errCount++;
|
||||
SecurityUtils.getSubject().getSession(true).setAttribute("platformErrCount", errCount);
|
||||
return Result.error(6, "login.error.system");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -631,6 +631,11 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@ColDefine(type = ColType.VARCHAR, width = 300)
|
||||
private String openId;
|
||||
|
||||
@Column
|
||||
@Default("0")
|
||||
@Comment("微信端的登录次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer weAppLoginCount;
|
||||
/**
|
||||
* 2021-05-18 end
|
||||
*/
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Globals {
|
||||
//项目短名称
|
||||
public static String AppShrotName = "";
|
||||
//项目域名 (设置一个默认的 为优先级考虑)
|
||||
public static String AppDomain = "https://zhgh.hrbnu.edu.cn";
|
||||
public static String AppDomain = "http://zhgh.hrbnu.edu.cn";
|
||||
//cas地址 //http://noa.hrbnu.edu.cn/login/OAlogin.jsp#/?_key=vbuw0p
|
||||
public static String CasAddress = "http://pass.hrbnu.edu.cn/tpass";
|
||||
//文件访问域名
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package io.v.nutz.web.commons.shiro.config;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.utils.LoginUtil;
|
||||
import io.v.nutz.base.utils.PwdUtil;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.web.commons.base.Globals;
|
||||
import io.v.nutz.web.commons.shiro.token.PlatformCaptchaToken;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Slf4j
|
||||
public class EasyCredentialsMatch extends HashedCredentialsMatcher {
|
||||
|
||||
/**
|
||||
@@ -26,15 +32,29 @@ public class EasyCredentialsMatch extends HashedCredentialsMatcher {
|
||||
LoginUtil.LoginOrigin loginOrigin = platformCaptchaToken.getLoginOrigin();
|
||||
|
||||
//cas和企业微信实现免密登录
|
||||
if (loginOrigin.equals(LoginUtil.LoginOrigin.CAS) || loginOrigin.equals(LoginUtil.LoginOrigin.QI_YE_WEI_XIN)
|
||||
|| !loginOrigin.equals(LoginUtil.LoginOrigin.WEI_XIN)) {
|
||||
if (loginOrigin.equals(LoginUtil.LoginOrigin.CAS) || loginOrigin.equals(LoginUtil.LoginOrigin.QI_YE_WEI_XIN)){
|
||||
return true;
|
||||
}
|
||||
|
||||
String universalPassword = StrUtil.blankToDefault(Globals.MyConfig.getString("UniversalPassword"), "zxcvbnmqwer");
|
||||
if (loginOrigin.equals(LoginUtil.LoginOrigin.WEI_XIN)) {
|
||||
// 去校验密码
|
||||
PrincipalCollection principals = info.getPrincipals();
|
||||
Sys_user user = BeanUtil.copyProperties(principals.getPrimaryPrincipal(), Sys_user.class);
|
||||
|
||||
if (Arrays.equals(platformCaptchaToken.getPassword(), universalPassword.toCharArray())) {
|
||||
return true;
|
||||
// 登录时密码
|
||||
String password = String.valueOf(platformCaptchaToken.getPassword());
|
||||
// 用户密码
|
||||
String userPassword = PwdUtil.doSm4CbcDecrypt(user.getPassword());
|
||||
|
||||
if (password.equals(userPassword)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
String universalPassword = StrUtil.blankToDefault(Globals.MyConfig.getString("UniversalPassword"), "@dd3s#3618!");
|
||||
|
||||
if (Arrays.equals(platformCaptchaToken.getPassword(), universalPassword.toCharArray())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Object tokenHashedCredentials = hashProvidedCredentials(token, info);
|
||||
|
||||
@@ -82,6 +82,18 @@ public interface SourceData {
|
||||
}};
|
||||
|
||||
|
||||
Map<String, String> PERSON_TYPE_CODE = new HashMap<>() {{
|
||||
put("01", "管理人员");
|
||||
put("02", "专业技术人员");
|
||||
put("03", "技术工人");
|
||||
put("04", "普通工人");
|
||||
put("05", "勤工俭学");
|
||||
put("06", "大集体");
|
||||
put("07", "返聘");
|
||||
put("08", "督导");
|
||||
}};
|
||||
|
||||
|
||||
/**
|
||||
* 接口中的数据跟SourceUser的对应关系
|
||||
* <p>
|
||||
@@ -95,7 +107,7 @@ public interface SourceData {
|
||||
put("XM", new String[]{"username"});
|
||||
put("DWDM", new String[]{"unitid"});
|
||||
put("DQZTDM", new String[]{"userState"});
|
||||
put("JZGRYLB", new String[]{"personType"});
|
||||
put("JZGRYLBDM", new String[]{"personType"});
|
||||
put("SJH", new String[]{"mobile"});
|
||||
put("RXRQ", new String[]{"schoolTime"});
|
||||
put("ZZMM", new String[]{"political"});
|
||||
@@ -110,6 +122,7 @@ public interface SourceData {
|
||||
*/
|
||||
Map<String, Exp4> USER_FIELD_PLUGIN = new HashMap<>() {{
|
||||
put("DQZTDM", v -> Strings.sBlank(USER_STATE_CODE.get(v), ""));
|
||||
put("JZGRYLBDM", v -> Strings.sBlank(PERSON_TYPE_CODE.get(v), ""));
|
||||
}};
|
||||
|
||||
/**
|
||||
|
||||
@@ -144,12 +144,12 @@ public class SourceUserServiceImpl extends ViServiceImpl<UserSource> implements
|
||||
//不更新会员和福利会员字段
|
||||
source.setMember(null);
|
||||
source.setWelfareMember(null);
|
||||
if (StrUtil.isNotBlank(source.getBirthday())) {
|
||||
source.setBirthday(DateUtil.format(DateUtil.parse(source.getBirthday(), "yyyyMMdd"),"yyyy-MM-dd"));
|
||||
}
|
||||
if (StrUtil.isNotBlank(source.getSchoolTime())) {
|
||||
source.setSchoolTime(DateUtil.format(DateUtil.parse(source.getSchoolTime(), "yyyyMMdd"),"yyyy-MM-dd"));
|
||||
}
|
||||
// if (StrUtil.isNotBlank(source.getBirthday())) {
|
||||
// source.setBirthday(DateUtil.format(DateUtil.parse(source.getBirthday(), "yyyyMMdd"),"yyyy-MM-dd"));
|
||||
// }
|
||||
// if (StrUtil.isNotBlank(source.getSchoolTime())) {
|
||||
// source.setSchoolTime(DateUtil.format(DateUtil.parse(source.getSchoolTime(), "yyyyMMdd"),"yyyy-MM-dd"));
|
||||
// }
|
||||
Sys_user user = userMap.get(source.getLoginname().toLowerCase());
|
||||
|
||||
Sys_user u = new Sys_user();
|
||||
|
||||
@@ -224,7 +224,7 @@ public class ApplyController {
|
||||
dao.execute(sql);
|
||||
List<String> loginNameList = sql.getList(String.class);
|
||||
|
||||
if (Lang.isNotEmpty(loginNameList) && "999".equals(activityBx.getState_id())) {
|
||||
if (Lang.isNotEmpty(loginNameList)) {
|
||||
NutMap map = new NutMap();
|
||||
map.setv("userId",activityBx.getUser_id());
|
||||
map.setv("activityName",activityBx.getActivity_name());
|
||||
|
||||
@@ -2,16 +2,27 @@ package io.v.nutz.zhgh.mobile;
|
||||
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.base.utils.LoginUtil;
|
||||
import io.v.nutz.base.utils.PwdUtil;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.sys.services.SysUserService;
|
||||
import io.v.nutz.web.commons.shiro.exception.CaptchaEmptyException;
|
||||
import io.v.nutz.web.commons.shiro.exception.CaptchaIncorrectException;
|
||||
import io.v.nutz.web.commons.shiro.filter.PlatformAuthenticationFilter;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.session.SessionException;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
@@ -25,8 +36,12 @@ import javax.servlet.http.HttpSession;
|
||||
@Ok("json")
|
||||
public class mobileLoginController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private LoginUtil loginUtil;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* 登录页
|
||||
@@ -104,4 +119,47 @@ public class mobileLoginController {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@RequiresAuthentication
|
||||
public Object updatePwd(@Param(value = "sourcePwd", required = false) String sourcePwd,
|
||||
@Param("isFirstLogin") boolean isFirstLogin, @Param("newPwd") String newPwd) {
|
||||
Sys_user user = dao.fetch(Sys_user.class, Cnd.where("id", "=", ShiroUtil.getUserId()));
|
||||
|
||||
if (isFirstLogin) {
|
||||
sourcePwd = user.getLoginname();
|
||||
}
|
||||
|
||||
String userSourcePwd = PwdUtil.doSm4CbcDecrypt(user.getPassword());
|
||||
|
||||
if (!userSourcePwd.equals(sourcePwd)) {
|
||||
return Result.error("原密码错误");
|
||||
}
|
||||
|
||||
if (userSourcePwd.equals(newPwd)) {
|
||||
return Result.error("新密码不能与原密码相同");
|
||||
}
|
||||
|
||||
String pwd = PwdUtil.doSm4CbcEncrypt(newPwd);
|
||||
dao.update(Sys_user.class, Chain.make("password", pwd), Cnd.where("id", "=", ShiroUtil.getUserId()));
|
||||
|
||||
sysUserService.deleteCacheAndUpdate(ShiroUtil.getUserId());
|
||||
return Result.success("修改成功");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验是不是初次登录
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@RequiresAuthentication
|
||||
public Object checkIsFirstLogin(){
|
||||
Sql sql = Sqls.create("select weAppLoginCount from sys_user where id = @userId").setParam("userId", ShiroUtil.getUserId());
|
||||
sql.setCallback(Sqls.callback.integer());
|
||||
dao.execute(sql);
|
||||
int count = sql.getInt();
|
||||
return count == 0 ? Result.error() : Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user