add login info into db
This commit is contained in:
parent
987077e7d7
commit
7e470463b1
|
@ -7,7 +7,7 @@ Warning: in some early versions, "token" stand for the instance of class model.U
|
||||||
Original author: Liu Peidong
|
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
|
from functools import wraps
|
||||||
import os, subprocess, math
|
import os, subprocess, math
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -144,6 +144,7 @@ class userManager:
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
User.query.all()
|
User.query.all()
|
||||||
|
LoginMsg.query.all()
|
||||||
except:
|
except:
|
||||||
db.create_all()
|
db.create_all()
|
||||||
if password == None:
|
if password == None:
|
||||||
|
@ -268,6 +269,9 @@ class userManager:
|
||||||
|
|
||||||
username = result['username']
|
username = result['username']
|
||||||
logger.info("External login success: username=%s, userip=%s" % (username, userip))
|
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()
|
user = User.query.filter_by(username = username).first()
|
||||||
if (user != None and user.auth_method == result['auth_method']):
|
if (user != None and user.auth_method == result['auth_method']):
|
||||||
result = {
|
result = {
|
||||||
|
@ -332,6 +336,9 @@ class userManager:
|
||||||
result = {'success':'false', 'reason':'auth_method error'}
|
result = {'success':'false', 'reason':'auth_method error'}
|
||||||
|
|
||||||
if result['success'] == 'true':
|
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))
|
logger.info("Login success: username=%s, userip=%s" % (result['data']['username'], userip))
|
||||||
else:
|
else:
|
||||||
logger.info("Login failed: userip=%s" % (userip))
|
logger.info("Login failed: userip=%s" % (userip))
|
||||||
|
|
|
@ -43,7 +43,8 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+fsdir+'/global/sys/UserTabl
|
||||||
app.config['SQLALCHEMY_BINDS'] = {
|
app.config['SQLALCHEMY_BINDS'] = {
|
||||||
'history': 'sqlite:///'+fsdir+'/global/sys/HistoryTable.db',
|
'history': 'sqlite:///'+fsdir+'/global/sys/HistoryTable.db',
|
||||||
'beansapplication': 'sqlite:///'+fsdir+'/global/sys/BeansApplication.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
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||||
try:
|
try:
|
||||||
|
@ -205,6 +206,21 @@ class UserNotificationPair(db.Model):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<UserName: %r, NotifyId: %r>' % (self.userName, self.notifyId)
|
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):
|
class VNode(db.Model):
|
||||||
__bind_key__ = 'history'
|
__bind_key__ = 'history'
|
||||||
name = db.Column(db.String(100), primary_key=True)
|
name = db.Column(db.String(100), primary_key=True)
|
||||||
|
|
Loading…
Reference in New Issue