def signinauthenticate(): #grab the request data try: #or use a email parsing library, you get the idea and do something... inputEmailAddress = request.form.get("inputEmailAddress") if not re.match(r"[^@]+@[^@]+\.[^@]+", inputEmailAddress): if not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", inputEmailAddress): inputPassword = request.form.get("inputPassword") #Query NoSQL and find out if this member already exists by email, if so, show the error member = MemberInfo() member = member.getMemberInfoByEmail(inputEmailAddress) #Make sure the password is correct if not check_password_hash(member.passwordhash, inputPassword): return render_template('index.html', inputEmailAddress=inputEmailAddress, alertmessage='It appears that is not quite right.') #Save the session and cookie values (do more than just email, but again, you get the idea) session[_SESSION_COOKIE_EMAIL] = member.emailaddress return redirect(url_for('landingpage')) except: return render_template('index.html', inputEmailAddress='', alertmessage='Oops!')
def userprofilephotoconfirm(): member = MemberInfo() #this will cause an ugly key error if we don't handle it properly try: inputUploadedPictureFile = request.files['inputProfilepicture'] if inputUploadedPictureFile: header = inputUploadedPictureFile.headers['Content-Type'] parsed_header = parse_options_header(header) blob_key = parsed_header[1]['blob-key'] except: #no need to log this error output dummyvariable = "" #a user is uploading a picture, either new if they did not have one prior, or uploaded a new one which would delete the old one if inputUploadedPictureFile: if member.pictureblobstorekey: blobstore.delete(member.pictureblobstorekey) images.delete_serving_url(member.pictureblobstorekey) member.pictureservingurl = images.get_serving_url(blob_key) member.pictureblobstorekey = blob_key member.put() return render_template('userprofilephotosaved.html', member=member) except: try: #If you couldn't complete the user save, be sure to delete the photo from the blobstore or re-use it later (to avoid a lost child hanging around) inputUploadedPictureFile = request.files['inputProfilepicture'] if inputUploadedPictureFile: header = inputUploadedPictureFile.headers['Content-Type'] parsed_header = parse_options_header(header) blob_key = parsed_header[1]['blob-key'] blobstore.delete(blob_key) except: #no need to log this error output dummyvariable = "" #Create a new form POST URL for the blobstore userprofilephoto_form_url = blobstore.create_upload_url('/userprofilephotoconfirm') return render_template('userprofilephoto.html', member=member, userprofilephoto_form_url=userprofilephoto_form_url, user_profilepicturesrc=user_profilepicturesrc, alertmessage='Oops!', userprofilephoto_form_url=userprofilephoto_form_url, user_profilepicturesrc=user_profilepicturesrc)