Skip to content

Commit

Permalink
Basic error message for unsupported file type in signup
Browse files Browse the repository at this point in the history
Error message displays on page for if you upload a file as your profile
pic, but the file isn’t an image
  • Loading branch information
tracey-le committed Jan 30, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 88edf6f commit e09d7d9
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions back_end/user.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
NOUSER_PROFILEPIC_FILENAME = 'nouser.png'

def signup_handler(request):
request.write(render('signup.html', {'signed_in':authenticate_cookie(request), 'username': get_secure_username(request)}))
request.write(render('signup.html', {'signed_in':authenticate_cookie(request), 'username': get_secure_username(request), 'unsupported_file_error_msg': ''}))
ident = request.get_field('id')
username = request.get_field('username')
email = request.get_field('email')
@@ -43,20 +43,21 @@ def signup_handler_post(request):
f.write(data)
db.User.update(new_user.id, new_user.password, new_user.nickname, new_user.email, new_user.gender, new_user.dob, new_user.bio, file_path_profile_pic)
print(new_user.picture)
request.redirect('/')

else:
request.write("Uploaded file type not supported.")
print('Uploaded file type not supported')
request.write(render('signup.html', {'signed_in':authenticate_cookie(request), 'username': get_secure_username(request), 'unsupported_file_error_msg': 'Uploaded file type not supported.'}))
else:
file_path_profile_pic = os.path.join('uploads', 'user_image', NOUSER_PROFILEPIC_FILENAME)
db.User.update(new_user.id, new_user.password, new_user.nickname, new_user.email, new_user.gender, new_user.dob, new_user.bio, file_path_profile_pic)
request.write('We couldn\'t find an uploaded file. So we\'ll assign you a default pic.')
request.redirect('/')

if username is not None:
request.set_secure_cookie("current_user", username)


request.redirect('/')


def signin_handler(request):
if get_secure_username(request):
2 changes: 1 addition & 1 deletion static/js/validate.js
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ function validateSignupForm() {


$("#webcam-input").value = document.querySelector("#webcam-canvas").toDataURL("image/png");
alert(document.querySelector("#webcam-canvas").toDataURL("image/png"));
//alert(document.querySelector("#webcam-canvas").toDataURL("image/png"));

return Boolean(validUsername && validNickname && validPassword && validEmail);
}
7 changes: 6 additions & 1 deletion templates/signup.html
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ <h2>Sign Up</h2>
<fieldset>
<div class="signup_div">
<label for="username" class="signup_text">Username *</label>
<input id="username" type="text" name="username" placeholder="Enter a username" autofocus required>
<input id="username" type="text" name="username" placeholder="Enter a username" val="{{ username }}" autofocus required>
<p class='error'></p>
</div>
<div class="signup_div">
@@ -49,6 +49,11 @@ <h2>Sign Up</h2>

<!-- Experimental live profile pic + Matilda, Tracey, Steph and Sam -->
<div class="signup_div photobox">
<p class='error' id='unsupported-file-error'>
{% if unsupported_file_error_msg %}
{{ unsupported_file_error_msg }}
{% end if %}
</p>
<p class='error' id='webcam-vid-error'></p>
<video autoplay id="webcam-vid"></video>
<canvas width='200' height='150' id='webcam-canvas'> </canvas>

1 comment on commit e09d7d9

@tracey-le
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18 plain error messages

Please sign in to comment.