add login info into db

This commit is contained in:
Firmlyzhu 2018-09-16 16:18:06 +08:00
parent 987077e7d7
commit 7e470463b1
2 changed files with 25 additions and 2 deletions

View File

@ -7,7 +7,7 @@ Warning: in some early versions, "token" stand for the instance of class model.U
Original author: Liu Peidong
'''
from utils.model import db, User, UserGroup, Notification, UserUsage
from utils.model import db, User, UserGroup, Notification, UserUsage, LoginMsg
from functools import wraps
import os, subprocess, math
import hashlib
@ -144,6 +144,7 @@ class userManager:
'''
try:
User.query.all()
LoginMsg.query.all()
except:
db.create_all()
if password == None:
@ -268,6 +269,9 @@ class userManager:
username = result['username']
logger.info("External login success: username=%s, userip=%s" % (username, userip))
loginmsg = LoginMsg(username,userip)
db.session.add(loginmsg)
db.session.commit()
user = User.query.filter_by(username = username).first()
if (user != None and user.auth_method == result['auth_method']):
result = {
@ -332,6 +336,9 @@ class userManager:
result = {'success':'false', 'reason':'auth_method error'}
if result['success'] == 'true':
loginmsg = LoginMsg(result['data']['username'],userip)
db.session.add(loginmsg)
db.session.commit()
logger.info("Login success: username=%s, userip=%s" % (result['data']['username'], userip))
else:
logger.info("Login failed: userip=%s" % (userip))

View File

@ -43,7 +43,8 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+fsdir+'/global/sys/UserTabl
app.config['SQLALCHEMY_BINDS'] = {
'history': 'sqlite:///'+fsdir+'/global/sys/HistoryTable.db',
'beansapplication': 'sqlite:///'+fsdir+'/global/sys/BeansApplication.db',
'system': 'sqlite:///'+fsdir+'/global/sys/System.db'
'system': 'sqlite:///'+fsdir+'/global/sys/System.db',
'login': 'sqlite:///'+fsdir+'/global/sys/Login.db'
}
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
try:
@ -205,6 +206,21 @@ class UserNotificationPair(db.Model):
def __repr__(self):
return '<UserName: %r, NotifyId: %r>' % (self.userName, self.notifyId)
class LoginMsg(db.Model):
__bind_key__ = 'login'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(10))
userip = db.Column(db.String(20))
time = db.Column(db.DateTime)
def __init__(self, username, userip):
self.username = username
self.userip = userip
self.time = datetime.now()
def __repr__(self):
return '<id=%d, username=%s, userip=%s, time=%s>' % (self.id,self.username,self.userip,self.time.strftime("%Y-%m-%d %H:%M:%S"))
class VNode(db.Model):
__bind_key__ = 'history'
name = db.Column(db.String(100), primary_key=True)