Search in sources :

Example 1 with SysThirdAccount

use of org.jeecg.modules.system.entity.SysThirdAccount in project jeecg-boot by jeecgboot.

the class SysThirdAccountServiceImpl method saveThirdUser.

@Override
public SysThirdAccount saveThirdUser(ThirdLoginModel tlm) {
    SysThirdAccount user = new SysThirdAccount();
    user.setDelFlag(CommonConstant.DEL_FLAG_0);
    user.setStatus(1);
    user.setThirdType(tlm.getSource());
    user.setAvatar(tlm.getAvatar());
    user.setRealname(tlm.getUsername());
    user.setThirdUserUuid(tlm.getUuid());
    user.setThirdUserId(tlm.getUuid());
    super.save(user);
    return user;
}
Also used : SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount)

Example 2 with SysThirdAccount

use of org.jeecg.modules.system.entity.SysThirdAccount in project jeecg-boot by jeecgboot.

the class SysThirdAccountServiceImpl method createUser.

@Override
public SysUser createUser(String phone, String thirdUserUuid) {
    // 先查询第三方,获取登录方式
    LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
    query.eq(SysThirdAccount::getThirdUserUuid, thirdUserUuid);
    SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
    // 通过用户名查询数据库是否已存在
    SysUser userByName = sysUserMapper.getUserByName(thirdUserUuid);
    if (null != userByName) {
        // 如果账号存在的话,则自动加上一个时间戳
        String format = DateUtils.yyyymmddhhmmss.get().format(new Date());
        thirdUserUuid = thirdUserUuid + format;
    }
    // 添加用户
    SysUser user = new SysUser();
    user.setActivitiSync(CommonConstant.ACT_SYNC_0);
    user.setDelFlag(CommonConstant.DEL_FLAG_0);
    user.setStatus(1);
    user.setUsername(thirdUserUuid);
    user.setPhone(phone);
    // 设置初始密码
    String salt = oConvertUtils.randomGen(8);
    user.setSalt(salt);
    String passwordEncode = PasswordUtil.encrypt(user.getUsername(), "123456", salt);
    user.setPassword(passwordEncode);
    user.setRealname(account.getRealname());
    user.setAvatar(account.getAvatar());
    String s = this.saveThirdUser(user);
    // 更新用户第三方账户表的userId
    SysThirdAccount sysThirdAccount = new SysThirdAccount();
    sysThirdAccount.setSysUserId(s);
    sysThirdAccountMapper.update(sysThirdAccount, query);
    return user;
}
Also used : SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount) SysUser(org.jeecg.modules.system.entity.SysUser) Date(java.util.Date) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 3 with SysThirdAccount

use of org.jeecg.modules.system.entity.SysThirdAccount in project jeecg-boot by jeecgboot.

the class SysThirdAccountServiceImpl method updateThirdUserId.

@Override
public void updateThirdUserId(SysUser sysUser, String thirdUserUuid) {
    // 修改第三方登录账户表使其进行添加用户id
    LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
    query.eq(SysThirdAccount::getThirdUserUuid, thirdUserUuid);
    SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
    SysThirdAccount sysThirdAccount = new SysThirdAccount();
    sysThirdAccount.setSysUserId(sysUser.getId());
    // 根据当前用户id和登录方式查询第三方登录表
    LambdaQueryWrapper<SysThirdAccount> thirdQuery = new LambdaQueryWrapper<>();
    thirdQuery.eq(SysThirdAccount::getSysUserId, sysUser.getId());
    thirdQuery.eq(SysThirdAccount::getThirdType, account.getThirdType());
    SysThirdAccount sysThirdAccounts = sysThirdAccountMapper.selectOne(thirdQuery);
    if (sysThirdAccounts != null) {
        sysThirdAccount.setThirdUserId(sysThirdAccounts.getThirdUserId());
        sysThirdAccountMapper.deleteById(sysThirdAccounts.getId());
    }
    // 更新用户账户表sys_user_id
    sysThirdAccountMapper.update(sysThirdAccount, query);
}
Also used : SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 4 with SysThirdAccount

use of org.jeecg.modules.system.entity.SysThirdAccount in project kms by mahonelau.

the class SysThirdAccountServiceImpl method createUser.

