##// 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 from rhodecode.model.db import User
38 from rhodecode.model.db import User
39 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
39 from rhodecode.model.forms import LoginForm, RegisterForm, PasswordResetForm
40 from rhodecode.model.user import UserModel
40 from rhodecode.model.user import UserModel
41 from rhodecode.model.meta import Session
41
42
42
43
43 log = logging.getLogger(__name__)
44 log = logging.getLogger(__name__)
@@ -109,6 +110,7 b' class LoginController(BaseController):'
109 user_model.create_registration(form_result)
110 user_model.create_registration(form_result)
110 h.flash(_('You have successfully registered into rhodecode'),
111 h.flash(_('You have successfully registered into rhodecode'),
111 category='success')
112 category='success')
113 Session().commit()
112 return redirect(url('login_home'))
114 return redirect(url('login_home'))
113
115
114 except formencode.Invalid, errors:
116 except formencode.Invalid, errors:
@@ -283,6 +283,10 b' class User(Base, BaseModel):'
283 notifications = relationship('UserNotification',)
283 notifications = relationship('UserNotification',)
284
284
285 @property
285 @property
286 def full_name(self):
287 return '%s %s' % (self.name, self.lastname)
288
289 @property
286 def full_contact(self):
290 def full_contact(self):
287 return '%s %s <%s>' % (self.name, self.lastname, self.email)
291 return '%s %s <%s>' % (self.name, self.lastname, self.email)
288
292
@@ -1170,6 +1174,7 b' class Notification(Base, BaseModel):'
1170 TYPE_CHANGESET_COMMENT = u'cs_comment'
1174 TYPE_CHANGESET_COMMENT = u'cs_comment'
1171 TYPE_MESSAGE = u'message'
1175 TYPE_MESSAGE = u'message'
1172 TYPE_MENTION = u'mention'
1176 TYPE_MENTION = u'mention'
1177 TYPE_REGISTRATION = u'registration'
1173
1178
1174 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
1179 notification_id = Column('notification_id', Integer(), nullable=False, primary_key=True)
1175 subject = Column('subject', Unicode(512), nullable=True)
1180 subject = Column('subject', Unicode(512), nullable=True)
@@ -57,8 +57,9 b' class NotificationModel(BaseModel):'
57 raise Exception('notification must be int or Instance'
57 raise Exception('notification must be int or Instance'
58 ' of Notification got %s' % type(notification))
58 ' of Notification got %s' % type(notification))
59
59
60 def create(self, created_by, subject, body, recipients,
60 def create(self, created_by, subject, body, recipients=None,
61 type_=Notification.TYPE_MESSAGE):
61 type_=Notification.TYPE_MESSAGE, with_email=True,
62 email_kwargs={}):
62 """
63 """
63
64
64 Creates notification of given type
65 Creates notification of given type
@@ -67,35 +68,46 b' class NotificationModel(BaseModel):'
67 notification
68 notification
68 :param subject:
69 :param subject:
69 :param body:
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 :param type_: type of notification
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 from rhodecode.lib.celerylib import tasks, run_task
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 raise Exception('recipients must be a list of iterable')
80 raise Exception('recipients must be a list of iterable')
77
81
78 created_by_obj = self.__get_user(created_by)
82 created_by_obj = self.__get_user(created_by)
79
83
80 recipients_objs = []
84 if recipients:
81 for u in recipients:
85 recipients_objs = []
82 obj = self.__get_user(u)
86 for u in recipients:
83 if obj:
87 obj = self.__get_user(u)
84 recipients_objs.append(obj)
88 if obj:
85 recipients_objs = set(recipients_objs)
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 notif = Notification.create(created_by=created_by_obj, subject=subject,
95 notif = Notification.create(created_by=created_by_obj, subject=subject,
88 body=body, recipients=recipients_objs,
96 body=body, recipients=recipients_objs,
89 type_=type_)
97 type_=type_)
90
98
99 if with_email is False:
100 return notif
101
91 # send email with notification
102 # send email with notification
92 for rec in recipients_objs:
103 for rec in recipients_objs:
93 email_subject = NotificationModel().make_description(notif, False)
104 email_subject = NotificationModel().make_description(notif, False)
94 type_ = EmailNotificationModel.TYPE_CHANGESET_COMMENT
105 type_ = type_
95 email_body = body
106 email_body = body
107 kwargs = {'subject':subject, 'body':h.rst(body)}
108 kwargs.update(email_kwargs)
96 email_body_html = EmailNotificationModel()\
109 email_body_html = EmailNotificationModel()\
97 .get_email_tmpl(type_, **{'subject':subject,
110 .get_email_tmpl(type_, **kwargs)
98 'body':h.rst(body)})
99 run_task(tasks.send_email, rec.email, email_subject, email_body,
111 run_task(tasks.send_email, rec.email, email_subject, email_body,
100 email_body_html)
112 email_body_html)
101
113
@@ -150,7 +162,9 b' class NotificationModel(BaseModel):'
150
162
151 _map = {notification.TYPE_CHANGESET_COMMENT:_('commented on commit'),
163 _map = {notification.TYPE_CHANGESET_COMMENT:_('commented on commit'),
152 notification.TYPE_MESSAGE:_('sent message'),
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 DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
168 DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
155
169
156 tmpl = "%(user)s %(action)s %(when)s"
170 tmpl = "%(user)s %(action)s %(when)s"
@@ -26,6 +26,7 b''
26 import logging
26 import logging
27 import traceback
27 import traceback
28
28
29 from pylons import url
29 from pylons.i18n.translation import _
30 from pylons.i18n.translation import _
30
31
31 from rhodecode.lib import safe_unicode
32 from rhodecode.lib import safe_unicode
@@ -33,7 +34,8 b' from rhodecode.lib.caching_query import '
33
34
34 from rhodecode.model import BaseModel
35 from rhodecode.model import BaseModel
35 from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \
36 from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \
36 UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember
37 UserToPerm, UsersGroupRepoToPerm, UsersGroupToPerm, UsersGroupMember, \
38 Notification
37 from rhodecode.lib.exceptions import DefaultUserException, \
39 from rhodecode.lib.exceptions import DefaultUserException, \
38 UserOwnsReposException
40 UserOwnsReposException
39
41
@@ -43,6 +45,7 b' from sqlalchemy.orm import joinedload'
43
45
44 log = logging.getLogger(__name__)
46 log = logging.getLogger(__name__)
45
47
48
46 PERM_WEIGHTS = {'repository.none': 0,
49 PERM_WEIGHTS = {'repository.none': 0,
47 'repository.read': 1,
50 'repository.read': 1,
48 'repository.write': 3,
51 'repository.write': 3,
@@ -211,7 +214,8 b' class UserModel(BaseModel):'
211 return None
214 return None
212
215
213 def create_registration(self, form_data):
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 try:
219 try:
216 new_user = User()
220 new_user = User()
217 for k, v in form_data.items():
221 for k, v in form_data.items():
@@ -219,18 +223,26 b' class UserModel(BaseModel):'
219 setattr(new_user, k, v)
223 setattr(new_user, k, v)
220
224
221 self.sa.add(new_user)
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 body = ('New user registration\n'
230 body = ('New user registration\n'
224 'username: %s\n'
231 '---------------------\n'
225 'email: %s\n')
232 '- Username: %s\n'
226 body = body % (form_data['username'], form_data['email'])
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 except:
244 except:
232 log.error(traceback.format_exc())
245 log.error(traceback.format_exc())
233 self.sa.rollback()
234 raise
246 raise
235
247
236 def update(self, user_id, form_data):
248 def update(self, user_id, form_data):
General Comments 0
You need to be logged in to leave comments. Login now