Skip to content

Commit

Permalink
用户注册服务。暴露接口
Browse files Browse the repository at this point in the history
  • Loading branch information
smn322 committed Dec 15, 2019
1 parent 812ae03 commit dc3fca3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package com.smn.it.taotaomall.sso.controller;

import com.alibaba.fastjson.JSONObject;
import com.smn.it.taotaomall.sso.entity.common.UserInfoVO;
import com.smn.it.taotaomall.sso.service.LogServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LogController {

@Autowired
private LogServices logServices;
@PostMapping("/log")
public JSONObject log(@RequestBody UserInfoVO userInfoVO){
return logServices.login(userInfoVO);
}
}
4 changes: 2 additions & 2 deletions sso/src/main/java/com/smn/it/taotaomall/sso/dao/LogDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@Repository
@Mapper
public interface LogDao {
@Select("SELECT count(1) as count FROM public.\"TT_userinfo_t\" where user_account = #{userAccount} and passowrd=#{password}")
int login(UserInfoVO userInfoVO);
@Select("SELECT \"UID\" as uid FROM public.\"TT_userinfo_t\" where user_account = #{userAccount} and passowrd=#{password}")
String login(UserInfoVO userInfoVO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSONObject;
import com.smn.it.taotaomall.sso.config.redis.RedisConfig;
import com.smn.it.taotaomall.sso.dao.LogDao;
import com.smn.it.taotaomall.sso.entity.common.UserInfoVO;
import com.smn.it.taotaomall.sso.service.LogServices;
import com.smn.it.taotaomall.sso.util.ResultBeanUtils;
import com.smn.it.taotaomall.sso.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Service(interfaceClass = LogServices.class)
Expand All @@ -17,12 +18,24 @@ public class LogServicesImpl implements LogServices {
@Autowired
private LogDao logDao;

@Autowired
private RedisConfig redisConfig;
@Override
public JSONObject login(UserInfoVO userInfoVO) {
if(logDao.login(userInfoVO) == 1)
String uid = null;
if((uid=logDao.login(userInfoVO))!= null)
{

return ResultBeanUtils.buildDefaultSuccessResult();
String token = TokenUtils.getToken(userInfoVO.getUserAccount());
boolean absent = redisConfig.putTokenIfAbsent(token, uid, TokenUtils.DEAFAULT_TOKEN_EXPIRED_TIME);
if(absent)
{
JSONObject data = new JSONObject();
data.put("token",token);
data.put("uid",uid);
JSONObject result = ResultBeanUtils.buildDefaultSuccessResult();
result.put("data", data);
return result;
}
}
return ResultBeanUtils.buildDefaultFailedResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public class TokenUtils {
private static final String TOKEN_PREFIX="token_";

public static final long DEAFAULT_TOKEN_EXPIRED_TIME=300000;

public static String getToken(String userAccount){
return TOKEN_PREFIX+userAccount;
}
Expand Down

0 comments on commit dc3fca3

Please sign in to comment.