-
Notifications
You must be signed in to change notification settings - Fork 23
Realnames #96
base: master
Are you sure you want to change the base?
Realnames #96
Changes from 8 commits
ed22f70
3a61c26
300ada3
d3078f7
fec33b9
1a2f01c
bdba277
2dff67e
e3dea7f
30b9399
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,15 +577,32 @@ def POST_resendconfirmation(self, res): | |
VModhash(), | ||
curpass = nop('curpass'), | ||
email = ValidEmail("email"), | ||
realname = VRname("real_name"), | ||
newpass = nop("newpass"), | ||
verpass = nop("verpass"), | ||
password = VPassword(['newpass', 'verpass'])) | ||
def POST_update(self, res, email, curpass, password, newpass, verpass): | ||
def POST_update(self, res, email, curpass, realname, password, newpass, verpass): | ||
res._update('status', innerHTML='') | ||
if res._chk_error(errors.WRONG_PASSWORD): | ||
res._focus('curpass') | ||
res._update('curpass', value='') | ||
return | ||
|
||
if res._chk_error(errors.BAD_REALNAME_CHARS): | ||
res._focus('real_name') | ||
elif res._chk_error(errors.BAD_REALNAME_SHORT): | ||
res._focus('real_name') | ||
elif res._chk_error(errors.BAD_REALNAME_LONG): | ||
res._focus('real_name') | ||
if realname and realname == c.user.real_name: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong to me. I think you should remove minimum length limits on real names and make it so that an empty string is interpreted as a request to delete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried that but it doesn't really work in this case - the update password/email/realname form handles 3 different actions - entering nothing should result in nothing happening. I suspect that people will want to remove their real name rarely enough to make the bizarre syntax acceptable, unless you have a better suggestion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the best way to deal with this is to pre-fill the form with the user's current realname, and if they blank it out then delete it from their profile. If it's unchanged then we can infer that the form is being used for something else (password change etc.). |
||
c.user.real_name = None | ||
c.user._commit() | ||
res._update('status', innerHTML=_('Your real name has been removed')) | ||
elif realname: | ||
c.user.real_name = realname | ||
c.user._commit() | ||
res._update('status', innerHTML=_('Your real name has been updated')) | ||
|
||
updated = False | ||
if res._chk_error(errors.BAD_EMAIL): | ||
res._focus('email') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# coding: utf8 | ||
# The contents of this file are subject to the Common Public Attribution | ||
# License Version 1.0. (the "License"); you may not use this file except in | ||
# compliance with the License. You may obtain a copy of the License at | ||
|
@@ -23,7 +24,7 @@ | |
from pylons.i18n import _ | ||
from pylons.controllers.util import abort | ||
from r2.lib import utils, captcha | ||
from r2.lib.filters import unkeep_space, websafe, _force_utf8, _force_ascii | ||
from r2.lib.filters import unkeep_space, websafe, _force_utf8, _force_ascii, _force_unicode | ||
from r2.lib.wikipagecached import WikiPageCached | ||
from r2.lib.db.operators import asc, desc | ||
from r2.config import cache | ||
|
@@ -600,6 +601,36 @@ def run(self, user_name): | |
except NotFound: | ||
return user_name | ||
|
||
realname_rx = re.compile(ur"^[\w\s\-]{1,40}$", re.UNICODE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs to be compiled and run every time, but if it must I'd call it |
||
|
||
def chkrealname(x): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't match the pattern for function names in this codebase. Can you change it to (say) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, these should be methods on the validator object. |
||
try: | ||
return x if realname_rx.match(x) else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather use |
||
except TypeError: | ||
return None | ||
except UnicodeEncodeError: | ||
return None | ||
|
||
def whyrealnamebad(x): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would fold this stuff into (what will be called) |
||
if not x: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under what circumstances does |
||
return errors.BAD_REALNAME_CHARS | ||
if len(x)<1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per the above comments re:removing lower length limit, this could go away. |
||
return errors.BAD_REALNAME_SHORT | ||
if len(x)>40: | ||
return errors.BAD_REALNAME_LONG | ||
return errors.BAD_REALNAME_CHARS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any invalid characters any more? I think I remember asking for the regex to be much more permissive, so can this still happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we changed the regex to allow any unicode "word" characters, but given the role of this field as a real name, I think it still makes sense to exclude names like "&&&*()%#". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thanks for the reminder. |
||
|
||
class VRname(VRequired): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
def __init__(self, item, *a, **kw): | ||
VRequired.__init__(self, item, errors.BAD_REALNAME, *a, **kw) | ||
def run(self, real_name): | ||
original_real_name = real_name | ||
real_name = chkrealname(real_name) | ||
if not real_name: | ||
return self.error(whyrealnamebad(original_real_name)) | ||
else: | ||
return real_name.encode('utf8') | ||
|
||
class VLogin(VRequired): | ||
def __init__(self, item, *a, **kw): | ||
VRequired.__init__(self, item, errors.WRONG_PASSWORD, *a, **kw) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,10 @@ | |
('BAD_USERNAME_SHORT', _('Username is too short')), | ||
('BAD_USERNAME_LONG', _('Username is too long')), | ||
('BAD_USERNAME_CHARS', _('Username may not contain special characters')), | ||
('BAD_REALNAME', _('Invalid name')), | ||
('BAD_REALNAME_SHORT', _('Name is too short')), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove any of these that don't apply. |
||
('BAD_REALNAME_LONG', _('Name is too long')), | ||
('BAD_REALNAME_CHARS', _('Name may not contain special characters')), | ||
('USERNAME_TAKEN', _('That username is already taken')), | ||
('NO_THING_ID', _('Id not specified')), | ||
('NOT_AUTHOR', _("Only the author can do that")), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,15 @@ | |
${error_field("NO_EMAIL")} | ||
</td> | ||
</tr> | ||
<tr> | ||
<td align="right">${_("Real Name")}:</td> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make it clear that this field is optional and will be shown publicly. Also, should it be added to the registration form? |
||
<td><input name="real_name" type="text" value="${hasattr(c.user,'real_name') and c.user.real_name or ''}" title="Enter your current real name to remove it"/></td> | ||
<td> | ||
${error_field("BAD_REALNAME_CHARS")} | ||
${error_field("BAD_REALNAME_SHORT")} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you find that you can remove any of these error messages elsewhere they'll have to be removed from here too. |
||
${error_field("BAD_REALNAME_LONG")} | ||
</td> | ||
</tr> | ||
<tr> | ||
<td align="right">${_("New password")}:</td> | ||
<td><input name="newpass" type="password" maxlength="20"/></td> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all going to have the same effect, so you could merge the conditions like: