# HG changeset patch # User Andrew Shadura # Date 1454168306 -3600 # Node ID 52356a58c1f6a828eb64f8236ce50dbc830afbe2 # Parent b24e015a4174e5633ee131d6776ed574dfa4be07 middleware: allow git and hg users to use email address instead of the username This commit also replaces __get_user('default') with a call to a more widely used User.get_default_user() function, and removes no longer really used __get_user() methods from both SimpleHg and SimpleGit. diff -r b24e015a4174 -r 52356a58c1f6 kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py Sat Jan 30 16:37:43 2016 +0100 +++ b/kallithea/lib/middleware/simplegit.py Sat Jan 30 16:38:26 2016 +0100 @@ -99,7 +99,7 @@ # CHECK ANONYMOUS PERMISSION #====================================================================== if action in ['pull', 'push']: - anonymous_user = self.__get_user('default') + anonymous_user = User.get_default_user(cache=True) username = anonymous_user.username if anonymous_user.active: # ONLY check permissions if the user is activated @@ -146,7 +146,7 @@ # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME #============================================================== try: - user = self.__get_user(username) + user = User.get_by_username_or_email(username) if user is None or not user.active: return HTTPForbidden()(environ, start_response) username = user.username @@ -248,9 +248,6 @@ return repo_name - def __get_user(self, username): - return User.get_by_username(username) - def __get_action(self, environ): """ Maps git request commands into a pull or push command. diff -r b24e015a4174 -r 52356a58c1f6 kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py Sat Jan 30 16:37:43 2016 +0100 +++ b/kallithea/lib/middleware/simplehg.py Sat Jan 30 16:38:26 2016 +0100 @@ -105,7 +105,7 @@ # CHECK ANONYMOUS PERMISSION #====================================================================== if action in ['pull', 'push']: - anonymous_user = self.__get_user('default') + anonymous_user = User.get_default_user(cache=True) username = anonymous_user.username if anonymous_user.active: # ONLY check permissions if the user is activated @@ -152,7 +152,7 @@ # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME #============================================================== try: - user = self.__get_user(username) + user = User.get_by_username_or_email(username) if user is None or not user.active: return HTTPForbidden()(environ, start_response) username = user.username @@ -248,9 +248,6 @@ return repo_name - def __get_user(self, username): - return User.get_by_username(username) - def __get_action(self, environ): """ Maps mercurial request commands into a clone,pull or push command.