Search in sources :

Example 11 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class UserLoginService method doLogin.

private TokenInfo doLogin(ShiroUsernamePasswordToken token, HttpServletRequest request) {
    Subject subject = SecurityUtils.getSubject();
    try {
        subject.login(token);
        Session session = subject.getSession(false);
        session.setAttribute(Constant.USER_ID, UserUtil.getUserId());
        session.setAttribute(Constant.USERNAME, UserUtil.getUsername());
        this.onSuccess(request);
        return new TokenInfo(session.getId().toString());
    } catch (AccountException e) {
        throw new BusinessException(11, e.getMessage());
    } catch (AuthenticationException e1) {
        if (LoginTypeEnum.PHONE.equals(token.getLoginType())) {
            throw new BusinessException(12, "验证码不正确");
        } else {
            throw new BusinessException(11, "账号或密码不正确");
        }
    }
}
Also used : BusinessException(top.longmarch.lmcore.exception.BusinessException) AccountException(org.apache.shiro.authc.AccountException) AuthenticationException(org.apache.shiro.authc.AuthenticationException) TokenInfo(top.longmarch.lmcore.shiro.api.bean.TokenInfo) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session)

Example 12 with BusinessException

use of top.longmarch.lmcore.exception.BusinessException in project longmarch by yuyueqty.

the class ActiveUserServiceImpl method findPasswordByPhone.

@Override
public String findPasswordByPhone(String phone, String code) {
    MsgUtil.checkVerificationCode(phone, code);
    String newPassword = RandomUtil.randomString(6);
    SysUser sysUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getPhone, phone));
    if (sysUser == null) {
        throw new BusinessException(5000, "账号不存在");
    }
    if (StatusEnum.no(sysUser.getStatus())) {
        throw new BusinessException(5000, "账号已被禁用,请联系管理员");
    }
    updateUserPassword(sysUser.getId(), newPassword);
    messageResultInfoService.sendPhoneLoginPassword(newPassword, phone);
    return newPassword;
}
Also used : BusinessException(top.longmarch.lmcore.exception.BusinessException) SysUser(top.longmarch.lmsys.entity.SysUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

BusinessException (top.longmarch.lmcore.exception.BusinessException)12 SysTableBody (top.longmarch.lmsys.entity.SysTableBody)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 SysTableTitle (top.longmarch.lmsys.entity.SysTableTitle)3 SysUser (top.longmarch.lmsys.entity.SysUser)3 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 CacheUtil (top.longmarch.lmcore.cache.CacheUtil)2 AppApiInfo (top.longmarch.sign.entity.AppApiInfo)2 AppProduct (top.longmarch.sign.entity.AppProduct)2 AppProductApi (top.longmarch.sign.entity.AppProductApi)2 ExcelExportUtil (cn.afterturn.easypoi.excel.ExcelExportUtil)1 ExportParams (cn.afterturn.easypoi.excel.entity.ExportParams)1 ExcelType (cn.afterturn.easypoi.excel.entity.enmus.ExcelType)1 ExcelExportEntity (cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity)1 CollectionUtil (cn.hutool.core.collection.CollectionUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 MD5 (cn.hutool.crypto.digest.MD5)1 JSONArray (cn.hutool.json.JSONArray)1