- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
- python web(bottle框架)知行合一之-简单知识付费
python web(bottle框架)知行合一之-简单知识付费平台-”全栈“实践(9)---登入接口
PS:笔记只是为了更好表达我怎么语言表述,有些时候可能难免废话一推!
因知识有限, 如有错误, 欢迎指正!
每日细语:生活有些时候是一场逃亡,我们不能坐以待毙!
续言
既然已经到了编写接口的时刻,那我们免不了的就是如何进行接口测试及调试,我自己个人的话,就不太喜欢在浏览器进行访问。
其实我们可以接触工具来辅助我们进行接口的测试。
比如:postman等工具。
接口划分
PS:项目开始之初我的立意就比较简单,不会搞的很复杂的相关的权限验证等。
声明两个模块:
image.pnglogin.py模块说明
登入模块里面涉及到的工具类:
PS:这些工具类来自大神的提供的工具类包中,
建议大家去学习一下这位大神的博文!我后续的开发也都是基于他的系列文章基础上来展开的哟!
更多内容,敬请观注他的博客:http://www.cnblogs.com/EmptyFS/
http://www.cnblogs.com/EmptyFS/p/7687691.html
web_helper.py # 获取来自于用户提交的相关的参数信息的封装
json_helper # 处理json工具类
模型类的重新封装:
from peewee import *
database = PostgresqlDatabase('knowledgepay',
**{'user': 'postgres', 'host': 'localhost', 'password': '123456', 'port': 5432})
class UnknownField(object):
def __init__(self, *_, **__): pass
class BaseModel(Model):
class Meta:
database = database
class Activity(BaseModel):
activity_describe = TextField(null=True)
activity = TextField(column_name='activity_id', index=True)
activity_name = TextField()
add_time = DateTimeField(index=True)
course_code = TextField(column_name='course_code_id', index=True)
course_img_cover = TextField()
expiry_date = DateTimeField(index=True, null=True)
is_enable = IntegerField(index=True, null=True)
class Meta:
table_name = 'activity'
class Announcement(BaseModel):
announcement_describe = TextField(null=True)
announcement = TextField(column_name='announcement_id', index=True)
announcement_name = TextField()
is_enable = IntegerField(index=True, null=True)
class Meta:
table_name = 'announcement'
class Course(BaseModel):
add_time = TextField(null=True)
all_num_count = IntegerField(null=True)
author = TextField(null=True)
course_classify_code = TextField(index=True, null=True)
course_code = TextField(column_name='course_code_id', null=True)
describe_detailed = TextField()
describe_simple = IntegerField(null=True)
has_learn_num = IntegerField(null=True)
has_updata_num_count = IntegerField(null=True)
img_cover = TextField()
is_down = IntegerField(null=True)
is_flee = IntegerField(null=True)
is_sell = IntegerField(null=True)
is_vip_flee = IntegerField(null=True)
name = TextField(index=True)
price = IntegerField()
state = IntegerField(null=True)
title = TextField()
type = IntegerField(index=True, null=True)
up_time = DateTimeField(null=True)
class Meta:
table_name = 'course'
class CourseClassify(BaseModel):
add_time = DateTimeField()
course_classify_code = TextField(index=True)
course_code = DateTimeField(column_name='course_code_id', index=True, null=True)
describe = TextField()
icon_url = TextField(null=True)
is_enable = IntegerField(index=True, null=True)
class Meta:
table_name = 'course_classify'
class CourseContent(BaseModel):
add_time = DateTimeField()
buy_describe = TextField(null=True)
code = TextField(index=True, null=True)
content_detailed = TextField(null=True)
content_file_url = TextField(null=True)
content_index = IntegerField(null=True)
course_code = IntegerField(column_name='course_code_id', index=True, null=True)
expiry_date = DateTimeField(index=True, null=True)
is_enable = IntegerField(null=True)
is_flee = TextField(null=True)
title = TextField(null=True)
visit_count = IntegerField(null=True)
class Meta:
table_name = 'course_content'
class CourseOrder(BaseModel):
add_time = DateTimeField()
course_code = TextField(column_name='course_code_id', index=True)
course_name = TextField(null=True)
is_pay = IntegerField(index=True, null=True)
order = TextField(column_name='order_id', index=True)
pay_state_describe = IntegerField(null=True)
pay_time = DateTimeField(null=True)
pay_type = TextField(null=True)
phone_num = TextField(index=True, null=True)
class Meta:
table_name = 'course_order'
class UserInfo(BaseModel):
e_mail = TextField(null=True)
gender = TextField(null=True)
head_cover = TextField(null=True)
is_activate = IntegerField(null=True)
is_vip = IntegerField(null=True)
nick_name = TextField()
pass_word = TextField()
phone_num = TextField(index=True)
register_time = DateTimeField(null=True)
wx_access_token = TextField(null=True)
class Meta:
table_name = 'user_info'
def GetSession():
return database
# 上下文出处理
from contextlib import contextmanager
@contextmanager
def session_scope():
session = GetSession()
session.connect()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()
user_info_logic.py 类的简单封装
from business_logic.db_model import knowledgepay_model
def InsertPerson(phone_num='', nick_name='', pass_word=''):
with knowledgepay_model.session_scope():
uncle_bob = knowledgepay_model.UserInfo(phone_num=phone_num, nick_name=nick_name, pass_word=pass_word)
return uncle_bob.save() # bob 现在被存储在数据库内
login.py 登入类接口:
PS: (不要挑密码是明文的毛病!全国人民都知道需要加密的!我只是懒!谢谢亲!)
#!/usr/bin/evn python
# coding=utf-8
# + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +
# ┏┓ ┏┓+ +
# ┏┛┻━━━┛┻┓ + +
# ┃ ┃
# ┃ ━ ┃ ++ + + +
# ████━████ ┃+
# ┃ ┃ +
# ┃ ┻ ┃
# ┃ ┃ + +
# ┗━┓ ┏━┛
# ┃ ┃
# ┃ ┃ + + + +
# ┃ ┃ Codes are far away from bugs with the animal protecting
# ┃ ┃ + 神兽保佑,代码无bug
# ┃ ┃
# ┃ ┃ +
# ┃ ┗━━━┓ + +
# ┃ ┣┓
# ┃ ┏┛
# ┗┓┓┏━┳┓┏┛ + + + +
# ┃┫┫ ┃┫┫
# ┗┻┛ ┗┻┛+ + + +
# + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +"""
"""
Author = zyx
@Create_Time: 2018/4/20 15:27
@version: v1.0.0
@Contact: 308711822@qq.com
@File: login.py
@文件功能描述: 登入服务接口
"""
from bottle import get, post, request
from base_framework.net import web_helper, session_helper
from business_logic.api_db_logics import user_info_logic
from base_framework.utils import json_helper
@get('/api/v1/user/login/')
@post('/api/v1/user/login/')
def callback():
'''登入'''
'''1:获取用户提交过来的手机号码 和 密码进行验证 是否已经注册过-----其实这里还可以进一步的进行封装'''
if request.method.upper() in ('POST', 'PUT', 'DELETE'):
phone_num = web_helper.get_form('phone_num', '用户号码') # 默认开启 不能为空的验证
pass_word = web_helper.get_form('pass_word', '用户密码') # 默认开启 不能为空的验证
else:
phone_num = web_helper.get_query('phone_num', '用户号码') # 默认开启 不能为空的验证
pass_word = web_helper.get_query('pass_word', '用户密码') # 默认开启 不能为空的验证
'''2:根据用户的手机号码,进行验证是否已注册,如果已经注册的话,那就再判断密码是否正确-----其实这里还可以进一步的进行封装'''
u = user_info_logic.check_by_get(phone_num)
if not u:
return web_helper.return_msg("9999", "亲!您还没有注册")
if u.get('pass_word') != pass_word:
return web_helper.return_msg("9999", "亲!您的密码被狗吃了")
'''3:写入相关的session信息到本地上'''
s = session_helper.get_session()
s['phone_num'] = phone_num
s['pass_word'] = pass_word
s.save()
return web_helper.return_msg("0000", "登入成功!")
进行接口测试:
测试
结束
登入的逻辑其实很简单,就是
1:查看数据库有没有此用户存在
2:查看密码是否和数据库存贮的一致
3:然后~然后我就结束了这章了!!!
以上笔记纯属个人学习实践总结,有兴趣的同学可以加群一起学习讨论QQ:308711822
网友评论