##// END OF EJS Templates
fixes #59, notifications for user registrations + some changes to mailer
marcink -
r689:ecc566f8 beta
parent child Browse files
Show More
@@ -22,6 +22,7 b' debug = true'
22 22 #smtp_password =
23 23 #smtp_port =
24 24 #smtp_use_tls = false
25 #smtp_use_ssl = true
25 26
26 27 [server:main]
27 28 ##nr of threads to spawn
@@ -22,6 +22,7 b' debug = true'
22 22 #smtp_password =
23 23 #smtp_port =
24 24 #smtp_use_tls = false
25 #smtp_use_ssl = true
25 26
26 27 [server:main]
27 28 ##nr of threads to spawn
@@ -230,15 +230,31 b' def reset_user_password(user_email):'
230 230
231 231 @task
232 232 def send_email(recipients, subject, body):
233 """
234 Sends an email with defined parameters from the .ini files.
235
236
237 :param recipients: list of recipients, it this is empty the defined email
238 address from field 'email_to' is used instead
239 :param subject: subject of the mail
240 :param body: body of the mail
241 """
233 242 log = send_email.get_logger()
234 243 email_config = dict(config.items('DEFAULT'))
244
245 if not recipients:
246 recipients = [email_config.get('email_to')]
247
248 def str2bool(v):
249 return v.lower() in ["yes", "true", "t", "1"]
250
235 251 mail_from = email_config.get('app_email_from')
236 252 user = email_config.get('smtp_username')
237 253 passwd = email_config.get('smtp_password')
238 254 mail_server = email_config.get('smtp_server')
239 255 mail_port = email_config.get('smtp_port')
240 tls = email_config.get('smtp_use_tls')
241 ssl = False
256 tls = str2bool(email_config.get('smtp_use_tls'))
257 ssl = str2bool(email_config.get('smtp_use_ssl'))
242 258
243 259 try:
244 260 m = SmtpMailer(mail_from, user, passwd, mail_server,
@@ -47,7 +47,7 b' class SmtpMailer(object):'
47 47 if self.debug:
48 48 smtp_serv.set_debuglevel(1)
49 49
50 smtp_serv.ehlo("mailer")
50 smtp_serv.ehlo("rhodecode mailer")
51 51
52 52 #if server requires authorization you must provide login and password
53 53 smtp_serv.login(self.user, self.passwd)
@@ -68,9 +68,18 b' def is_git(environ):'
68 68 return True
69 69 return False
70 70
71 def action_logger(user, action, repo, ipaddr, sa=None):
71 def action_logger(user, action, repo, ipaddr='', sa=None):
72 72 """
73 73 Action logger for various action made by users
74
75 :param user: user that made this action, can be a string unique username or
76 object containing user_id attribute
77 :param action: action to log, should be on of predefined unique actions for
78 easy translations
79 :param repo: repository that action was made on
80 :param ipaddr: optional ip address from what the action was made
81 :param sa: optional sqlalchemy session
82
74 83 """
75 84
76 85 if not sa:
@@ -84,12 +93,22 b' def action_logger(user, action, repo, ip'
84 93 else:
85 94 raise Exception('You have to provide user object or username')
86 95
96
97 if repo:
87 98 repo_name = repo.lstrip('/')
99
100 repository = RepoModel(sa).get(repo_name, cache=False)
101 if not repository:
102 raise Exception('You have to provide valid repository')
103 else:
104 raise Exception('You have to provide repository to action logger')
105
106
88 107 user_log = UserLog()
89 108 user_log.user_id = user_obj.user_id
90 109 user_log.action = action
91 110 user_log.repository_name = repo_name
92 user_log.repository = RepoModel(sa).get(repo_name, cache=False)
111 user_log.repository = repository
93 112 user_log.action_date = datetime.datetime.now()
94 113 user_log.user_ip = ipaddr
95 114 sa.add(user_log)
@@ -72,6 +72,7 b' class UserModel(object):'
72 72 raise
73 73
74 74 def create_registration(self, form_data):
75 from rhodecode.lib.celerylib import tasks, run_task
75 76 try:
76 77 new_user = User()
77 78 for k, v in form_data.items():
@@ -80,6 +81,14 b' class UserModel(object):'
80 81
81 82 self.sa.add(new_user)
82 83 self.sa.commit()
84 body = ('New user registration\n'
85 'username: %s\n'
86 'email: %s\n')
87 body = body % (form_data['username'], form_data['email'])
88
89 run_task(tasks.send_email, None,
90 _('[RhodeCode] New User registration'),
91 body)
83 92 except:
84 93 log.error(traceback.format_exc())
85 94 self.sa.rollback()
General Comments 0
You need to be logged in to leave comments. Login now