uni-app uni-id-pages希望增加需求 手机号短信注册接口增加密码字段
uni-app uni-id-pages希望增加需求 手机号短信注册接口增加密码字段
操作步骤:
- config.js设置
setPasswordAfterLogin: true,uni-id-pages–短信验证码登录–验证码–跳转到设置密码–设置密码还要短信验证码
预期结果:
- 主要是不太想浪费短信验证码。希望手机号短信登录注册接口增加密码字段,不用跳转设置密码又一次获取短信验证码。
实际结果:
- 手机号短信登录注册接口增加密码字段,不用跳转到设置密码页面又一次获取短信验证码
bug描述:
在用uni-id-pages的时候,用到短信验证码登录的时候,需求是提示用户设置密码,然后想到可以在config.js文件里面设置setPasswordAfterLogin: true,这样确实可以跳转到设置密码页面,但是设置密码页面还是需要短信验证码才能提交,这样一来就是需要两次短信验证码了,不太想花费两次短信验证码的钱来实现登录注册,毕竟短信验证码不便宜对不对?官方能不能改一下?手机号短信登录注册接口增加密码字段,我可以加上密码一起提交行不行,就不用跳转设置密码页面了
更多关于uni-app uni-id-pages希望增加需求 手机号短信注册接口增加密码字段的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在短信验证码登录接口添加密码不太符合接口设计规范,你如果需要此功能,可以手动修改uni-id-co云对象代码来实现个性化需求。
更多关于uni-app uni-id-pages希望增加需求 手机号短信注册接口增加密码字段的实战教程也可以访问 https://www.itying.com/category-93-b0.html
关键不知道怎么改你们代码
回复 请教大佬: uni-id-co 代码在 uni_modules/uni-id-pages/uniCloud 目录下。
回复 DCloud_uniCloud_CRL: 我当然知道代码在哪里啊,你们代码不好改,而且我升级uni-id又得重新弄,好烦
在 uni-app 的 uni-id-pages 中,如果你希望为手机号短信注册接口增加密码字段,可以按照以下步骤进行修改和扩展。
1. 修改前端页面
首先,你需要在注册页面中添加一个密码输入框,并确保在提交时能够将密码字段发送到后端。
示例代码:
<template>
<view>
<input type="text" v-model="phone" placeholder="请输入手机号" />
<input type="password" v-model="password" placeholder="请输入密码" />
<input type="text" v-model="code" placeholder="请输入验证码" />
<button @click="sendCode">获取验证码</button>
<button @click="register">注册</button>
</view>
</template>
<script>
export default {
data() {
return {
phone: '',
password: '',
code: ''
};
},
methods: {
async sendCode() {
// 调用发送验证码的接口
const res = await uniCloud.callFunction({
name: 'uni-id-send-sms-code',
data: {
phone: this.phone
}
});
if (res.result.code === 0) {
uni.showToast({ title: '验证码发送成功', icon: 'none' });
} else {
uni.showToast({ title: res.result.msg, icon: 'none' });
}
},
async register() {
// 调用注册接口
const res = await uniCloud.callFunction({
name: 'uni-id-register-by-sms',
data: {
phone: this.phone,
password: this.password,
code: this.code
}
});
if (res.result.code === 0) {
uni.showToast({ title: '注册成功', icon: 'none' });
// 注册成功后的逻辑
} else {
uni.showToast({ title: res.result.msg, icon: 'none' });
}
}
}
};
</script>
2. 修改后端云函数
接下来,你需要在后端的云函数中接收并处理这个密码字段。
示例代码:
'use strict';
const uniID = require('uni-id');
exports.main = async (event, context) => {
const { phone, password, code } = event;
// 验证验证码
const verifyRes = await uniID.verifyCode({
phone,
code,
type: 'register'
});
if (verifyRes.code !== 0) {
return verifyRes;
}
// 注册用户
const registerRes = await uniID.register({
username: phone,
password,
role: ['user']
});
return registerRes;
};
3. 修改 uni-id 配置
确保你的 uni-id 配置文件中允许通过手机号和密码进行注册。
示例配置:
{
"passwordSecret": "your_password_secret",
"tokenSecret": "your_token_secret",
"tokenExpiresIn": 7200,
"passwordErrorLimit": 6,
"passwordErrorRetryTime": 3600,
"sms": {
"codeExpiresIn": 300,
"codeLength": 6,
"smsKey": "your_sms_key",
"smsSecret": "your_sms_secret"
}
}


