def reset_token(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Your password has been updated! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('reset_token.html', title='Reset Password', form=form)
def testapp(request): app = create_app('flaskblog.settings.TestConfig') client = app.test_client() db.app = app db.create_all() if getattr(request.module, "create_user", True): admin = User('admin', 'supersafepassword') db.session.add(admin) db.session.commit() def teardown(): db.session.remove() db.drop_all() request.addfinalizer(teardown) return client
def register(): form = RegistrationForm() if form.validate_on_submit(): image_file = 0 if form.picture.data: picture_file = save_picture(form.picture.data) image_file = picture_file hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') if image_file == 0: flash('Please Upload Your Profile Picture.', 'danger') return redirect(url_for('register')) # user = User(username=form.username.data, email=form.email.data, password=hashed_password) else: user = User(username=form.username.data, email=form.email.data, password=hashed_password, image_file = image_file, face_reco_id = image_file) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) # 만들어둔 form 을 템플릿에 전달 form = RegistrationForm() # is valid when it submitted if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() # bootstrap 이 지원하는 alert class 중에서 success를 적용하기위해 2번째 인자로 전달 flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: #falls angemeldet weiterleiten an die Startseite return redirect(url_for('home')) form = RegistrationForm() #Überprüfung der Daten beim Registierung if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data, password=form.password.data) #Speicherung der Daten in der User-Datenbank. db.session.add(user) db.session.commit() #Anzeige bei erfolgreicher Anmeldung flash('Super, du hast jetzt einen Account und kannst dich einloggen', 'success') #Weiterleitung zum Login return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def user_create_admin(): form = AdminUserCreateForm(request.form) if form.validate(): username = form.username.data password = form.password.data admin = form.admin.data existing_username = User.query.filter_by(username=username).first() if existing_username: flash('This username has been already taken. Try another one.', 'warning') return render_template('register.html', form=form) user = User(username, password, admin) db.session.add(user) db.session.commit() flash('New User Created.', 'info') return redirect(url_for('users_list_admin')) if form.errors: flash(form.errors, 'danger') return render_template('user-create-admin.html', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash('Token expirado', 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') # decode for instead bytes have string user.password = hashed_password db.session.commit() flash(f'Contraseña actualizada', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title='Cambiar contraseña', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for("home")) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode( "utf-8") # hashes the password from the form user = User( username=form.username.data, email=form.email.data, password=hashed_password ) # init the user object using the data from the form with the hashed password db.session.add(user) # adding the user to the database session db.session.commit() # comming the database session to the database flash("Your accound has been created! You are now able to log in", "success") return redirect(url_for("login")) return render_template("register.html", title="Register", form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for("home")) user = User.verify_reset_token(token) if user is None: flash("That is an invalid or expired token", "warning") return redirect(url_for("reset_request")) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode("utf-8") user.password = hashed_password db.session.commit() flash("Your password has been updated! You are now able to log in", "success") return redirect(url_for("login")) return render_template("reset_token.html", title="Reset Password", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): # since no salt is passed, one is generated randomly # `fullhash` is of the form `salt$hash` full_hash = '$'.join(hash_pw(form.password.data)) user = User(username=form.username.data, email=form.email.data, password=full_hash) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in.', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_pw, confirmed=False ) db.session.add(user) db.session.commit() token = generate_email_confirmation_token(form.email.data) username = form.username.data flash('Account created for {}! An email has been sent with instructions howto activate your account'.format(username), 'success') return redirect(url_for('main.home')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: #CHECKS IF USER IS ALREADY LOGGED IN return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode( 'utf-8') #ASSIGNS HASHED PASSWORD TO VARIABLE user = User(username=form.username.data, email=form.email.data, password=hashed_password) #CREATING A NEW INSTANCE OF USER db.session.add(user) #ADD ABOVE CHANGES TO DATABASE db.session.commit() flash('Your account has been created! You are now able to log in', 'success') #success is category for successful form validation return redirect( url_for('login') ) #AFTER SUCCESSFUL ACCOUNT CREATION USER IS REDIRECTED TO LOGIN PAGE return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode( 'utf-8' ) #hashing the passord of the user and then inserting into the DB user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash( 'Your Account has sucessfully created and You are able to login now.', 'success') return redirect(url_for('Login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for("main.home_page")) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode( "utf-8" ) user = User( username=form.username.data, email=form.email.data, password=hashed_password ) db.session.add(user) db.session.commit() flash( f"{form.username.data} successfully registered! You can now log in.", "success", ) return redirect(url_for("users.login")) return render_template("register.html", title="Sign Up", form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash('Your password reset link has been expired', 'warning') return redirect(url_for('users.reset_password_request')) form = PassswordResetForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash(f'Your password is successfully updated. You can login now', 'success') return redirect(url_for('users.login')) return render_template('reset_password.html', title='Reset Password', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) #creamos la instancia del RegistrationForm form = RegistrationForm() #mandamos un mensaje si se registro correctamente un usuario if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: flash(f'You have already loged in as {current_user.username}', 'info') return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Your account has been created! You are now able to login', 'success') return redirect( url_for('users.login')) # note: `url_for` gets the FUNCTION NAME return render_template('register.html', title='Register', form=form)
def request_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user: flash('Invalid Token', 'warning') form = Change_password() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_pw db.session.commit() flash("{}'s password is updated successfully!".format(user.username), 'success') return redirect(url_for('users.login')) return render_template('password_reset.html', title="Password Reset", form=form, form_name="Password Reset")
def reset_password(token): if current_user.is_authenticated: flash('Please Logout first to reset your password.', 'warning') return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash('This is an invalid or expired link.', 'danger') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_pass = bcrypt.generate_password_hash( form.password.data).decode() user.password = hashed_pass db.session.commit() flash('Your passwor has been changed, You can now login', 'success') return redirect(url_for('users.login')) return render_template('reset_password.html', form=form, title='Reset Password')
def test_incorrect_login(client): hashed_password = bcrypt.generate_password_hash('12345').decode('utf-8') user = User(username='******', email='*****@*****.**', password=hashed_password) db.session.add(user) # db.session.commit() rv = client.post('/login', data=dict(email="*****@*****.**", password="******"), follow_redirects=True) # print("rv : ", rv) # print("rv : ", rv.path) # assertRedirects(rv,url_for('/home')) # url_for('home.html')) assert 201 == rv.status_code assert b'Login Unsuccessful. Please check email and password' in rv.data # assertRedirects(res, url_for('home.html')) db.session.delete(user) db.session.commit()
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm( ) # This is the link. Pulls Resgistration Form from forms.py if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f'Your account has been created! You are now able to log in.', 'success') # python 3 format. return redirect(url_for('login')) return render_template( 'register.html', title='Register', form=form ) # This is what happens if the submit is unsuccessful with errors highlighted
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() # This gonna flash a message. # The second arguement of the flash method is for the category (here is used 'success'). flash('Your account has been created! You are now able to log in', 'success') # This gonna redirect to the home page after registering return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register_page(): if current_user.is_authenticated: return redirect(url_for("main.home_page")) form = RegistrationForm() if form.validate_on_submit(): hashed_password = brcypt.generate_password_hash( form.password.data).decode("utf-8") user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash( "Your Account has been Created! You can now Login!".format( {form.username.data}), "success", ) return redirect(url_for("users.login_page")) return render_template("register.html", title="Register", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form, msg=message)
def register(): if current_user.is_authenticated: return redirect(url_for('home')) print("register -----------------------------------------------------") form = RegistrationForm() if form.validate_on_submit(): print("validate on submit ----------------------------------") hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') print("creating record ---------------------------------") user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() print(User.query.all()) flash(f'Your account has been created. You can now login', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash('El token es invalido o ha expirado', 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash(f'Tu contraseña ha sido actualizada, ya puedes iniciar sesion', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', form=form, title='Resetear Contraseña')
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash( f"You have registered as {form.username.data}! Now you can login.", 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Your password has been updated! You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('reset_token.html', title='Reset Password', form=form)
def update_post(post_id): post = Post.objects(id=post_id).first() if not post: abort(404) user = User.objects(id=current_user.id).first() if post.author != user: abort(403) form = PostForm() if form.validate_on_submit(): post.update(title=form.title.data, content=form.content.data) flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title="Update Post", form=form, legend="Update Post")
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): # using decode to convert hashed password byte type to string hashed_pw = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_pw) db.session.add(user) db.session.commit() flash('Your account is created!', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register(): if current_user.is_authenticated: #if logged in, redirect to home return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_pw = bcrypt.generate_password_hash(form.password.data).decode( 'utf-8') #hash pw user = User(username=form.username.data, email=form.email.data, password=hashed_pw) #create user in database db.session.add(user) #add to database db.session.commit() #commit to database flash(f'Account created for {form.username.data}! You can now Login.', 'success' ) #f means variable in flash msg, success tells type of message return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)