@@ -22,6 +22,7 @@ debug = true
#smtp_password =
#smtp_port =
#smtp_use_tls = false
#smtp_use_ssl = true
[server:main]
##nr of threads to spawn
@@ -230,15 +230,31 @@ def reset_user_password(user_email):
@task
def send_email(recipients, subject, body):
"""
Sends an email with defined parameters from the .ini files.
:param recipients: list of recipients, it this is empty the defined email
address from field 'email_to' is used instead
:param subject: subject of the mail
:param body: body of the mail
log = send_email.get_logger()
email_config = dict(config.items('DEFAULT'))
if not recipients:
recipients = [email_config.get('email_to')]
def str2bool(v):
return v.lower() in ["yes", "true", "t", "1"]
mail_from = email_config.get('app_email_from')
user = email_config.get('smtp_username')
passwd = email_config.get('smtp_password')
mail_server = email_config.get('smtp_server')
mail_port = email_config.get('smtp_port')
tls = email_config.get('smtp_use_tls')
ssl = False
tls = str2bool(email_config.get('smtp_use_tls'))
ssl = str2bool(email_config.get('smtp_use_ssl'))
try:
m = SmtpMailer(mail_from, user, passwd, mail_server,
@@ -47,7 +47,7 @@ class SmtpMailer(object):
if self.debug:
smtp_serv.set_debuglevel(1)
smtp_serv.ehlo("mailer")
smtp_serv.ehlo("rhodecode mailer")
#if server requires authorization you must provide login and password
smtp_serv.login(self.user, self.passwd)
@@ -68,9 +68,18 @@ def is_git(environ):
return True
return False
def action_logger(user, action, repo, ipaddr, sa=None):
def action_logger(user, action, repo, ipaddr='', sa=None):
Action logger for various action made by users
:param user: user that made this action, can be a string unique username or
object containing user_id attribute
:param action: action to log, should be on of predefined unique actions for
easy translations
:param repo: repository that action was made on
:param ipaddr: optional ip address from what the action was made
:param sa: optional sqlalchemy session
if not sa:
@@ -84,12 +93,22 @@ def action_logger(user, action, repo, ip
else:
raise Exception('You have to provide user object or username')
if repo:
repo_name = repo.lstrip('/')
repository = RepoModel(sa).get(repo_name, cache=False)
if not repository:
raise Exception('You have to provide valid repository')
raise Exception('You have to provide repository to action logger')
user_log = UserLog()
user_log.user_id = user_obj.user_id
user_log.action = action
user_log.repository_name = repo_name
user_log.repository = RepoModel(sa).get(repo_name, cache=False)
user_log.repository = repository
user_log.action_date = datetime.datetime.now()
user_log.user_ip = ipaddr
sa.add(user_log)
@@ -72,6 +72,7 @@ class UserModel(object):
raise
def create_registration(self, form_data):
from rhodecode.lib.celerylib import tasks, run_task
new_user = User()
for k, v in form_data.items():
@@ -80,6 +81,14 @@ class UserModel(object):
self.sa.add(new_user)
self.sa.commit()
body = ('New user registration\n'
'username: %s\n'
'email: %s\n')
body = body % (form_data['username'], form_data['email'])
run_task(tasks.send_email, None,
_('[RhodeCode] New User registration'),
body)
except:
log.error(traceback.format_exc())
self.sa.rollback()
Status change: