Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added redirect after login for non-ajax requests #68

Merged
merged 1 commit into from Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 28 additions & 16 deletions app/handlers/AuthHandler.py
Expand Up @@ -51,28 +51,40 @@ def post(self):
session_token = FMAuth.authenticate_by_token(self, token)
if session_token:
FMLocale.set_language(self, language, session_token)
self.json({
'error': False,
'url': '/'
})
if self.is_ajax():
self.json({
'error': False,
'url': '/'
})
else:
self.redirect('/')
else:
self.json({
'error': True,
'message': self.get_user_locale().translate("Incorrect security token")
})
if self.is_ajax():
self.json({
'error': True,
'message': self.get_user_locale().translate("Incorrect security token")
})
else:
self.redirect('/')
else:
session_token = FMAuth.authenticate_by_pam(self, login, password)
if session_token:
FMLocale.set_language(self, language, session_token)
self.json({
'error': False,
'url': '/'
})
if self.is_ajax():
self.json({
'error': False,
'url': '/'
})
else:
self.redirect('/')
else:
self.json({
'error': True,
'message': self.get_user_locale().translate("Incorrect login or password")
})
if self.is_ajax():
self.json({
'error': True,
'message': self.get_user_locale().translate("Incorrect login or password")
})
else:
self.redirect('/')

self.finish()

Expand Down
6 changes: 6 additions & 0 deletions app/handlers/BaseHandler.py
Expand Up @@ -197,6 +197,12 @@ def get_user_locale(self):
except:
return tornado.locale.get(DEFAULT_LOCALE)

def is_ajax(self):
if 'X-Requested-With' in self.request.headers:
if self.request.headers['X-Requested-With'] == 'XMLHttpRequest':
return True
return False


def wrap_catch(method):
def catch(*args, **kwargs):
Expand Down