@Override
public SysUser createUser(String phone, String thirdUserUuid) {
    // 先查询第三方,获取登录方式
    LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
    query.eq(SysThirdAccount::getThirdUserUuid, thirdUserUuid);
    SysThirdAccount account = sysThirdAccountMapper.selectOne(query);
    // 通过用户名查询数据库是否已存在
    SysUser userByName = sysUserMapper.getUserByName(thirdUserUuid);
    if (null != userByName) {
        // 如果账号存在的话,则自动加上一个时间戳
        String format = DateUtils.yyyymmddhhmmss.get().format(new Date());
        thirdUserUuid = thirdUserUuid + format;
    }
    // 添加用户
    SysUser user = new SysUser();
    user.setActivitiSync(CommonConstant.ACT_SYNC_0);
    user.setDelFlag(CommonConstant.DEL_FLAG_0);
    user.setStatus(1);
    user.setUsername(thirdUserUuid);
    user.setPhone(phone);
    // 设置初始密码
    String salt = oConvertUtils.randomGen(8);
    user.setSalt(salt);
    String passwordEncode = PasswordUtil.encrypt(user.getUsername(), "123456", salt);
    user.setPassword(passwordEncode);
    user.setRealname(account.getRealname());
    user.setAvatar(account.getAvatar());
    String s = this.saveThirdUser(user);
    // 更新用户第三方账户表的userId
    SysThirdAccount sysThirdAccount = new SysThirdAccount();
    sysThirdAccount.setSysUserId(s);
    sysThirdAccountMapper.update(sysThirdAccount, query);
    return user;
}
Also used : SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount) SysUser(org.jeecg.modules.system.entity.SysUser) Date(java.util.Date) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 5 with SysThirdAccount

use of org.jeecg.modules.system.entity.SysThirdAccount in project kms by mahonelau.

the class ThirdLoginController method getThirdLoginUser.

@SuppressWarnings("unchecked")
@RequestMapping(value = "/getLoginUser/{token}/{thirdType}", method = RequestMethod.GET)
@ResponseBody
public Result<JSONObject> getThirdLoginUser(@PathVariable("token") String token, @PathVariable("thirdType") String thirdType) throws Exception {
    Result<JSONObject> result = new Result<JSONObject>();
    String username = JwtUtil.getUsername(token);
    // 1. 校验用户是否有效
    SysUser sysUser = sysUserService.getUserByName(username);
    result = sysUserService.checkUserIsEffective(sysUser);
    if (!result.isSuccess()) {
        return result;
    }
    // update-begin-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
    LambdaQueryWrapper<SysThirdAccount> query = new LambdaQueryWrapper<>();
    query.eq(SysThirdAccount::getSysUserId, sysUser.getId());
    query.eq(SysThirdAccount::getThirdType, thirdType);
    SysThirdAccount account = sysThirdAccountService.getOne(query);
    if (oConvertUtils.isEmpty(sysUser.getRealname())) {
        sysUser.setRealname(account.getRealname());
    }
    if (oConvertUtils.isEmpty(sysUser.getAvatar())) {
        sysUser.setAvatar(account.getAvatar());
    }
    // update-end-author:wangshuai date:20201118 for:如果真实姓名和头像不存在就取第三方登录的
    JSONObject obj = new JSONObject();
    // 用户登录信息
    obj.put("userInfo", sysUser);
    // token 信息
    obj.put("token", token);
    result.setResult(obj);
    result.setSuccess(true);
    result.setCode(200);
    baseCommonService.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null);
    return result;
}
Also used : SysThirdAccount(org.jeecg.modules.system.entity.SysThirdAccount) JSONObject(com.alibaba.fastjson.JSONObject) SysUser(org.jeecg.modules.system.entity.SysUser) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

SysThirdAccount (org.jeecg.modules.system.entity.SysThirdAccount)18 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)12 SysUser (org.jeecg.modules.system.entity.SysUser)12 JSONObject (com.alibaba.fastjson.JSONObject)9 Result (org.jeecg.common.api.vo.Result)9 Date (java.util.Date)3 AuthResponse (me.zhyd.oauth.model.AuthResponse)3 AuthRequest (me.zhyd.oauth.request.AuthRequest)3 ThirdLoginModel (org.jeecg.modules.system.model.ThirdLoginModel)3