Add information of login to user log
This commit is contained in:
parent
46ea09828d
commit
987077e7d7
|
@ -254,7 +254,7 @@ class userManager:
|
|||
}
|
||||
return result
|
||||
|
||||
def auth_external(self, form):
|
||||
def auth_external(self, form, userip=""):
|
||||
|
||||
if (env.getenv('EXTERNAL_LOGIN') != 'True'):
|
||||
failed_result = {'success': 'false', 'reason' : 'external auth disabled'}
|
||||
|
@ -267,6 +267,7 @@ class userManager:
|
|||
return failed_result
|
||||
|
||||
username = result['username']
|
||||
logger.info("External login success: username=%s, userip=%s" % (username, userip))
|
||||
user = User.query.filter_by(username = username).first()
|
||||
if (user != None and user.auth_method == result['auth_method']):
|
||||
result = {
|
||||
|
@ -316,19 +317,25 @@ class userManager:
|
|||
}
|
||||
return result
|
||||
|
||||
def auth(self, username, password):
|
||||
def auth(self, username, password, userip=""):
|
||||
'''
|
||||
authenticate a user by username & password
|
||||
return a token as well as some user information
|
||||
'''
|
||||
user = User.query.filter_by(username = username).first()
|
||||
result = {}
|
||||
if (user == None or user.auth_method =='pam'):
|
||||
return self.auth_pam(username, password)
|
||||
result = self.auth_pam(username, password)
|
||||
elif (user.auth_method == 'local'):
|
||||
return self.auth_local(username, password)
|
||||
result = self.auth_local(username, password)
|
||||
else:
|
||||
result = {'success':'false', 'reason':'auth_method error'}
|
||||
return result
|
||||
|
||||
if result['success'] == 'true':
|
||||
logger.info("Login success: username=%s, userip=%s" % (result['data']['username'], userip))
|
||||
else:
|
||||
logger.info("Login failed: userip=%s" % (userip))
|
||||
return result
|
||||
|
||||
def auth_token(self, token):
|
||||
'''
|
||||
|
|
|
@ -87,9 +87,10 @@ def login():
|
|||
logger.info("handle request : user login")
|
||||
user = request.form.get("user", None)
|
||||
key = request.form.get("key", None)
|
||||
userip = request.form.get("ip", "")
|
||||
if user == None or key == None:
|
||||
return json.dumps({'success': 'false', 'message':'user or key is null'})
|
||||
auth_result = G_usermgr.auth(user,key)
|
||||
auth_result = G_usermgr.auth(user,key,userip)
|
||||
if auth_result['success'] == 'false':
|
||||
logger.info("%s login failed" % user)
|
||||
return json.dumps({'success':'false', 'message':'auth failed'})
|
||||
|
@ -100,8 +101,9 @@ def login():
|
|||
def external_login():
|
||||
global G_usermgr
|
||||
logger.info("handle request : external user login")
|
||||
userip = request.form.get("ip", "")
|
||||
try:
|
||||
result = G_usermgr.auth_external(request.form)
|
||||
result = G_usermgr.auth_external(request.form,userip)
|
||||
return json.dumps(result)
|
||||
except:
|
||||
result = {'success':'false', 'reason':'Something wrong happened when auth an external account'}
|
||||
|
|
|
@ -52,7 +52,7 @@ class loginView(normalView):
|
|||
@classmethod
|
||||
def post(self):
|
||||
if (request.form['username']):
|
||||
data = {"user": request.form['username'], "key": request.form['password']}
|
||||
data = {"user": request.form['username'], "key": request.form['password'], 'ip': request.remote_addr}
|
||||
result = dockletRequest.unauthorizedpost('/login/', data)
|
||||
ok = result and result.get('success', None)
|
||||
if (ok and (ok == "true")):
|
||||
|
|
Loading…
Reference in New Issue