提交 8e68abdd 编写于 作者: DCloud_JSON's avatar DCloud_JSON

新增注册成功后的逻辑

上级 03468546
module.exports = {
"h5":{
"url":"https://static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com" ,// 前端网页托管的域名
"openApp":{
"url":"https://static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com",// 前端网页托管的域名
"openApp":{ // 在h5端全局悬浮引导用户下载app的功能 更多自定义要求在/common/openApp.js中修改
"openUrl":'https://sj.qq.com/myapp/detail.htm?apkName=com.tencent.android.qqdownloader&info=6646FD239A6EBA9E2DEE5DFC7E18D867',
"appname": 'base-app',
"logo": './static/logo.png',
......
......@@ -10,15 +10,14 @@ export default function() {
`<img src="${CONFIG_OPEN.logo}" style="width: 2rem;height: 2rem;border-radius: 3px;">` : '';
let openApp = document.createElement("div");
openApp.id = 'openApp';
openApp.style =
'position: fixed;top: 0;left: 0;right: 0;z-index: 999;width: 100%;height: 45px;display: flex;flex-direction: row;justify-content: space-between;align-items: center;box-sizing: border-box;padding: 0 0.5rem;background-color: #FFFFFF;'
'position: fixed;background:#FFFFFF;box-shadow: #eeeeee 1px 1px 9px; ;top: 0;left: 0;right: 0;z-index: 999;width: 100%;height: 45px;display: flex;flex-direction: row;justify-content: space-between;align-items: center;box-sizing: border-box;padding: 0 0.5rem;'
openApp.innerHTML = `
<div style="display: flex;flex-direction: row;justify-content: flex-start;align-items: center;">
${openLogo}
<div style="padding-left: 0.3rem;font-size: 0.25rem;">${CONFIG_OPEN.appname || ''}</div>
<div style="padding-left: 0.3rem;font-size: 12px;">${CONFIG_OPEN.appname || ''}</div>
</div>
<div class="openBtn" style="padding: 5px;font-size: 0.3rem;border-radius: 2px;border: 1px solid #007AFF;color: #007AFF;">下载app</div>
<div class="openBtn" style="padding: 5px;font-size:12px;border-radius: 2px;border: 1px solid #007AFF;color: #007AFF;">下载app</div>
`;
document.body.insertBefore(openApp, document.body.firstChild);
document.body.style = 'height:calc(100% - 45px); margin-top:45px;';
......
{
"bsonType": "object",
"permission": {
"read": "doc.is_reply == false",
"create": true,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id": {
"bsonType": "string",
"description": "留言反馈用户ID\/回复留言用户ID,参考uni-id-users表",
"foreignKey": "uni-id-users._id",
"forceDefaultValue": {
"$env": "uid"
}
},
"title": {
"description": "反馈标题(用于列表展示)"
},
"ip": {
"forceDefaultValue": {
"$env": "clientIP"
}
},
"create_date": {
"bsonType": "timestamp",
"description": "留言时间\/回复留言时间",
"forceDefaultValue": {
"$env": "now"
}
},
"content": {
"bsonType": "string",
"description": "留言内容\/回复内容",
"trim": "right"
},
"imgs": {
"bsonType": "array",
"description": "图片列表"
},
"is_reply": {
"bsonType": "bool",
"description": "是否是回复类型"
},
"feedback_id": {
"bsonType": "string",
"description": "被回复留言ID"
},
"contact": {
"bsonType": "string",
"description": "联系人",
"trim": "both"
},
"mobile": {
"bsonType": "string",
"description": "联系电话",
"trim": "both"
},
"reply_count": {
"bsonType": "int",
"description": "被回复条数"
}
}
}
......@@ -32,11 +32,23 @@ exports.main = async (event, context) => {
return recentRecord.data.filter(item => item.state === 0).length === recordSize;
}
//注册成功后为用户执行相关操作,如创建该用户的积分表等
function registerSuccess(uid) {
await db.collection('uni-id-scores').add({
user_id: uid,
score: 1,
type: 1,
balance: 1,
comment: "",
create_date: Date.now()
})
}
//设置某些模块不需要token(也就是登陆成功后)才能操作,如果需要token就获取当前操作账户的uid
let noCheckAction = [
'register', 'checkToken','login', 'logout', 'sendSmsCode',
'createCaptcha', 'verifyCaptcha','refreshCaptcha', 'inviteLogin',
'login_by_weixin','login_by_univerify','login_by_apple','loginBySms','resetPwdBySmsCode'
'register', 'checkToken', 'login', 'logout', 'sendSmsCode',
'createCaptcha', 'verifyCaptcha', 'refreshCaptcha', 'inviteLogin',
'login_by_weixin', 'login_by_univerify', 'login_by_apple', 'loginBySms', 'resetPwdBySmsCode'
]
let payload;
console.log(event.action);
......@@ -83,20 +95,31 @@ exports.main = async (event, context) => {
let res = {}
switch (event.action) {
case 'register':
let {username,password,gender,nickname} = params
if(/^1\d{10}$/.test(username)){
let {
username, password, gender, nickname
} = params
if (/^1\d{10}$/.test(username)) {
return {
code: 401,
msg: '用户名不能是手机号'
}
};
if(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(username)){
if (/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(username)) {
return {
code: 401,
msg: '用户名不能是邮箱'
}
}
res = await uniID.register({username,password,gender,nickname,password});
res = await uniID.register({
username,
password,
gender,
nickname,
password
});
if (res.code === 0) {
registerSuccess(res.uid)
}
break;
case 'login':
let passed = false;
......@@ -113,6 +136,10 @@ exports.main = async (event, context) => {
queryField: ['username', 'email', 'mobile']
});
await loginLog(res);
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
needCaptcha = await getNeedCaptcha();
}
......@@ -121,17 +148,26 @@ exports.main = async (event, context) => {
case 'login_by_weixin':
res = await uniID.loginByWeixin(params);
await uniID.updateUser({
uid: params.uid,
username:"微信用户"
uid: res.uid,
username: "微信用户"
});
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
res.userInfo.username = "微信用户"
loginLog(res)
break;
case 'login_by_univerify':
res = await uniID.loginByUniverify(params)
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
break;
case 'login_by_apple':
res = await uniID.loginByApple(params)
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
loginLog(res)
break;
case 'checkToken':
......@@ -167,6 +203,9 @@ exports.main = async (event, context) => {
type: params.type,
templateId
})
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
break;
case 'loginBySms':
if (!params.code) {
......@@ -182,6 +221,9 @@ exports.main = async (event, context) => {
}
}
res = await uniID.loginBySms(params)
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
loginLog(res)
break;
case 'inviteLogin':
......@@ -195,6 +237,9 @@ exports.main = async (event, context) => {
...params,
type: 'register'
})
if (res.code == 0 && res.type == 'register') {
registerSuccess(res.uid)
}
break;
case 'resetPwdBySmsCode':
if (!params.code) {
......@@ -211,9 +256,12 @@ exports.main = async (event, context) => {
}
let loginBySmsRes = await uniID.loginBySms(params)
console.log(loginBySmsRes);
if(loginBySmsRes.code === 0){
res = await uniID.resetPwd({password:params.password,"uid":loginBySmsRes.uid})
}else{
if (loginBySmsRes.code === 0) {
res = await uniID.resetPwd({
password: params.password,
"uid": loginBySmsRes.uid
})
} else {
return loginBySmsRes
}
break;
......
<template>
<view class="uni-container">
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
<uni-forms-item name="article_id" label="" required>
<uni-easyinput placeholder="文章id,参考opendb-news-articles表" v-model="formData.article_id" />
</uni-forms-item>
<uni-forms-item name="create_date" label="">
<uni-datetime-picker return-type="timestamp" :value="formData.create_date" />
</uni-forms-item>
<view class="uni-button-group">
<button type="primary" class="uni-button" @click="submit">提交</button>
</view>
</uni-forms>
</view>
</template>
<script>
import { validator } from '../../js_sdk/validator/opendb-news-favorite.js';
const db = uniCloud.database();
const dbCollectionName = 'opendb-news-favorite';
function getValidator(fields) {
let reuslt = {}
for (let key in validator) {
if (fields.indexOf(key) > -1) {
reuslt[key] = validator[key]
}
}
return reuslt
}
export default {
data() {
return {
formData: {
"article_id": "",
"create_date": null
},
formOptions: {},
rules: {
...getValidator(["article_id","create_date"])
}
}
},
onReady() {
this.$refs.form.setRules(this.rules)
},
methods: {
/**
* 触发表单提交
*/
submit() {
uni.showLoading({
mask: true
})
this.$refs.form.submit().then((res) => {
this.submitForm(res)
}).catch((errors) => {
uni.hideLoading()
})
},
submitForm(value) {
// 使用 clientDB 提交数据
db.collection(dbCollectionName).add(value).then((res) => {
uni.showToast({
icon: 'none',
title: '新增成功'
})
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}
}
}
</script>
<style>
.uni-container {
padding: 15px;
}
.uni-input-border,
.uni-textarea-border {
width: 100%;
font-size: 14px;
color: #666;
border: 1px #e5e5e5 solid;
border-radius: 5px;
box-sizing: border-box;
}
.uni-input-border {
padding: 0 10px;
height: 35px;
}
.uni-textarea-border {
padding: 10px;
height: 80px;
}
.uni-button-group {
margin-top: 50px;
display: flex;
justify-content: center;
}
.uni-button {
width: 184px;
padding: 12px 20px;
font-size: 14px;
border-radius: 4px;
line-height: 1;
margin: 0;
}
</style>
<template>
<view class="container">
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" :options="options" collection="opendb-news-favorite" field="article_id,create_date" :where="queryWhere" :getone="true" :manual="true">
<view v-if="error">{{error.message}}</view>
<view v-else-if="loading">
<uni-load-more :contentText="loadMore" status="loading"></uni-load-more>
</view>
<view v-else-if="data">
<view>
<text>article_id:</text>
<text>{{data.article_id}}</text>
</view>
<view>
<text>create_date:</text>
<uni-dateformat :date="data.create_date" :threshold="[0, 0]" />
</view>
</view>
</unicloud-db>
<view class="btns">
<button type="primary" @click="handleUpdate">修改</button>
<button type="warn" class="btn-delete" @click="handleDelete">删除</button>
</view>
</view>
</template>
<script>
// 由schema2code生成,包含校验规则和enum静态数据
import { enumConverter } from '../../js_sdk/validator/opendb-news-favorite.js';
export default {
data() {
return {
queryWhere: '',
loadMore: {
contentdown: '',
contentrefresh: '',
contentnomore: ''
},
options: {
// 将scheme enum 属性静态数据中的value转成text
...enumConverter
}
}
},
onLoad(e) {
this._id = e.id
},
onReady() {
if (this._id) {
this.queryWhere = '_id=="' + this._id + '"'
}
},
methods: {
handleUpdate() {
// 打开修改页面
uni.navigateTo({
url: './edit?id=' + this._id,
events: {
// 监听修改页面成功修改数据后, 刷新当前页面数据
refreshData: () => {
this.$refs.udb.loadData({
clear: true
})
}
}
})
},
handleDelete() {
this.$refs.udb.remove(this._id, {
success: (res) => {
// 删除数据成功后跳转到list页面
uni.navigateTo({
url: './list'
})
}
})
}
}
}
</script>
<style>
.container {
padding: 10px;
}
.btns {
margin-top: 10px;
display: flex;
flex-direction: row;
}
.btns button {
flex: 1;
}
.btn-delete {
margin-left: 10px;
}
</style>
<template>
<view class="uni-container">
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
<uni-forms-item name="article_id" label="" required>
<uni-easyinput placeholder="文章id,参考opendb-news-articles表" v-model="formData.article_id" />
</uni-forms-item>
<uni-forms-item name="create_date" label="">
<uni-datetime-picker return-type="timestamp" :value="formData.create_date" />
</uni-forms-item>
<view class="uni-button-group">
<button type="primary" class="uni-button" @click="submit">提交</button>
</view>
</uni-forms>
</view>
</template>
<script>
import { validator } from '../../js_sdk/validator/opendb-news-favorite.js';
const db = uniCloud.database();
const dbCollectionName = 'opendb-news-favorite';
function getValidator(fields) {
let reuslt = {}
for (let key in validator) {
if (fields.indexOf(key) > -1) {
reuslt[key] = validator[key]
}
}
return reuslt
}
export default {
data() {
return {
formData: {
"article_id": "",
"create_date": null
},
formOptions: {},
rules: {
...getValidator(["article_id","create_date"])
}
}
},
onLoad(e) {
const id = e.id
this.formDataId = id
this.getDetail(id)
},
onReady() {
this.$refs.form.setRules(this.rules)
},
methods: {
/**
* 触发表单提交
*/
submit() {
uni.showLoading({
mask: true
})
this.$refs.form.submit().then((res) => {
this.submitForm(res)
}).catch((errors) => {
uni.hideLoading()
})
},
submitForm(value) {
// 使用 clientDB 提交数据
db.collection(dbCollectionName).doc(this.formDataId).update(value).then((res) => {
uni.showToast({
icon: 'none',
title: '修改成功'
})
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
},
/**
* 获取表单数据
* @param {Object} id
*/
getDetail(id) {
uni.showLoading({
mask: true
})
db.collection(dbCollectionName).doc(id).field('article_id').get().then((res) => {
const data = res.result.data[0]
if (data) {
this.formData = data
}
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}
}
}
</script>
<style>
.uni-container {
padding: 15px;
}
.uni-input-border,
.uni-textarea-border {
width: 100%;
font-size: 14px;
color: #666;
border: 1px #e5e5e5 solid;
border-radius: 5px;
box-sizing: border-box;
}
.uni-input-border {
padding: 0 10px;
height: 35px;
}
.uni-textarea-border {
padding: 10px;
height: 80px;
}
.uni-button-group {
margin-top: 50px;
display: flex;
justify-content: center;
}
.uni-button {
width: 184px;
padding: 12px 20px;
font-size: 14px;
border-radius: 4px;
line-height: 1;
margin: 0;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册