文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit befefe33 by 李景熙

update 登录注册接口

parent b064e388
from peewee import *
import json
mysql = MySQLDatabase(
'sys',
......@@ -11,68 +12,124 @@ mysql = MySQLDatabase(
mysql.connect()
class Result:
code: int
message: []
data: {}
def __init__(self, code, message, data):
self.code = code
self.message = message
self.data = data
class User(Model):
username = CharField(unique=True, null=False);
password = CharField(null=False);
email = CharField(unique=True, null=False);
type = BooleanField(default=False);
picscore = IntegerField(default=0);
picAccuracy = DoubleField(default=0);
textscore = IntegerField(default=0);
textAccuracy = DoubleField(default=0);
publishscore = IntegerField(default=0);
usrId = AutoField(primary_key=True, unique=True)
userName = CharField(null=False, max_length=10, unique=True)
password = CharField(null=False, max_length=20)
mail = CharField(null=False, max_length=32)
type = FixedCharField(max_length=1, choices=['t', 'p'], default='t')
imageScore = IntegerField(null=False, default=0)
imageAccuracy = DoubleField(null=True)
textScore = IntegerField(null=False, default=0)
textAccuracy = DoubleField(null=True)
postScore = IntegerField(null=False, default=0)
postNum = IntegerField(null=False, default=0)
class Meta:
database = mysql
# 注册功能
def create_user(username, password, email):
if not User.table_exists():
User.create_table()
user = User(username=username, password=password, email=email)
try:
user.save()
except Exception:
print(0)
def register(username, pwd, email):
if User.select().where(User.userName == username).count() > 0:
return Result(0, "userName is repeat", {})
else:
print(1)
User.create(userName=username, password=pwd, mail=email)
tmp = User.get(User.userName == username)
data = {
'userId': tmp.usrId,
'username': tmp.userName,
'email': tmp.mail,
'identity': tmp.type
}
return Result(1, "", data)
# 登录
def find_user(username, password):
if not User.table_exists():
User.create_table()
try:
p = User.get(User.username == username and User.password == password)
except Exception:
print(0)
def login(username, pwd):
u = User.get(User.userName == username)
if (u.password == pwd):
tmp = User.get(User.userName == username)
data = {
'userId': tmp.usrId,
'username': tmp.userName,
'email': tmp.mail,
'identity': tmp.type
}
return Result(1, "", data)
else:
print(1)
return Result(0, "wrong userName/password", {})
# 个人信息界面根据用户名返回用户信息
def find_information(username):
if not User.table_exists():
User.create_table()
try:
p = User.get(User.username == username)
except Exception:
print(0)
else:
print(p.email)
#检查是否存在该发布者uid
def find_id(id):
try:
p = User.get(User.id == id)
except Exception:
return False
else:
return True
def personnal_information(id):
tmp = User.get(User.usrId == id)
data = {
'userName': tmp.userName,
'userId': tmp.usrId,
'email': tmp.mail,
'identity': tmp.type,
'imageIntegration': tmp.imageScore,
'imageAccuracy': tmp.imageAccuracy,
'textIntegration': tmp.textScore,
'textAccuracy': tmp.textAccuracy,
'releaseTaskIntegration': tmp.postScore,
'taskNumber': tmp.postNum
}
return Result(1, "", data)
def set_type(id, type):
tmp = User.get(User.usrId == id)
tmp.type = type
tmp.save()
def add_image_score(id, score):
tmp = User.get(User.usrId == id)
tmp.imageScore = tmp.imageScore + score
tmp.save()
def setImageAccuracy(id, acuuracy):
tmp = User.get(User.usrId == id)
tmp.imageAccuracy = tmp.imageAccuracy + acuuracy
tmp.save()
def add_text_score(id, score):
tmp = User.get(User.usrId == id)
tmp.textScore = tmp.textScore + score
tmp.save()
def setTextAccuracy(id, acuuracy):
tmp = User.get(User.usrId == id)
tmp.textAccuracy = tmp.textAccuracy + acuuracy
tmp.save()
def add_post_score(id, score):
tmp = User.get(User.usrId == id)
tmp.postScore = tmp.postScore + score
tmp.save()
def add_post_num(id, num):
tmp = User.get(User.usrId == id)
tmp.postNum = tmp.postNum + num
tmp.save()
if __name__ == '__main__':
create_user('333', '0', '7')
find_information('333')
find_user('123', '200')
\ No newline at end of file
User.register('tom', '123', '32@qq.com')
User.register('tom', '123', '32@qq.com')
print(User.personnal_information(2))
......@@ -2,7 +2,7 @@ from flask import Flask
# from views.uploadDownload import uploadDownload
# from views.textAnnotation import textAnnotation
from views.login import user
from views.user import user
app = Flask(__name__)
# app.register_blueprint(textAnnotation)
......
import json
from flask import Blueprint
from flask import request
from Dao import User
user = Blueprint("user", __name__, url_prefix="/user")
@user.route("/register")
def register():
username = request.args['username']
password = request.args['passwd']
email = request.args['email']
User.create_user(username, password, email)
return json.dumps(username)
@user.route("/login", methods=["Post"])
def login():
username = request.form['name']
passwd = request.form['passwd']
User.find_user(username, passwd)
return json.dumps(username)
import json
from flask import Blueprint
from flask import request
from Dao import User
user = Blueprint("user", __name__, url_prefix="/user")
@user.route("/signup", methods=["Post"])
def register():
username = request.args['userName']
password = request.args['password']
email = request.args['email']
return User.register(username, password, email)
@user.route("/signin", methods=["Post"])
def signup():
username = request.args['userName']
password = request.args['password']
ret = User.login(username, password)
res = {
'code': ret.code,
'message': ret.message,
'data': ret.data
}
return json.dumps(res)
@user.route("/personalInformation", methods=["GET"])
def personnal_information():
userId = request.args['userId']
return User.personnal_information(userId)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment