这个程序不连数据库,所以一旦python程序重启前面的注册就没用了
这个程序不连数据库,所以一旦python程序重启前面的注册就没用了
这个程序不连数据库,所以一旦python程序重启前面的注册就没用了
这里无脑简单介绍一下这个low到爆炸的小程序(额。。因为当时无脑在练习python的正则的后来不知怎么就写到这里了,这里给读者一个心里暗示:本人尚未接受算法教学,所以内部代码极度的low,如果有大神有好的代码练习请带带无脑)
好了话不多说直接上代码:
先是微信小程序:
//登录界面// index.js
Page({/*** 页面的初始数据*/data: {account:"",//账号password:"",//密码inputtext:"",//清空input内容res:false,//判断账号密码是否正确 true->可以登录;false->不能登录;},//函数--获取账号gettext:function(e){this.setData({account:e.detail.value})},// 函数--获取密码getpassword:function(e){this.setData({password:e.detail.value})},// 函数--将获取的账号和密码交给后端对比submitTp:function(){wx.request({url: 'http://127.0.0.1:8001/models/denglu',data:{account:this.data.account,password:this.data.password},header: {'content-type': 'application/json' // 默认值},success:(res)=>{console.log(res)this.setData({res:res.data.res})if(this.data.res==false){wx.showToast({title: '登录失败',icon:'error',duration:500,mask:true,image:"/对方错了.jpg"})}else{this.setData({password:""})wx.navigateTo({url: '/pages/account/account',//跳转到用户界面额。。。因为只是为了实现注册和登录无脑并没有把account界面录入进来})}}})this.setData({inputtext:""})},// 函数--跳转注册页面toRegister:function(){wx.navigateTo({url: '/pages/register/register',})},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {},/*** 生命周期函数--监听页面初次渲染完成*/onReady: function () {},/*** 生命周期函数--监听页面显示*/onShow: function () {},/*** 生命周期函数--监听页面隐藏*/onHide: function () {},/*** 生命周期函数--监听页面卸载*/onUnload: function () {},/*** 页面相关事件处理函数--监听用户下拉动作*/onPullDownRefresh: function () {},/*** 页面上拉触底事件的处理函数*/onReachBottom: function () {},/*** 用户点击右上角分享*/onShareAppMessage: function () {}
})<!--index.wxml-->
<view class="container"><view id='id1' class="text"><text>账号:</text><input placeholder="请输入账号" bindinput="gettext" /></view><view id='id1' class="passworld"><text>密码:</text><input placeholder="请输入密码" password="true" bindinput="getpassword" value="{{ inputtext}}"/></view><button bindtap="submitTp">登录</button><button bindtap="toRegister">注册</button>
</view>/**index.wxss**/
.container{display: flex;flex-direction: column;
}
#id1{display: flex;flex-direction: row;align-items: center;
}
input{border: 1rpx solid #225588;margin: 20rpx 100rpx;border-radius: 20rpx;
}
button{background-color: darkgray;margin: 20rpx;
}
//注册界面// pages/register/register.js
Page({/*** 页面的初始数据*/data: {account:"",password:"",e_mail:"",flag:"",//判断是否注册成功},// 函数--获取accountgetAccount:function(e){this.setData({account:e.detail.value})},// 函数--获取passwordgetPassword:function(e){this.setData({password:e.detail.value})},// 函数--获取e-mailgetE_mail:function(e){this.setData({e_mail:e.detail.value})},// 函数--提交注册信息submit_Information:function(){wx.request({url: 'http://127.0.0.1:8000/model/zhuce',data:{account:this.data.account,password:this.data.password,email:this.data.e_mail},header: {'content-type': 'application/json' // 默认值},success:(res)=>{console.log(res.data.res)let res1=res.data.resif(res1==false){wx.showToast({title: '邮箱有误或是账号已存在',})}else{wx.showToast({title: '注册成功',})}}})},/*** 生命周期函数--监听页面加载*/onLoad: function (options) {},/*** 生命周期函数--监听页面初次渲染完成*/onReady: function () {},/*** 生命周期函数--监听页面显示*/onShow: function () {},/*** 生命周期函数--监听页面隐藏*/onHide: function () {},/*** 生命周期函数--监听页面卸载*/onUnload: function () {},/*** 页面相关事件处理函数--监听用户下拉动作*/onPullDownRefresh: function () {},/*** 页面上拉触底事件的处理函数*/onReachBottom: function () {},/*** 用户点击右上角分享*/onShareAppMessage: function () {}
})<!--pages/register/register.wxml-->
<view class="register"><view class="box1"><text>账号:</text><input placeholder="请输入用户名" bindinput="getAccount" /><text>密码:</text><input password="true" placeholder="请输入密码" bindinput="getPassword"/><text>邮箱:</text><input placeholder="请输入邮箱" bindinput="getE_mail"/></view><button bindtap="submit_Information">提交</button>
</view>/* pages/register/register.wxss */
.box1{display: flex;flex-direction: row;align-items: center;flex-wrap: wrap;
}
.box1 text{margin: 20rpx 30rpx;
}
.box1 input{border: 1rpx solid #c9acac;border-radius: 20rpx;
}
button{margin-top: 20rpx;background-color: darkgrey;
}
算了,考虑到无脑每次找别人代码时经常缺斤少两导致重新跑不起来这里把app的代码也带入吧
// app.json
{"pages": ["pages/index/index","pages/account/account","pages/register/register"],"window": {"backgroundTextStyle": "light","navigationBarBackgroundColor": "#fff","navigationBarTitleText": "Weixin","navigationBarTextStyle": "black"},"style": "v2","sitemapLocation": "sitemap.json"
}
js和css无脑没改(直接删干净)
这是其中要的一张图
python的代码:
#登录的后端
# _*_ coding:utf-8 _*_
# @time :2022/4/6 9:47
# @file :text/wx-dl-后端.py
# @IDE :PyCharm
# @Author :zfrom fastapi import FastAPI
import uvicorn
import requests as rq
import reapp = FastAPI()@app.get('/models/denglu')
def say_hello(account: str, password: str):flag = Falseflag = determine_password(account, password)return { "res": flag}def determine_password(account, password):''':param account: 登录的账号:param password: 登录的密码:return: 如果匹配:True;如果不匹配:False;'''f = open('dir12.txt', 'r')str_txt = f.read()dict_txt = eval(str_txt)if account in dict_txt:if password == dict_txt[account]:return Trueelse:return Falseelse:return Falseif __name__ == '__main__':# 我的文件名为wx-dl-后端,所以下面的参数app = ‘wx-dl-后端:app’uvicorn.run(app='wx-dl-后端:app', host="127.0.0.1", port=8001, reload=True, debug=True)
#注册的后端
# _*_ coding:utf-8 _*_
# @time :2022/4/6 13:05
# @file :text/wx-zc-后端.py
# @IDE :PyCharm
# @Author :zfrom fastapi import FastAPI
import uvicornapp = FastAPI()
dir1_str = {}@app.get('/model/zhuce')
def say_hello(account: str, password: str, email: str):global dir1_strflag = Trueif email.find('@') == -1 or not email.endswith(".com"):flag = Falseelse:f_r = open('dir12.txt', 'r') # 打开账号文件用于读txt_str = f_r.read() # 读取账号信息f_r.close()f_w = open('dir12.txt', 'w') # 打开账号文件用于写 !!!!切记此行代码必须在f_r读取关闭的后面不然会清空原文件!!!!if len(txt_str) != 0:dir1_str = eval(txt_str) # 内容转字典if exist_account(dir1_str, account): # 判断账号是否被注册dir1_str[account] = password # 存入字典f_w.write(str(dir1_str))f_w.close()else:f_w.write(str(dir1_str))f_w.close()flag = Falsereturn {"res": flag}def exist_account(mydir, account):''':param mydir: 字典参数:param account: 注册的账号:return: 存在:false ;不存在:True'''if account in mydir:return Falseelse:return Trueif __name__ == '__main__':# 我的文件名为wx-zc-后端,所以下面的参数app = ‘wx-zc-后端:app’uvicorn.run(app='wx-zc-后端:app', host="127.0.0.1", port=8000, reload=True, debug=True)