##// END OF EJS Templates
implements #222 registration feedback...
marcink -
r1731:31e6eb2f beta
parent child Browse files
Show More
@@ -0,0 +1,9 b''
1 ## -*- coding: utf-8 -*-
2 <%inherit file="main.html"/>
3
4 A new user have registered in RhodeCode
5
6 ${body}
7
8
9 View this user here :${registered_user_url} No newline at end of file
@@ -38,6 +38,7 b' from rhodecode.lib.base import BaseContr'
38 38 from rhodecode.model.db import User
39 39 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
40 40 from rhodecode.model.user import UserModel
41 from rhodecode.model.meta import Session
41 42
42 43
43 44 log = logging.getLogger(__name__)
@@ -109,6 +110,7 b' class LoginController(BaseController):'
109 110 user_model.create_registration(form_result)
110 111 h.flash(_('You have successfully registered into rhodecode'),
111 112 category='success')
113 Session().commit()
112 114 return redirect(url('login_home'))
113 115
114 116 except formencode.Invalid, errors:
@@ -283,6 +283,10 b' class User(Base, BaseModel):'
283 283 notifications = relationship('UserNotification',)
284 284
285 285 @property
286 def full_name(self):
287 return '%s %s' % (self.name, self.lastname)
288
289 @property
286 290 def full_contact(self):
287 291 return '%s %s <%s>' % (self.name, self.lastname, self.email)
288 292
@@ -1170,6 +1174,7 b' class Notification(Base, BaseModel):'
1170 1174 TYPE_CHANGESET_COMMENT = u'cs_comment'
1171 1175 TYPE_MESSAGE = u'message'
1172 1176 TYPE_MENTION = u'mention'
1177 TYPE_REGISTRATION = u'registration'
1173 1178
1174 1179 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
1175 1180 subject = Column('subject', Unicode(512), nullable=True)
@@ -57,8 +57,9 b' class NotificationModel(BaseModel):'
57 57 raise Exception('notification must be int or Instance'
58 58 ' of Notification got %s' % type(notification))
59 59
60 def create(self, created_by, subject, body, recipients,
61 type_=Notification.TYPE_MESSAGE):
60 def create(self, created_by, subject, body, recipients=None,
61 type_=Notification.TYPE_MESSAGE, with_email=True,
62 email_kwargs={}):
62 63 """
63 64
64 65 Creates notification of given type
@@ -67,35 +68,46 b' class NotificationModel(BaseModel):'
67 68 notification
68 69 :param subject:
69 70 :param body:
70 :param recipients: list of int, str or User objects
71 :param recipients: list of int, str or User objects, when None
72 is given send to all admins
71 73 :param type_: type of notification
74 :param with_email: send email with this notification
75 :param email_kwargs: additional dict to pass as args to email template
72 76 """
73 77 from rhodecode.lib.celerylib import tasks, run_task
74 78
75 if not getattr(recipients, '__iter__', False):
79 if recipients and not getattr(recipients, '__iter__', False):
76 80 raise Exception('recipients must be a list of iterable')
77 81
78 82 created_by_obj = self.__get_user(created_by)
79 83
80 recipients_objs = []
81 for u in recipients:
82 obj = self.__get_user(u)
83 if obj:
84 recipients_objs.append(obj)
85 recipients_objs = set(recipients_objs)
84 if recipients:
85 recipients_objs = []
86 for u in recipients:
87 obj = self.__get_user(u)
88 if obj:
89 recipients_objs.append(obj)
90 recipients_objs = set(recipients_objs)
91 else:
92 # empty recipients means to all admins
93 recipients_objs = User.query().filter(User.admin == True).all()
86 94
87 95 notif = Notification.create(created_by=created_by_obj, subject=subject,
88 96 body=body, recipients=recipients_objs,
89 97 type_=type_)
90 98
99 if with_email is False:
100 return notif
101
91 102 # send email with notification
92 103 for rec in recipients_objs:
93 104 email_subject = NotificationModel().make_description(notif, False)
94 type_ = EmailNotificationModel.TYPE_CHANGESET_COMMENT
105 type_ = type_
95 106 email_body = body
107 kwargs = {'subject':subject, 'body':h.rst(body)}
108 kwargs.update(email_kwargs)
96 109 email_body_html = EmailNotificationModel()\
97 .get_email_tmpl(type_, **{'subject':subject,
98 'body':h.rst(body)})
110 .get_email_tmpl(type_, **kwargs)
99 111 run_task(tasks.send_email, rec.email, email_subject, email_body,
100 112 email_body_html)
101 113
@@ -150,7 +162,9 b' class NotificationModel(BaseModel):'
150 162
151 163 _map = {notification.TYPE_CHANGESET_COMMENT:_('commented on commit'),
152 164 notification.TYPE_MESSAGE:_('sent message'),
153 notification.TYPE_MENTION:_('mentioned you')}
165 notification.TYPE_MENTION:_('mentioned you'),
166 notification.TYPE_REGISTRATION:_('registered in RhodeCode')}
167
154 168 DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
155 169
156 170 tmpl = "%(user)s %(action)s %(when)s"
@@ -26,6 +26,7 b''
26 26 import logging
27 27 import traceback
28 28
29 from pylons import url
29 30 from pylons.i18n.translation import _
30 31
31 32 from rhodecode.lib import safe_unicode
@@ -33,7 +34,8 b' from rhodecode.lib.caching_query import '
33 34
34 35 from rhodecode.model import BaseModel
35 36 from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \
36 UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember
37 UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \
38 Notification
37 39 from rhodecode.lib.exceptions import DefaultUserException, \
38 40 UserOwnsReposException
39 41
@@ -43,6 +45,7 b' from sqlalchemy.orm import joinedload'
43 45
44 46 log = logging.getLogger(__name__)
45 47
48
46 49 PERM_WEIGHTS = {'repository.none': 0,
47 50 'repository.read': 1,
48 51 'repository.write': 3,
@@ -211,7 +214,8 b' class UserModel(BaseModel):'
211 214 return None
212 215
213 216 def create_registration(self, form_data):
214 from rhodecode.lib.celerylib import tasks, run_task
217 from rhodecode.model.notification import NotificationModel
218
215 219 try:
216 220 new_user = User()
217 221 for k, v in form_data.items():
@@ -219,18 +223,26 b' class UserModel(BaseModel):'
219 223 setattr(new_user, k, v)
220 224
221 225 self.sa.add(new_user)
222 self.sa.commit()
226 self.sa.flush()
227
228 # notification to admins
229 subject = _('new user registration')
223 230 body = ('New user registration\n'
224 'username: %s\n'
225 'email: %s\n')
226 body = body % (form_data['username'], form_data['email'])
231 '---------------------\n'
232 '- Username: %s\n'
233 '- Full Name: %s\n'
234 '- Email: %s\n')
235 body = body % (new_user.username, new_user.full_name,
236 new_user.email)
237 edit_url = url('edit_user', id=new_user.user_id, qualified=True)
238 kw = {'registered_user_url':edit_url}
239 NotificationModel().create(created_by=new_user, subject=subject,
240 body=body, recipients=None,
241 type_=Notification.TYPE_REGISTRATION,
242 email_kwargs=kw)
227 243
228 run_task(tasks.send_email, None,
229 _('[RhodeCode] New User registration'),
230 body)
231 244 except:
232 245 log.error(traceback.format_exc())
233 self.sa.rollback()
234 246 raise
235 247
236 248 def update(self, user_id, form_data):
General Comments 0
You need to be logged in to leave comments. Login now