python学习
This commit is contained in:
@@ -1 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb()
|
||||
23
common/libs/user/UserService.py
Normal file
23
common/libs/user/UserService.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import hashlib,base64,random,string
|
||||
|
||||
class UserService():
|
||||
|
||||
@staticmethod
|
||||
def geneAuthCode(user_info = None ):
|
||||
m = hashlib.md5()
|
||||
str = "%s-%s-%s-%s" % (user_info.uid, user_info.login_name, user_info.login_pwd, user_info.login_salt)
|
||||
m.update(str.encode("utf-8"))
|
||||
return m.hexdigest()
|
||||
|
||||
@staticmethod
|
||||
def genePwd( pwd,salt):
|
||||
m = hashlib.md5()
|
||||
str = "%s-%s" % ( base64.encodebytes( pwd.encode("utf-8") ) , salt)
|
||||
m.update(str.encode("utf-8"))
|
||||
return m.hexdigest()
|
||||
|
||||
@staticmethod
|
||||
def geneSalt( length = 16 ):
|
||||
keylist = [ random.choice( ( string.ascii_letters + string.digits ) ) for i in range( length ) ]
|
||||
return ( "".join( keylist ) )
|
||||
1
common/libs/user/__init__.py
Normal file
1
common/libs/user/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
22
common/models/User.py
Normal file
22
common/models/User.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# coding: utf-8
|
||||
from sqlalchemy import BigInteger, Column, DateTime, Integer, String
|
||||
from sqlalchemy.schema import FetchedValue
|
||||
from application import db
|
||||
|
||||
|
||||
|
||||
class User(db.Model):
|
||||
__tablename__ = 'user'
|
||||
|
||||
uid = db.Column(db.BigInteger, primary_key=True)
|
||||
nickname = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue())
|
||||
mobile = db.Column(db.String(20), nullable=False, server_default=db.FetchedValue())
|
||||
email = db.Column(db.String(100), nullable=False, server_default=db.FetchedValue())
|
||||
sex = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
|
||||
avatar = db.Column(db.String(64), nullable=False, server_default=db.FetchedValue())
|
||||
login_name = db.Column(db.String(20), nullable=False, unique=True, server_default=db.FetchedValue())
|
||||
login_pwd = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
|
||||
login_salt = db.Column(db.String(32), nullable=False, server_default=db.FetchedValue())
|
||||
status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
|
||||
updated_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
|
||||
created_time = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue())
|
||||
Reference in New Issue
Block a user