def register(): """ Sending a GET request returns the register.html page. Sending a POST request validates, then registers the user. If successful, the user is immediately brought to the sticky note page. """ if request.method == 'GET': return render_template('register.html') else: username = request.form['username'] password = request.form['password'] confirmation = request.form['confirmPassword'] if not confirmed_password_valid(password, confirmation): return fail_registration( "Your password and confirmation didn't match up.") if len(password) == 0: return fail_registration("Passwords can not be blank.") if ' ' in password: return fail_registration("Passwords can not have spaces") with closing(shelve.open(users_file)) as user_shelf: users = Users(user_shelf) if not users.is_valid_user(username): flash("Username %s is not valid." % (username)) flash("Either it's taken, it has a space, or it's blank") return render_template('register.html') users.register_user(username, password) session['username'] = username return redirect(url_for('notes'))
def login(): """ Sending a GET request gets the login form page. Sending a POST request tries to logs in the user. """ if request.method == 'GET': return render_template('login.html') else: username = request.form['username'] password = request.form['password'] with closing(shelve.open(users_file)) as user_shelf: users = Users(user_shelf) if users.login_is_valid(username, password): session['username'] = username return redirect(url_for('notes')) flash('Login failed. Maybe you made a typo?') return render_template('login.html')
def notes_storage(): """ Sending a GET request to this URL retrieves the notes associated with the user logged in (checked via the session). Sending a POST request updates the shelf with the provided new values. JavaScript calls this function to save/load notes. """ if 'username' not in session: abort(401) with closing(shelve.open(users_file)) as user_shelf: users = Users(user_shelf) if request.method == 'GET': return users.stickies_for_user(session['username']) else: data = request.form['noteSet'] users.save_stickies_for_user(session['username'], data) return 'Post successful'
Image.fromarray(dilated[key]).convert('L').save(key[:-4] + '_dl5.bmp') # Repeat for erode opened and closed, using different operators eroded = {} for key in bmp: eroded[key] = erode(bmp[key], se3) Image.fromarray(eroded[key]).convert('L').save(key[:-4] + '_er3.bmp') opened = {} for key in bmp: opened[key] = opening(bmp[key], se3) Image.fromarray(opened[key]).convert('L').save(key[:-4] + '_op3.bmp') closed = {} for key in bmp: closed[key] = closing(bmp[key], se5) Image.fromarray(closed[key]).convert('L').save(key[:-4] + '_cl5.bmp') # For outlined, start with the dilated image, or you wont get a good outline of anything. outlined = {} for key in dilated: outlined[key] = boundary(dilated[key], se3) Image.fromarray(outlined[key]).convert('L').save(key[:-4] + '_bd3.bmp') # To arbitrarily process the image to what I think looks best # Dilate, then close, open, and erode the image. arb = {} for key in bmp: arb[key] = dilate(bmp[key], se3) arb[key] = closing(arb[key], se5) arb[key] = opening(arb[key], se5)