Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 40 additions & 26 deletions weasyl/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,28 @@ def signin_get_(request):
@guest_required
@token_checked
def signin_post_(request):
form = request.web_input(username="", password="", referer="", sfwmode="nsfw")
form.referer = form.referer or '/'

logid, logerror = login.authenticate_bcrypt(form.username, form.password, request=request, ip_address=request.client_addr, user_agent=request.user_agent)
referer = request.params.get('referer', '/')
sfwmode = request.params.get('sfwmode', 'nsfw')

logid, logerror = login.authenticate_bcrypt(
request.params.get('username'),
request.params.get('password'),
request=request,
ip_address=request.client_addr,
user_agent=request.user_agent
)

if logid and logerror == 'unicode-failure':
raise HTTPSeeOther(location='/signin/unicode-failure')
elif logid and logerror is None:
if form.sfwmode == "sfw":
if sfwmode == "sfw":
request.set_cookie_on_response("sfwmode", "sfw", 31536000)
# Invalidate cached versions of the frontpage to respect the possibly changed SFW settings.
index.template_fields.invalidate(logid)
raise HTTPSeeOther(location=form.referer)
raise HTTPSeeOther(location=referer)
elif logid and logerror == "2fa":
# Password authentication passed, but user has 2FA set, so verify second factor (Also set SFW mode now)
if form.sfwmode == "sfw":
if sfwmode == "sfw":
request.set_cookie_on_response("sfwmode", "sfw", 31536000)
index.template_fields.invalidate(logid)
# Check if out of recovery codes; this should *never* execute normally, save for crafted
Expand All @@ -79,11 +85,11 @@ def signin_post_(request):
return Response(define.webpage(
request.userid,
"etc/signin_2fa_auth.html",
[define.get_display_name(logid), form.referer, remaining_recovery_codes, None],
[define.get_display_name(logid), referer, remaining_recovery_codes, None],
title="Sign In - 2FA"
))
elif logerror == "invalid":
return Response(define.webpage(request.userid, "etc/signin.html", [True, form.referer]))
return Response(define.webpage(request.userid, "etc/signin.html", [True, referer]))
elif logerror == "banned":
reason = moderation.get_ban_reason(logid)
return Response(define.errorpage(
Expand Down Expand Up @@ -194,15 +200,18 @@ def signin_unicode_failure_get_(request):

@login_required
def signin_unicode_failure_post_(request):
form = request.web_input(password='', password_confirm='')
login.update_unicode_password(request.userid, form.password, form.password_confirm)
login.update_unicode_password(
request.userid,
request.params.get('password', ''),
request.params.get('password_confirm', '')
)
raise HTTPFound(location="/", headers=request.response.headers)


@login_required
@disallow_api
def signout_(request):
if request.web_input(token="").token != define.get_token()[:8]:
if request.params.get('token') != define.get_token()[:8]:
raise WeasylError('token')

login.signout(request)
Expand All @@ -212,12 +221,10 @@ def signout_(request):

@guest_required
def signup_get_(request):
form = request.web_input(email="")

return Response(define.webpage(request.userid, "etc/signup.html", [
# Signup data
{
"email": form.email,
"email": request.params.get('email', ''),
"username": None,
"day": None,
"month": None,
Expand All @@ -230,16 +237,21 @@ def signup_get_(request):
@guest_required
@token_checked
def signup_post_(request):
form = request.web_input(
username="", password="", passcheck="", email="", emailcheck="",
day="", month="", year="")

if not define.captcha_verify(form.get('g-recaptcha-response')):
if not define.captcha_verify(request.params.get('g-recaptcha-response', '')):
return Response(define.errorpage(
request.userid,
"There was an error validating the CAPTCHA response; you should go back and try again."))

login.create(form)
login.create(
request.params.get('username', ''),
request.params.get('email', ''),
request.params.get('emailcheck', ''),
request.params.get('password', ''),
request.params.get('passcheck', ''),
request.params.get('year', ''),
request.params.get('month', ''),
request.params.get('day', '')
)
return Response(define.errorpage(
request.userid,
"**Success!** Your username has been reserved and a message "
Expand All @@ -251,7 +263,7 @@ def signup_post_(request):

@guest_required
def verify_account_(request):
login.verify(token=request.web_input(token="").token, ip_address=request.client_addr)
login.verify(token=request.params.get('token'), ip_address=request.client_addr)
return Response(define.errorpage(
request.userid,
"**Success!** Your email address has been verified "
Expand All @@ -261,7 +273,7 @@ def verify_account_(request):

@login_required
def verify_emailchange_get_(request):
token = request.web_input(token="").token
token = request.params.get('token')
email = login.verify_email_change(request.userid, token)
return Response(define.errorpage(
request.userid,
Expand Down Expand Up @@ -332,9 +344,11 @@ def force_resetpassword_(request):
if define.common_status_check(request.userid) != "resetpassword":
raise WeasylError('InsufficientPermissions')

form = request.web_input(password="", passcheck="")

resetpassword.force(request.userid, form)
resetpassword.force(
request.userid,
request.params.get('password', ''),
request.params.get('passcheck', ''),
)

# Invalidate all other user sessions for this user.
profile.invalidate_other_sessions(request.userid)
Expand Down
19 changes: 6 additions & 13 deletions weasyl/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,17 @@ def password_secure(password):
return len(password) >= _PASSWORD


# form
# username email month
# password emailcheck year
# passcheck day

def create(form):
def create(username, email, emailcheck, password, passcheck, year, month, day):
# Normalize form data
username = clean_display_name(form.username)
username = clean_display_name(username)
sysname = d.get_sysname(username)

email = emailer.normalize_address(form.email)
emailcheck = emailer.normalize_address(form.emailcheck)
email = emailer.normalize_address(email)
emailcheck = emailer.normalize_address(emailcheck)

password = form.password
passcheck = form.passcheck
if form.day and form.month and form.year:
if day and month and year:
try:
birthday = arrow.Arrow(int(form.year), int(form.month), int(form.day))
birthday = arrow.Arrow(int(year), int(month), int(day))
except ValueError:
raise WeasylError("birthdayInvalid")
else:
Expand Down
12 changes: 4 additions & 8 deletions weasyl/resetpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,14 @@ def reset(token, password, passcheck, expect_userid, address):
)


# form
# password
# passcheck

def force(userid, form):
def force(userid, password, passcheck):
from weasyl import login

if form.password != form.passcheck:
if password != passcheck:
raise WeasylError("passwordMismatch")
elif not login.password_secure(form.password):
elif not login.password_secure(password):
raise WeasylError("passwordInsecure")

d.engine.execute("UPDATE login SET force_password_reset = FALSE WHERE userid = %(user)s", user=userid)
d.engine.execute("UPDATE authbcrypt SET hashsum = %(new_hash)s WHERE userid = %(user)s", new_hash=login.passhash(form.password), user=userid)
d.engine.execute("UPDATE authbcrypt SET hashsum = %(new_hash)s WHERE userid = %(user)s", new_hash=login.passhash(password), user=userid)
d._get_all_config.invalidate(userid)
Loading