From ced6197dfd5c0da74c4aa6b0b102e9883b6a1dfb Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 27 2015 15:07:11 +0000 Subject: Add method in the internal API to the user_emails_pending table --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index f4d4349..ec99d1e 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -1503,3 +1503,35 @@ def add_user_pending_email(session, userobj, email): session.flush() pagure.lib.notify.notify_new_email(tmpemail, user=userobj) + + +def search_pending_email(session, email=None, token=None): + ''' Searches the database for the pending email matching the given + criterias. + + :arg session: the session to use to connect to the database. + :kwarg email: the email to look for + :type email: string or None + :kwarg token: the token of the pending email to look for + :type token: string or None + :return: A single UserEmailPending object + :rtype: UserEmailPending + + ''' + query = session.query( + model.UserEmailPending + ) + + if email is not None: + query = query.filter( + model.UserEmailPending.email == email + ) + + if token is not None: + query = query.filter( + model.UserEmailPending.token == token + ) + + output = query.first() + + return output