'Reset the user\'s password. Send an email with token that allows a password change.'

@web.expose
def reset_password(self, trans, email=None, **kwd):

    if (trans.app.config.smtp_server is None):
        return trans.show_error_message('Mail    is    not    configured    for    this    Galaxy    instance    and    password    reset    information    cannot    be    sent.    Please    contact    your    local    Galaxy    administrator.')
    message = None
    status = 'done'
    if kwd.get('reset_password_button', False):
        message = validate_email(trans, email, check_dup=False)
        if (not message):
            message = ('Your    reset    request    for    %s    has    been    received.        Please    check    your    email    account    for    more    instructions.        If    you    do    not    receive    an    email    shortly,    please    contact    an    administrator.' % escape(email))
            reset_user = trans.sa_session.query(trans.app.model.User).filter((trans.app.model.User.table.c.email == email)).first()
            if (not reset_user):
                reset_user = trans.sa_session.query(trans.app.model.User).filter((func.lower(trans.app.model.User.table.c.email) == func.lower(email))).first()
            if reset_user:
                prt = trans.app.model.PasswordResetToken(reset_user)
                trans.sa_session.add(prt)
                trans.sa_session.flush()
                host = trans.request.host.split(':')[0]
                if (host in ['localhost', '127.0.0.1', '0.0.0.0']):
                    host = socket.getfqdn()
                reset_url = url_for(controller='user', action='change_password', token=prt.token, qualified=True)
                body = (PASSWORD_RESET_TEMPLATE % (host, prt.expiration_time.strftime(trans.app.config.pretty_datetime_format), reset_url))
                frm = (trans.app.config.email_from or ('galaxy-no-reply@' + host))
                subject = 'Galaxy    Password    Reset'
                try:
                    util.send_mail(frm, email, subject, body, trans.app.config)
                    trans.sa_session.add(reset_user)
                    trans.sa_session.flush()
                    trans.log_event(('User    reset    password:    %s' % email))
                except Exception:
                    log.exception('Unable    to    reset    password.')
    return trans.fill_template('/user/reset_password.mako', message=message, status=status)
