Skip to content

Commit

Permalink
Fix issues in the user controller
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jul 28, 2011
1 parent 6b1f372 commit 48f62a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
31 changes: 22 additions & 9 deletions ckan/controllers/user.py
Expand Up @@ -84,9 +84,6 @@ def read(self, id=None):
try:
user_dict = get.user_show(context,data_dict)
except NotFound:
abort(404, _('User not found'))

if not user_dict:
h.redirect_to(controller='user', action='login', id=None)

c.user_dict = user_dict
Expand Down Expand Up @@ -253,22 +250,38 @@ def request_reset(self):
'user': c.user}

data_dict = {'id':id}

user_obj = None
try:
user_dict = get.user_show(context,data_dict)
user_obj = context['user_obj']

if user_dict is None:
except NotFound:
# Try searching the user
del data_dict['id']
data_dict['q'] = id

if id and len(id) > 2:
user_list = get.user_list(context,data_dict)
if len(user_list) == 1:
# This is ugly, but we need the user object for the mailer,
# and user_list does not return them
del data_dict['q']
data_dict['id'] = user_list[0]['id']
user_dict = get.user_show(context,data_dict)
user_obj = context['user_obj']
elif len(user_list) > 1:
h.flash_error(_('"%s" matched several users') % (id))
else:
h.flash_error(_('No such user: %s') % id)
else:
h.flash_error(_('No such user: %s') % id)

if user_obj:
try:
mailer.send_reset_link(user_obj)
h.flash_success(_('Please check your inbox for a reset code.'))
redirect('/')
except mailer.MailerException, e:
h.flash_error(_('Could not send reset link: %s') % unicode(e))

except NotFound:
h.flash_error(_('No such user: %s') % id)
return render('user/request_reset.html')

def perform_reset(self, id):
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/action/get.py
Expand Up @@ -358,7 +358,7 @@ def user_show(context, data_dict):
elif provided_user:
context['user_obj'] = user = provided_user
else:
return None
raise NotFound

user_dict = user_dictize(user,context)

Expand Down

0 comments on commit 48f62a1

Please sign in to comment.