コード例 #1
0
ファイル: User.py プロジェクト: toebbel/splitpot
def doMerge(email=None, key=None):
    """
Merge two accounts together. Will send a confirmation mail to the to-be-merged email.
"""

    tmpl = lookup.get_template('profile.html')

    errors = ''
    if key is not None and isValidMergeUrlKey(key):

        newMail = getUserFromPassword(key[:8])
        oldMail = getUserFromPassword(key[8:])

        log.info('valid merging key, merging "' + newMail + '" and "'
                 + oldMail + '" now')
        if mergeUser(newMail, oldMail):
            tmpl = lookup.get_template('index.html')
            return tmpl.render(good_news='Merge was successful!')
        else:
            log.warning('couldn\'t merge "' + newMail + '" and "'
                        + oldMail + '" for some unexpected reason')
            return tmpl.render(feedback='Oh no! Something went wrong. Please try again later.'
                               )
    elif email is not None:

        log.info('merge "' + email.lower() + '" with "'
                 + getCurrentUserName() + '"')
        if emailRegex.match(email) == None:
            errors += '<li>Your email is invalid</li>'
        elif not userExists(email, True):
            errors += '<li>' + str(email.lower()) \
                + ' doesn\'t exist</li>'
        if userExists(getCurrentUserName()):
            events = listAllEventsFor(getCurrentUserName())
            for event in events:
                if str(event.participants).find(email) != -1:
                    log.info('found instance where "' + email.lower()
                             + '" and "' + getCurrentUserName().lower()
                             + '" are listed as hoster and participant. Can\'t merge'
                             )
                    errors = \
                        '<li>Can\'t merge these two accounts, because there are events, where host and participant are the same person.</li>'
                if str(event.owner).find(email) != -1:
                    log.info('found instance where owner and to-be-merged user are the same'
                             )
                    errors = '<li>Can\'t merge two same accounts.</li>'
        if not errors == '':
            return tmpl.render(bad_news='<ul>' + errors + '</ul>')
        else:
            mergeKey = getMergeUrlKey(getCurrentUserName(), email)
            Email.mergeRequest(getCurrentUserName(), email, mergeKey)

            return tmpl.render(good_news='An email has be sent to "'
                               + email.lower()
                               + '" for further information')
    else:
        tmpl = lookup.get_template('index.html')
        return tmpl.render(bad_news="Something went wrong, merge wasn't successful (maybe you already merged?)"
                           )
コード例 #2
0
ファイル: Splitpot.py プロジェクト: Jupiterrr/splitpot
    def doMerge(self, email=None, key=None):
        """
    Merge two accounts together. Will send a confirmation mail to the to-be-merged email.
    """

        tmpl = lookup.get_template("merge.html")

        errors = ""
        if key is not None and isValidMergeUrlKey(key):

            newMail = getUserFromPassword(key[:8])
            oldMail = getUserFromPassword(key[8:])

            log.info('valid merging key, merging "' + newMail + '" and "' + oldMail + '" now')
            if mergeUser(newMail, oldMail):
                return self.index()
            else:
                log.warning("couldn't merge \"" + newMail + '" and "' + oldMail + '" for some unexpected reason')
                return tmpl.render(
                    feedback="Oh no! Something went wrong. Please try again later.", newUser=getCurrentUserName()
                )
        else:

            log.info('merge "' + email.lower() + '" with "' + getCurrentUserName() + '"')
            if email is None:
                errors += "<li>You have to provide an email address</li>"
            if emailRegex.match(email) == None:
                errors += "<li>Your email is invalid</li>"
            elif not userExists(email, True):
                errors += "<li>" + str(email.lower()) + " doesn't exist</li>"
            if userExists(getCurrentUserName()):
                events = listAllEventsFor(getCurrentUserName())
                for event in events:
                    if str(event.participants).find(email) != -1:
                        log.info(
                            'found instance where "'
                            + email.lower()
                            + '" and "'
                            + getCurrentUserName().lower()
                            + "\" are listed as hoster and participant. Can't merge"
                        )
                        errors = "<li>Can't merge these two accounts, because there are events, where host and participant are the same person.</li>"
                    if str(event.owner).find(email) != -1:
                        log.info("found instance where owner and to-be-merged user are the same")
                        errors = "<li>Can't merge two same accounts.</li>"
            if not errors == "":
                return tmpl.render(bad_news="<ul>" + errors + "</ul>", newUser=getCurrentUserName())
            else:
                mergeKey = getMergeUrlKey(getCurrentUserName(), email)
                Email.mergeRequest(getCurrentUserName(), email, mergeKey)

                return tmpl.render(
                    good_news='An email has be sent to "' + email.lower() + '" for further information',
                    newUser=getCurrentUserName(),
                )