Browse Source

提交免登录

master
[yxf] 2 days ago
parent
commit
a870596705
  1. 27
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  2. 89
      im-uniapp/pages/login/login.vue

27
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -87,33 +87,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override
public LoginVO login(LoginDTO dto) {
User user = this.findUserByUserName(dto.getUserName());
if (Objects.isNull(user)) {
throw new GlobalException("用户不存在");
}
if(user.getIsCustomer() == 2){
throw new GlobalException("用户不存在");
}
if (user.getIsBanned()) {
String tip = String.format("您的账号因'%s'已被管理员封禁,请联系客服!",user.getReason());
throw new GlobalException(tip);
}
if (!passwordEncoder.matches(dto.getPassword(), user.getPassword())) {
throw new GlobalException(ResultCode.PASSWOR_ERROR);
}
if(!Objects.isNull(dto.getIp())){
user.setLastLoginIp(dto.getIp());
this.updateIpAndAddress(user);
}
// 生成token
UserSession session = BeanUtils.copyProperties(user, UserSession.class);
session.setUserId(user.getId());
session.setTerminal(dto.getTerminal());
String strJson = JSON.toJSONString(session);
String accessToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getAccessTokenExpireIn(),
jwtProperties.getAccessTokenSecret());
String refreshToken = JwtUtil.sign(user.getId(), strJson, jwtProperties.getRefreshTokenExpireIn(),
jwtProperties.getRefreshTokenSecret());
// 生成游客唯一标识UUID
String guestUuid = UUID.randomUUID().toString();

89
im-uniapp/pages/login/login.vue

@ -1,57 +1,14 @@
<template>
<view class="login">
<!-- 主要内容区域 -->
<view class="content">
<!-- Logo和标题区域 -->
<view class="header">
<view class="title">欢迎登录</view>
<view class="subtitle">登录您的账号开启聊天之旅</view>
</view>
<!-- 表单区域 -->
<view class="form-container">
<view class="form">
<view class="form-item" :class="{'focused': userNameFocused}">
<view class="icon-wrapper">
<view class="icon iconfont icon-username"></view>
</view>
<input class="input" type="text" v-model="dataForm.userName" placeholder="用户名"
@focus="userNameFocused = true" @blur="userNameFocused = false" />
</view>
<view class="form-item" :class="{'focused': passwordFocused}">
<view class="icon-wrapper">
<view class="icon iconfont icon-pwd"></view>
</view>
<input class="input" :type="isShowPwd?'text':'password'" v-model="dataForm.password"
placeholder="密码" @focus="passwordFocused = true" @blur="passwordFocused = false" />
<view class="icon-suffix iconfont" :class="isShowPwd?'icon-pwd-show':'icon-pwd-hide'"
@click="onSwitchShowPwd"></view>
</view>
</view>
<!-- 登录按钮 -->
<button class="submit-btn" @click="submit" type="primary">
<view class="btn-content">
<text class="btn-text">立即登录</text>
</view>
</button>
<!-- 底部导航 -->
<view class="nav-tool-bar">
<view class="nav-register">
<navigator url="/pages/register/register" class="register-link">
<text class="register-text">没有账号</text>
<text class="register-highlight">立即注册</text>
</navigator>
</view>
</view>
</view>
</view>
<view>
</view>
</template>
<script>
import UNI_APP from '@/.env.js';
// APP
let GLOBAL_AUTO_LOGIN_LOCK = false;
export default {
data() {
return {
@ -67,18 +24,7 @@ export default {
}
},
methods: {
async submit() {
if (!this.dataForm.userName) {
return uni.showToast({
title: "请输入您的账号",
icon: "none"
})
}
if (!this.dataForm.password) {
return uni.showToast({
title: "请输入您的密码",
icon: "none"
})
<<<<<<< HEAD
autoLogin() {
// ========================
//
@ -100,12 +46,7 @@ export default {
})
return;
}
await this.getIp();
console.log("登录参数:", this.dataForm);
this.getIp();
//
// if (!userName || !password) {
// console.log("");
@ -123,7 +64,7 @@ export default {
}).then(loginInfo => {
uni.setStorageSync("isAgree", this.isAgree);
uni.setStorageSync("loginInfo", loginInfo);
getApp().$vm.init()
console.log("loginInfo", loginInfo);
this.$http({
@ -147,11 +88,10 @@ export default {
console.log("自动登录失败", err);
});
// uni.navigateTo({ url: "/pages/chat/chat-box?chatIdx=0" });
},
async getIp() {
// ip
return new Promise((resolve, reject) => {
@ -172,19 +112,18 @@ export default {
});
},
onSwitchShowPwd() {
this.isShowPwd = !this.isShowPwd;
}
},
onLoad() {
//
setTimeout(() => {
this.autoLogin();
}, 50);
},

Loading…
Cancel
Save