def register(): # Check session if current_user.is_authenticated: return redirect(url_for('index')) # get form form = RegistrationForm() # Check if form is if form.validate_on_submit(): # Hash password hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') # Get user info from form user = User(username=form.username.data, password=hashed_password, dateAdded=getEpoch(), isAdmin='false') try: # Add user db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') # Send them to the login return redirect(url_for('login')) except: # Undo if it broke db.session.rollback() flash('Your account has not been created.', 'fail') return render_template('register.html', title='Register', form=form)
def makeAdmin(): # Hash password hashed_password = bcrypt.generate_password_hash('admin').decode('utf-8') # Add user, ID will AI admin = User(username='******', password=hashed_password, dateAdded=getEpoch(), isAdmin='true') # Commit user db.session.add(admin) db.session.commit()
def changePassword(): form = ChangePassword() if form.validate_on_submit(): if bcrypt.check_password_hash(current_user.password, form.password.data): if form.newPassword.data == form.confirmNewPassword.data: current_user.password = bcrypt.generate_password_hash( form.newPassword.data).decode('utf-8') db.session.commit() flash('Password Updated.', 'success') return redirect(url_for('settings')) else: flash( '"New Password" and "Confirm New Password" fields do not match.', 'warning') else: flash('Password does not match.', 'danger') # Show page to the user return render_template('changePassword.html', form=form)