'Check whether token fits the user and then activate the user\'s account.'

@web.expose
def activate(self, trans, **kwd):

    params = util.Params(kwd, sanitize=False)
    email = urllib.unquote(params.get('email', None))
    activation_token = params.get('activation_token', None)
    if ((email is None) or (activation_token is None)):
        return (trans.show_error_message("You    are    using    an    invalid    activation    link.    Try    to    log    in    and    we    will    send    you    a    new    activation    email.    <br><a    href='%s'>Go    to    login    page.</a>") % web.url_for(controller='root', action='index'))
    else:
        user = trans.sa_session.query(trans.app.model.User).filter((trans.app.model.User.table.c.email == email)).first()
        if (user.active is True):
            return (trans.show_ok_message("Your    account    is    already    active.    Nothing    has    changed.    <br><a    href='%s'>Go    to    login    page.</a>") % web.url_for(controller='root', action='index'))
        if (user.activation_token == activation_token):
            user.activation_token = None
            user.active = True
            trans.sa_session.add(user)
            trans.sa_session.flush()
            return (trans.show_ok_message("Your    account    has    been    successfully    activated!    <br><a    href='%s'>Go    to    login    page.</a>") % web.url_for(controller='root', action='index'))
        else:
            return (trans.show_error_message("You    are    using    an    invalid    activation    link.    Try    to    log    in    and    we    will    send    you    a    new    activation    email.    <br><a    href='%s'>Go    to    login    page.</a>") % web.url_for(controller='root', action='index'))
    return
