# HG changeset patch --
Bitbucket.org
# Project galaxy-dist
# URL
http://bitbucket.org/galaxy/galaxy-dist/overview
# User Nate Coraor <nate(a)bx.psu.edu>
# Date 1277754926 14400
# Node ID 10027d1e6dc31200319f9d90a4d8233170393f2b
# Parent eea2c040ccb7bd0d2a7c6e5eab8e65f98a163009
Switch methods using sendmail to SMTP instead.
--- a/lib/galaxy/web/controllers/user.py
+++ b/lib/galaxy/web/controllers/user.py
@@ -4,8 +4,9 @@ Contains the user interface in the Unive
from galaxy.web.base.controller import *
from galaxy.model.orm import *
from galaxy import util
-import logging, os, string, re
+import logging, os, string, re, smtplib, socket
from random import choice
+from email.MIMEText import MIMEText
from galaxy.web.form_builder import *
from galaxy.util.json import from_json_string, to_json_string
from galaxy.web.framework.helpers import iff
@@ -152,10 +153,20 @@ class User( BaseController ):
self.__save_user_info( trans, user, action='create',
new_user=True, **kwd )
if subscribe_checked:
# subscribe user to email list
- mail = os.popen( "%s -t" %
trans.app.config.sendmail_path, 'w' )
- mail.write( "To: %s\nFrom: %s\nSubject: Join Mailing
List\n\nJoin Mailing list." % ( trans.app.config.mailing_join_addr,email ) )
- if mail.close():
- error = "Now logged in as " + user.email + ".
However, subscribing to the mailing list has failed."
+ if trans.app.config.smtp_server is None:
+ error = "Now logged in as " + user.email + ".
However, subscribing to the mailing list has failed because mail is not configured for
this Galaxy instance."
+ else:
+ msg = MIMEText( 'Join Mailing list.\n' )
+ to = msg[ 'To' ] =
trans.app.config.mailing_join_addr
+ frm = msg[ 'From' ] = email
+ msg[ 'Subject' ] = 'Join Mailing List'
+ try:
+ s = smtplib.SMTP()
+ s.connect( trans.app.config.smtp_server )
+ s.sendmail( frm, [ to ], msg.as_string() )
+ s.close()
+ except:
+ error = "Now logged in as " + user.email +
". However, subscribing to the mailing list has failed."
if not error and not admin_view:
# The handle_user_login() method has a call to the
history_set_default_permissions() method
# (needed when logging in with a history), user needs to have
default permissions set before logging in
@@ -594,6 +605,8 @@ class User( BaseController ):
webapp=webapp ) )
@web.expose
def reset_password( self, trans, email=None, webapp='galaxy', **kwd ):
+ if trans.app.config.smtp_server is None:
+ return trans.show_error_message( "Mail is not configured for this Galaxy
instance. Please contact an administrator." )
message = util.restore_text( kwd.get( 'message', '' ) )
status = 'done'
if kwd.get( 'reset_password_button', False ):
@@ -608,20 +621,30 @@ class User( BaseController ):
new_pass = ""
for i in range(15):
new_pass = new_pass + choice(chars)
- mail = os.popen("%s -t" % trans.app.config.sendmail_path,
'w')
- mail.write("To: %s\nFrom: no-reply(a)nowhere.edu\nSubject: Galaxy
Password Reset\n\nYour password has been reset to \"%s\" (no quotes)." %
(email, new_pass) )
- if mail.close():
- message = 'Failed to reset password. If this problem
persists, please submit a bug report.'
+ host = trans.request.host.split(':')[0]
+ if host == 'localhost':
+ host = socket.getfqdn()
+ msg = MIMEText( 'Your password on %s has been reset to:\n\n
%s\n' % ( host, new_pass ) )
+ to = msg[ 'To' ] = email
+ frm = msg[ 'From' ] = 'galaxy-no-reply@' + host
+ msg[ 'Subject' ] = 'Galaxy Password Reset'
+ try:
+ s = smtplib.SMTP()
+ s.connect( trans.app.config.smtp_server )
+ s.sendmail( frm, [ to ], msg.as_string() )
+ s.close()
+ reset_user.set_password_cleartext( new_pass )
+ trans.sa_session.add( reset_user )
+ trans.sa_session.flush()
+ trans.log_event( "User reset password: %s" % email )
+ message = "Password has been reset and emailed to: %s.
<a href='%s'>Click here</a> to return to the login form." % (
email, web.url_for( action='login' ) )
+ except Exception, e:
+ message = 'Failed to reset password: %s' % str( e )
status = 'error'
- reset_user.set_password_cleartext( new_pass )
- trans.sa_session.add( reset_user )
- trans.sa_session.flush()
- trans.log_event( "User reset password: %s" % email )
- message = "Password has been reset and emailed to: %s. <a
href='%s'>Click here</a> to return to the login form." % ( email,
web.url_for( action='login' ) )
return trans.response.send_redirect( web.url_for(
controller='user',
action='reset_password',
message=message,
-
status='done' ) )
+ status=status ) )
elif email != None:
message = "The specified user does not exist"
status = 'error'
--- a/templates/user/register.mako
+++ b/templates/user/register.mako
@@ -72,13 +72,15 @@
letters, numbers, and the '-' character.
</div></div>
- <div class="form-row">
- <label>Subscribe to mailing list:</label>
- %if subscribe_checked:
- <% subscribe_check_box.checked = True %>
- %endif
- ${subscribe_check_box.get_html()}
- </div>
+ %if trans.app.config.smtp_server:
+ <div class="form-row">
+ <label>Subscribe to mailing list:</label>
+ %if subscribe_checked:
+ <% subscribe_check_box.checked = True %>
+ %endif
+ ${subscribe_check_box.get_html()}
+ </div>
+ %endif
%if user_info_select:
<div class="form-row"><label>User
type</label>
--- a/lib/galaxy/web/controllers/requests_admin.py
+++ b/lib/galaxy/web/controllers/requests_admin.py
@@ -4,9 +4,10 @@ from galaxy.model.orm import *
from galaxy.datatypes import sniff
from galaxy import model, util
from galaxy.util.streamball import StreamBall
-import logging, tempfile, zipfile, tarfile, os, sys, subprocess
+import logging, tempfile, zipfile, tarfile, os, sys, subprocess, smtplib, socket
from galaxy.web.form_builder import *
from datetime import datetime, timedelta
+from email.MIMEText import MIMEText
from galaxy.web.controllers.forms import get_all_forms
from sqlalchemy.sql.expression import func, and_
from sqlalchemy.sql import select
@@ -1403,13 +1404,21 @@ class RequestsAdmin( BaseController ):
trans.sa_session.flush()
# now that the request is complete send the email notification to the
# the user
- if request.notify:
- mail = os.popen("%s -t" % trans.app.config.sendmail_path,
'w')
- subject = "Galaxy Sample Tracking: '%s' sequencing request
in complete." % request.name
- body = "The '%s' sequencing request (type: %s) is now
complete. Datasets from all the samples are now available for analysis or download from
the respective data libraries in Galaxy." % (request.name, request.type.name)
- email_content = "To: %s\nFrom: no-reply(a)nowhere.edu\nSubject:
%s\n\n%s" % (request.user.email, subject, body)
- mail.write( email_content )
- x = mail.close()
+ if request.notify and trans.app.config.smtp_server is not None:
+ host = trans.request.host.split(':')[0]
+ if host == 'localhost':
+ host = socket.getfqdn()
+ msg = MIMEText( "The '%s' sequencing request (type: %s) is
now complete. Datasets from all the samples are now available for analysis or download
from the respective data libraries in Galaxy." % ( request.name, request.type.name )
)
+ to = msg[ 'To' ] = request.user.email
+ frm = msg[ 'From' ] = 'galaxy-no-reply@' + host
+ msg[ 'Subject' ] = "Galaxy Sample Tracking: '%s'
sequencing request in complete." % request.name
+ try:
+ s = smtplib.SMTP()
+ s.connect( trans.app.config.smtp_server )
+ s.sendmail( frm, [ to ], msg.as_string() )
+ s.close()
+ except:
+ pass
def change_state(self, trans, sample):
possible_states = sample.request.type.states
curr_state = sample.current_state()