Commit c1cd8817 authored by libin's avatar libin

applet登录注册

parent 992d784b
...@@ -166,4 +166,40 @@ public class AuthController { ...@@ -166,4 +166,40 @@ public class AuthController {
} }
/**
* 根据用户id登录 Unbelievable ! ! !
* @param userId
* @return
* @throws Exception
*/
@PostMapping(value = "/applet/uid/login")
public JSONObject appletLoginByUserId(@RequestParam("userId") Integer userId) throws Exception{
JSONObject data = appAuthService.appletLoginByUserId(userId);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data");
if(result==null){
data.put("status",1001);
}else {
String token=appAuthService.getToken(String.valueOf(data.get("username")),data.getInteger("userId"));
data.put("token",token);
}
}
return data;
}
@PostMapping(value = "/applet/registry")
public JSONObject registryWithApplet(@RequestParam("phone") String phone,@RequestParam("pwd") String pwd,@RequestParam("code") String code)throws Exception {
JSONObject data=appAuthService.appletRegistry(phone,pwd,code);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data");
if(result==null){
data.put("status",1001);
}else {
String token=appAuthService.getToken(String.valueOf(data.get("username")),data.getInteger("userId"));
data.put("token",token);
}
}
return data;
}
} }
...@@ -6,10 +6,7 @@ import com.github.wxiaoqi.security.api.vo.user.UserInfo; ...@@ -6,10 +6,7 @@ import com.github.wxiaoqi.security.api.vo.user.UserInfo;
import com.github.wxiaoqi.security.auth.configuration.FeignConfiguration; import com.github.wxiaoqi.security.auth.configuration.FeignConfiguration;
import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest; import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/** /**
...@@ -51,4 +48,22 @@ public interface IUserService { ...@@ -51,4 +48,22 @@ public interface IUserService {
public JSONObject reset( @RequestParam(value="username")String username, public JSONObject reset( @RequestParam(value="username")String username,
@RequestParam(value="mobilecode")String mobilecode, @RequestParam(value="mobilecode")String mobilecode,
@RequestParam(value="password")String password); @RequestParam(value="password")String password);
/**
* 小程序通过用户id登录登录
* @param userid
* @return
*/
@PostMapping("/api/app/applet/uid/login")
JSONObject appletLogin(@RequestParam(value = "userid") Integer userid);
/**
* 小程序注册
* @param phone
* @param pwd
* @param code
* @return
*/
@PostMapping("/api/app/applet/registry")
JSONObject appletRegistry(@RequestParam(value = "phone") String phone,@RequestParam("pwd") String pwd,@RequestParam("code") String code);
} }
...@@ -3,6 +3,7 @@ package com.github.wxiaoqi.security.auth.service; ...@@ -3,6 +3,7 @@ package com.github.wxiaoqi.security.auth.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest; import com.github.wxiaoqi.security.auth.util.user.JwtAuthenticationRequest;
import org.springframework.web.bind.annotation.RequestParam;
public interface AuthService { public interface AuthService {
String login(JwtAuthenticationRequest authenticationRequest) throws Exception; String login(JwtAuthenticationRequest authenticationRequest) throws Exception;
...@@ -16,4 +17,20 @@ public interface AuthService { ...@@ -16,4 +17,20 @@ public interface AuthService {
JSONObject tlogin(String username, String password,String mobilecode,Integer type) throws Exception; JSONObject tlogin(String username, String password,String mobilecode,Integer type) throws Exception;
String getToken(String username,Integer id) throws Exception; String getToken(String username,Integer id) throws Exception;
JSONObject reset(String username, String mobilecode, String password) throws Exception; JSONObject reset(String username, String mobilecode, String password) throws Exception;
/**
* 使用用户id登录 Unbelievable ! ! !
* @param userid
* @return
*/
JSONObject appletLoginByUserId(Integer userid);
/**
* 通过小程序注册
* @param phone
* @param pwd
* @param code
* @return
*/
JSONObject appletRegistry(String phone,String pwd,String code);
} }
...@@ -86,4 +86,14 @@ public class AppAuthServiceImpl implements AuthService { ...@@ -86,4 +86,14 @@ public class AppAuthServiceImpl implements AuthService {
return userService.reset(username,mobilecode,password); return userService.reset(username,mobilecode,password);
} }
@Override
public JSONObject appletLoginByUserId(Integer userid) {
return userService.appletLogin(userid);
}
@Override
public JSONObject appletRegistry(String phone, String pwd, String code) {
return userService.appletRegistry(phone,pwd,code);
}
} }
...@@ -83,4 +83,9 @@ public class AuthServiceImpl implements AuthService { ...@@ -83,4 +83,9 @@ public class AuthServiceImpl implements AuthService {
public JSONObject reset(String username, String mobilecode, String password) throws Exception { public JSONObject reset(String username, String mobilecode, String password) throws Exception {
return userService.reset(username,mobilecode,password); return userService.reset(username,mobilecode,password);
} }
@Override
public JSONObject loginWithUserId(Integer userid) {
return userService.login(userid);
}
} }
...@@ -100,7 +100,7 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> { ...@@ -100,7 +100,7 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
public AppUserLogin checkeUserLogin(String username) { public AppUserLogin checkeUserLogin(String username) {
Example example = new Example(AppUserLogin.class); Example example = new Example(AppUserLogin.class);
example.createCriteria().andEqualTo("username", username).andEqualTo("isdel", 0); example.createCriteria().andEqualTo("username", username).andEqualTo("isdel", 0).andEqualTo("status",0);
List<AppUserLogin> userLoginList = mapper.selectByExample(example); List<AppUserLogin> userLoginList = mapper.selectByExample(example);
if (userLoginList != null && userLoginList.size() != 0) { if (userLoginList != null && userLoginList.size() != 0) {
return userLoginList.get(0); return userLoginList.get(0);
...@@ -149,6 +149,4 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> { ...@@ -149,6 +149,4 @@ public class AppUserLoginBiz extends BaseBiz<AppUserLoginMapper, AppUserLogin> {
public AppUserLogin getUserById(Integer userId){ public AppUserLogin getUserById(Integer userId){
return mapper.selectByPrimaryKey(userId); return mapper.selectByPrimaryKey(userId);
} }
} }
...@@ -171,5 +171,22 @@ public class AppUserRest { ...@@ -171,5 +171,22 @@ public class AppUserRest {
return appPermissionService.upAuthentication(userId,name,idNumber,status); return appPermissionService.upAuthentication(userId,name,idNumber,status);
} }
/**
* 通过用户id登录 unbelievable! ! !
* @param userid
* @return
*/
@PostMapping("/applet/uid/login")
public JSONObject appletLogin(@RequestParam(value = "userid") Integer userid){
return appPermissionService.appletLoginByUserId(userid);
}
@PostMapping("/applet/registry")
public JSONObject appletRegistry(@RequestParam(value = "phone") String phone,@RequestParam("pwd") String pwd,@RequestParam("code") String code){
//默认昵称
String nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000);
return appPermissionService.appletRegistry(phone,nickname,pwd,code);
}
} }
...@@ -283,7 +283,7 @@ public class AppPermissionService { ...@@ -283,7 +283,7 @@ public class AppPermissionService {
//userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS); //userRedisTemplate.opsForValue().set("imtoken_" + userid,imtoken_,SystemConfig.REDISTOKENTIME, TimeUnit.SECONDS);
// 返回结果 // 返回结果
// data.put("token", token); // data.put("token", token);
data.put("username", username); data.put("username", StringUtils.isNotEmpty(username)?username:userLoign.getUsername());
data.put("userId", userid); data.put("userId", userid);
} }
...@@ -657,4 +657,24 @@ public class AppPermissionService { ...@@ -657,4 +657,24 @@ public class AppPermissionService {
} }
/**
* 通过用户id登录*** Unbelievable! ! !
* @param uid
* @return
*/
public JSONObject appletLoginByUserId(Integer uid) {
return autoLogin(uid,null,null,null);
}
/**
*通过小程序注册
* @param phone
* @param pwd
* @param code
* @return
*/
public JSONObject appletRegistry(String phone,String nickname, String pwd,String code){
return register(phone,pwd,null,nickname,code,null,null,null);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment