-
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 6 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') | ||
|
@@ -594,6 +611,7 @@ def POST_update(self, res, email, curpass, password, newpass, verpass): | |
elif email and (not hasattr(c.user,'email') | ||
or c.user.email != email): | ||
c.user.email = email | ||
c.user._commit() | ||
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 isn't required because the |
||
self.send_confirmation() | ||
res._update('status', | ||
innerHTML=_('Your email has been updated. You will have to confirm before commenting or posting.')) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,6 +600,36 @@ def run(self, user_name): | |
except NotFound: | ||
return user_name | ||
|
||
realname_rx = re.compile(r"^[a-zA-Z\s\-]{3,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. Hi Lucas, I think this regex excludes many valid names. Personally I know someone with é in their name and another with ä in their surname. Can you please tweak to allow non-ASCII characters. 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. Done. On Thu, May 1, 2014 at 5:25 PM, Wesley Moore [email protected]:
"And someday when the descendants of humanity have spread from star to -Eliezer Yudkowsky "Trust me" means "I love you" http://project-apollo.net/mos/mos114.html "This isn't even my final form!" -Tim Hausler |
||
|
||
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 str(x) if realname_rx.match(x) else None | ||
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)<3: | ||
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. And here too. |
||
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 | ||
|
||
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: