优化登录记住我体验
This commit is contained in:
@@ -30,7 +30,7 @@ public class JwtProperties {
|
|||||||
/**
|
/**
|
||||||
* 记住登录 AccessToken 有效期,单位秒。
|
* 记住登录 AccessToken 有效期,单位秒。
|
||||||
*/
|
*/
|
||||||
private long rememberMeAccessTokenExpirationSeconds = 60 * 60;
|
private long rememberMeAccessTokenExpirationSeconds = 7 * 24 * 60 * 60;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RefreshToken 有效期,单位秒。
|
* RefreshToken 有效期,单位秒。
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ fingertip-designer:
|
|||||||
jwt:
|
jwt:
|
||||||
issuer: fingertip-designer
|
issuer: fingertip-designer
|
||||||
access-token-expiration-seconds: 7200
|
access-token-expiration-seconds: 7200
|
||||||
remember-me-access-token-expiration-seconds: 3600
|
remember-me-access-token-expiration-seconds: 604800
|
||||||
refresh-token-expiration-seconds: 604800
|
refresh-token-expiration-seconds: 604800
|
||||||
clock-skew-seconds: 30
|
clock-skew-seconds: 30
|
||||||
signature:
|
signature:
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ class JwtUtilTest {
|
|||||||
void resolveAccessTokenExpirationSecondsShouldUseRememberMeSeconds() {
|
void resolveAccessTokenExpirationSecondsShouldUseRememberMeSeconds() {
|
||||||
JwtProperties properties = new JwtProperties();
|
JwtProperties properties = new JwtProperties();
|
||||||
properties.setAccessTokenExpirationSeconds(120L);
|
properties.setAccessTokenExpirationSeconds(120L);
|
||||||
properties.setRememberMeAccessTokenExpirationSeconds(3600L);
|
properties.setRememberMeAccessTokenExpirationSeconds(604800L);
|
||||||
JwtUtil jwtUtil = new JwtUtil(properties);
|
JwtUtil jwtUtil = new JwtUtil(properties);
|
||||||
|
|
||||||
assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(false)).isEqualTo(120L);
|
assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(false)).isEqualTo(120L);
|
||||||
assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(true)).isEqualTo(3600L);
|
assertThat(jwtUtil.resolveAccessTokenExpirationSeconds(true)).isEqualTo(604800L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const authApi = require('../../api/auth')
|
|||||||
const { BRAND_CONFIG } = require('../../utils/config')
|
const { BRAND_CONFIG } = require('../../utils/config')
|
||||||
|
|
||||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
||||||
|
const LOGIN_PREFERENCE_KEY = 'fingertip_manager_login_preference'
|
||||||
|
|
||||||
function buildSession(data) {
|
function buildSession(data) {
|
||||||
const userInfo = data.userInfo || data.user || {}
|
const userInfo = data.userInfo || data.user || {}
|
||||||
@@ -60,6 +61,22 @@ function assertShopSession(session) {
|
|||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLoginPreference() {
|
||||||
|
try {
|
||||||
|
return wx.getStorageSync(LOGIN_PREFERENCE_KEY) || {}
|
||||||
|
} catch (error) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLoginPreference(preference) {
|
||||||
|
wx.setStorageSync(LOGIN_PREFERENCE_KEY, preference || {})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearLoginPreference() {
|
||||||
|
wx.removeStorageSync(LOGIN_PREFERENCE_KEY)
|
||||||
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
loginMode: 'phone',
|
loginMode: 'phone',
|
||||||
@@ -83,6 +100,19 @@ Page({
|
|||||||
switchingShop: false
|
switchingShop: false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
const preference = getLoginPreference()
|
||||||
|
if (!preference.rememberMe) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.setData({
|
||||||
|
loginMode: preference.loginMode === 'password' ? 'password' : 'phone',
|
||||||
|
rememberMe: true,
|
||||||
|
'form.account': preference.account || '',
|
||||||
|
'form.phone': preference.phone || ''
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
onInput(event) {
|
onInput(event) {
|
||||||
const field = event.currentTarget.dataset.field
|
const field = event.currentTarget.dataset.field
|
||||||
this.setData({
|
this.setData({
|
||||||
@@ -138,8 +168,24 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggleRememberMe() {
|
toggleRememberMe() {
|
||||||
this.setData({
|
const rememberMe = !this.data.rememberMe
|
||||||
rememberMe: !this.data.rememberMe
|
this.setData({ rememberMe })
|
||||||
|
if (!rememberMe) {
|
||||||
|
clearLoginPreference()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
saveLoginPreference() {
|
||||||
|
if (!this.data.rememberMe) {
|
||||||
|
clearLoginPreference()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const form = this.data.form
|
||||||
|
setLoginPreference({
|
||||||
|
rememberMe: true,
|
||||||
|
loginMode: this.data.loginMode,
|
||||||
|
account: String(form.account || '').trim(),
|
||||||
|
phone: String(form.phone || '').trim()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -286,6 +332,7 @@ Page({
|
|||||||
const session = await this.loginForShop(shopId)
|
const session = await this.loginForShop(shopId)
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
app.setSession(session)
|
app.setSession(session)
|
||||||
|
this.saveLoginPreference()
|
||||||
this.closeShopSelector()
|
this.closeShopSelector()
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
wx.reLaunch({ url: '/pages/planning/index' })
|
||||||
},
|
},
|
||||||
@@ -346,6 +393,7 @@ Page({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.setSession(assertShopSession(session))
|
app.setSession(assertShopSession(session))
|
||||||
|
this.saveLoginPreference()
|
||||||
wx.reLaunch({ url: '/pages/planning/index' })
|
wx.reLaunch({ url: '/pages/planning/index' })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isShopSelectionRequiredError(error) || await this.tryOpenLoginShopSelector()) {
|
if (isShopSelectionRequiredError(error) || await this.tryOpenLoginShopSelector()) {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="remember-row" bindtap="toggleRememberMe">
|
<view class="remember-row" bindtap="toggleRememberMe">
|
||||||
<view class="agreement-check {{rememberMe ? 'checked' : ''}}">{{rememberMe ? '✓' : ''}}</view>
|
<view class="agreement-check {{rememberMe ? 'checked' : ''}}">{{rememberMe ? '✓' : ''}}</view>
|
||||||
<view class="agreement-copy">记住登录 1 小时</view>
|
<view class="agreement-copy">记住我</view>
|
||||||
</view>
|
</view>
|
||||||
<button class="primary-btn login-btn" loading="{{loading}}" bindtap="submit">登录</button>
|
<button class="primary-btn login-btn" loading="{{loading}}" bindtap="submit">登录</button>
|
||||||
<view class="auth-links">
|
<view class="auth-links">
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
.auth-page {
|
.auth-page {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: flex-start;
|
||||||
padding-top: 84rpx;
|
padding-top: 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand {
|
.brand {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-bottom: 54rpx;
|
margin-bottom: 34rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
|
|||||||
Reference in New Issue
Block a user