修改密码失败,一直提示token失效或错误
来源:6-9 用户模块所有功能自测试
黑色天空8655
2018-12-31
[20:20:46.809][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-8] Creating a new SqlSession
[20:20:46.820][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-8] SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1058389a] was not registered for synchronization because synchronization is not active
[20:20:47.126][DEBUG][o.m.s.t.SpringManagedTransaction][http-bio-8088-exec-8] JDBC Connection [jdbc:mysql://localhost:3306/mmall_learning?characterEncoding=utf-8, UserName=root@localhost, MySQL-AB JDBC Driver] will not be managed by Spring
[20:20:47.130][DEBUG][com.mmall.dao.UserMapper.checkUsername][http-bio-8088-exec-8] ==> Preparing: select count(1) from mmall_user where username = ?
[20:20:47.148][DEBUG][com.mmall.dao.UserMapper.checkUsername][http-bio-8088-exec-8] > Parameters: geely(String)
[20:20:47.159][DEBUG][com.mmall.dao.UserMapper.checkUsername][http-bio-8088-exec-8] < Total: 1
[20:20:47.161][DEBUG][org.mybatis.spring.SqlSessionUtils][http-bio-8088-exec-8] Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1058389a]
检查了很多遍,实在找不出问题在哪里了。。。
4回答
-
同学,你好,我是geely老师的助教。
请你提供修改密码的代码,方便我尽快定位问题。
10 -
慕后端6535789
2019-08-17
这个问题解决了吗,怎么解决的
00 -
黑色天空8655
提问者
2018-12-31
public class TokenCache { private static Logger logger = LoggerFactory.getLogger(TokenCache.class); public static final String TOKEN_PREFIX = "token_"; private static LoadingCache<String,String> localCache = CacheBuilder.newBuilder().initialCapacity(1000).maximumSize(10000).expireAfterAccess(12, TimeUnit.HOURS) .build(new CacheLoader<String, String>() { @Override public String load(String s) throws Exception { return "null"; } }); public static void setKey(String key,String value){ localCache.put(key, value); } public static String getKey(String key){ String value = null; try{ value = localCache.get(key); if("null".equals(value)){ return null; } return value; }catch (Exception e){ logger.error("localCache get error",e); } return null; } }
麻烦您了
00 -
黑色天空8655
提问者
2018-12-31
public ServerResponse<String> checkAnswer(String username,String question,String answer){ int resultCount = userMapper.checkAnswer(username, question, answer); if(resultCount>0){ String forgetToken = UUID.randomUUID().toString(); TokenCache.setKey(TokenCache.TOKEN_PREFIX+username,forgetToken); return ServerResponse.createBySuccess(forgetToken); } return ServerResponse.createByErrorMessage("问题的答案错误"); } public ServerResponse<String> forgetResetPassword(String username,String passwordNew,String forgetToken){ if(StringUtils.isBlank(forgetToken)){ return ServerResponse.createByErrorMessage("参数错误,token需要传递"); } ServerResponse validResponse = this.checkValid(username,Const.USERNAME); if(validResponse.isSuccess()){ //用户不存在 return ServerResponse.createByErrorMessage("用户不存在"); } String token = TokenCache.getKey(TokenCache.TOKEN_PREFIX+username); if(StringUtils.isBlank(token)){ return ServerResponse.createByErrorMessage("token无效或过期"); } if(StringUtils.equals(forgetToken,token)){ String md5Password = MD5Util.MD5EncodeUtf8(passwordNew); int rowCount = userMapper.updatePasswordByUsername(username,md5Password); if(rowCount>0){ return ServerResponse.createBySuccessMessage("密码修改成功"); } }else{ return ServerResponse.createByErrorMessage("token错误,请重新获取修改密码的token"); } return ServerResponse.createByErrorMessage("修改密码失败"); }
052019-08-17
相似问题