1. 快速登录
2. 解绑设备
This commit is contained in:
parent
b2cfaf1e0c
commit
82e881ce1b
|
@ -132,10 +132,23 @@ public class SysLoginController
|
|||
* 微信登录
|
||||
*/
|
||||
@PostMapping("/wxlogin")
|
||||
public AjaxResult wxlogin(String mobileCode) {
|
||||
public AjaxResult wxlogin(String mobileCode,String openid) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.wxloing(mobileCode);
|
||||
String token = loginService.wxloing(mobileCode,openid);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据openid静默登录
|
||||
*/
|
||||
@PostMapping("/loginByopenid")
|
||||
public AjaxResult loginByopenid(String openid) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 生成令牌
|
||||
String token = loginService.loginByopenid(openid);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
return ajax;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,17 @@ public class AsUser extends BaseEntity
|
|||
/** 展示当前设备id */
|
||||
private Long deviceId;
|
||||
|
||||
/** 微信openid */
|
||||
private String wxopenid;
|
||||
|
||||
public String getWxopenid() {
|
||||
return wxopenid;
|
||||
}
|
||||
|
||||
public void setWxopenid(String wxopenid) {
|
||||
this.wxopenid = wxopenid;
|
||||
}
|
||||
|
||||
|
||||
public AsUser()
|
||||
{
|
||||
|
|
|
@ -113,7 +113,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|||
// 过滤请求
|
||||
.authorizeRequests()
|
||||
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
||||
.antMatchers("/login","/wxlogin", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**","/common/upload").permitAll()
|
||||
.antMatchers("/login","/wxlogin", "/register", "/captchaImage","/common/receive","/appCaptcha","/appCodeLogin","/app/**","/common/upload","/loginByopenid").permitAll()
|
||||
// 静态资源,可匿名访问
|
||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
|
||||
|
|
|
@ -259,7 +259,7 @@ public class SysLoginService
|
|||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
public String wxloing(String mobileCode) {
|
||||
public String wxloing(String mobileCode,String openid) {
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
||||
String phoneNumber = null;
|
||||
AsUser user = null;
|
||||
|
@ -286,6 +286,7 @@ public class SysLoginService
|
|||
asUser.setPhonenumber(phoneNumber);
|
||||
asUser.setLoginIp(IpUtils.getIpAddr());
|
||||
asUser.setLoginDate(DateUtils.getNowDate());
|
||||
asUser.setWxopenid(openid);
|
||||
asUser.setCreateTime(DateUtils.getNowDate());
|
||||
int i = asUserService.insertUser(asUser);
|
||||
user = asUser;
|
||||
|
@ -314,5 +315,37 @@ public class SysLoginService
|
|||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据openid静默登录
|
||||
*/
|
||||
public String loginByopenid(String openid) {
|
||||
AsUser user = asUserService.selectUserByWxopenid(openid);
|
||||
if(ObjectUtils.isEmpty(user)){
|
||||
throw new ServiceException("未查询到用户信息");
|
||||
}
|
||||
Authentication authentication = null; // 用户验证
|
||||
try {
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName(), Constants.CUSTOM_LOGIN_WX);
|
||||
// 用户名和密码等信息保存在一个上下文中,只要是同一线程等会就能拿到用户名和密码,也就是能在loadUserByUsername(String username)方法中进行密码验证等
|
||||
AuthenticationContextHolder.setContext(authenticationToken);
|
||||
// 把用户类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取
|
||||
authenticationToken.setDetails(Constants.USER_TYPE_APP);
|
||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||
authentication = authenticationManager.authenticate(authenticationToken);
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof BadCredentialsException) {
|
||||
throw new UserPasswordNotMatchException(); //抛出账号或者密码错误的异常
|
||||
} else {
|
||||
throw new ServiceException(e.getMessage()); //抛出其他异常
|
||||
}
|
||||
} finally {
|
||||
AuthenticationContextHolder.clearContext();
|
||||
}
|
||||
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
||||
recordAppLoginInfo(loginUser.getUserId());
|
||||
return tokenService.createToken(loginUser);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -157,15 +157,16 @@ public class AppController extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 删除设备列表 逻辑删除
|
||||
* 解绑设备
|
||||
*/
|
||||
@Log(title = "删除设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/device/{deviceId}")
|
||||
public AjaxResult remove(@PathVariable Long deviceId)
|
||||
@Log(title = "解绑设备", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/device/unbind/{deviceId}")
|
||||
public AjaxResult unbind(@PathVariable Long deviceId)
|
||||
{
|
||||
AsDevice device = new AsDevice();
|
||||
device.setDeviceId(deviceId);
|
||||
device.setStatus("1");
|
||||
device.setUserId(0L);
|
||||
device.setIsNetwork("0");
|
||||
return toAjax(asDeviceService.logicallyDelete(device));
|
||||
}
|
||||
|
||||
|
|
|
@ -133,4 +133,6 @@ public interface AsUserMapper
|
|||
* @return 用户对象信息
|
||||
*/
|
||||
public AsUser selectUserByPhone(String phone);
|
||||
|
||||
AsUser selectUserByWxopenid(String openid);
|
||||
}
|
||||
|
|
|
@ -188,4 +188,12 @@ public interface IAsUserService
|
|||
* 计算下次定时时间
|
||||
*/
|
||||
public void setNextDs(AsDevice asDevice1, DatapointValue.nextDs next_ds);
|
||||
|
||||
/**
|
||||
* 通过openid查询用户
|
||||
*
|
||||
* @param openid
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
AsUser selectUserByWxopenid(String openid);
|
||||
}
|
||||
|
|
|
@ -123,7 +123,15 @@ public class AsModelServiceImpl extends ServiceImpl<AsModelMapper, AsModel> impl
|
|||
AsDeviceClassify deviceClassify = classifyMapper.selectAsDeviceClassifyByClassifyId(asModel.getClassifyId());
|
||||
String classifyName = deviceClassify.getClassifyName();
|
||||
asModel.setClassifyName(classifyName);
|
||||
return asModelMapper.updateAsModel(asModel);
|
||||
int i = asModelMapper.updateAsModel(asModel);
|
||||
AsDevice device = new AsDevice();
|
||||
device.setModelId(asModel.getModelId());
|
||||
List<AsDevice> asDevices = deviceMapper.selectAsDeviceList(device);
|
||||
for(AsDevice device1: asDevices){
|
||||
device1.setModel(asModel.getModel());
|
||||
deviceMapper.updateAsDevice(device1);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -418,6 +418,17 @@ public class AsUserServiceImpl implements IAsUserService
|
|||
return asUserMapper.selectUserByPhone(phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过openid查询用户
|
||||
*
|
||||
* @param openid 手机号
|
||||
* @return 用户对象信息
|
||||
*/
|
||||
@Override
|
||||
public AsUser selectUserByWxopenid(String openid) {
|
||||
return asUserMapper.selectUserByWxopenid(openid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据登录用户获取绑定设备
|
||||
* 根据登录用户获取是否有绑定设备,没有则显示添加设备页面,如果有则从列表中取一条记录展示
|
||||
|
|
|
@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="onlineStatus != null and onlineStatus != ''"> and online_status = #{onlineStatus}</if>
|
||||
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="deviceId != null "> and device_id != #{deviceId}</if>
|
||||
<if test="modelId != null "> and model_id = #{modelId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
@ -70,7 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="isBandByMac" resultType="java.lang.Integer">
|
||||
select count(1) from as_device
|
||||
where mac = #{mac} and user_id IS NOT NULL and is_network = 1
|
||||
where mac = #{mac} and user_id IS NOT NULL and is_network = 1 and user_id != 0
|
||||
</select>
|
||||
|
||||
<insert id="insertAsDevice" parameterType="AsDevice" useGeneratedKeys="true" keyProperty="deviceId">
|
||||
|
|
|
@ -105,6 +105,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where u.phonenumber = #{phonenumber}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByWxopenid" parameterType="String" resultMap="AsUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.wxopenid = #{openid}
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="AsUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into as_user(
|
||||
<if test="userId != null and userId != 0">user_id,</if>
|
||||
|
|
Loading…
Reference in New Issue
Block a user