def Settings(): form = ChangeSettingsForm() if form.validate_on_submit(): if (form.pfp.data): newname = saveimg(form.pfp.data) current_user.pfp = newname if (form.pfc.data): newname = saveimg(form.pfc.data, "CoverPics", 1920, 1080) current_user.pfc = newname current_user.username = form.username.data current_user.email = form.email.data current_user.activity = form.activity.data current_user.description = form.description.data if form.password.data != "": current_user.password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') db.session.commit() flash(f'Settings Changed Succefully', 'success') return redirect(url_for('UserProfile', user_name=current_user.username)) elif request.method == "GET": form.username.data = current_user.username form.email.data = current_user.email form.activity.data = current_user.activity form.description.data = current_user.description return render_template("Settings.html", form=form, user=current_user)
def new_user(): hashed_password = bcrypt.generate_password_hash("testing").decode('utf-8') user = User(username="******", email="*****@*****.**", password=hashed_password, id=1) return user
def init_db(): db.drop_all() db.create_all() # adding test user data hashed_pass1 = bcrypt.generate_password_hash('password') hashed_pass2 = bcrypt.generate_password_hash('testing') user = User(username='******', email='*****@*****.**', password=hashed_pass1) user1 = User(username='******', email='*****@*****.**', password=hashed_pass2) db.session.add(user) db.session.add(user1) db.session.commit() # adding testing project data project = Project(title='test', content='test', user_id=user.id, id=1) project1 = Project(title='test', content='test', user_id=user1.id, id=2) db.session.add(project) db.session.add(project1) db.session.commit() #adding test article data article = Article(title='test', content='test', user_id=user.id, id=1) article1 = Article(title='test', content='test', user_id=user1.id, id=2) db.session.add(article) db.session.add(article1) db.session.commit() #adding test comment data reply = Reply(content='test_comment', username=user.username, project_id=project.id) db.session.add(reply) db.session.commit() #adding test reply data tore = Tore(content='test_reply', username=user.username, reply_id=reply.id) db.session.add(tore) db.session.commit() # tests happen HERE! yield db db.drop_all()
def register(): 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'Profile created for {form.username.data}!', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def init_db(scope="session"): db.session.close() db.drop_all() db.create_all() # adding test user data hashed_pass1 = bcrypt.generate_password_hash("password").decode("utf-8") hashed_pass2 = bcrypt.generate_password_hash("testing").decode("utf-8") user = User(username="******", email="*****@*****.**", password=hashed_pass1) user1 = User(username="******", email="*****@*****.**", password=hashed_pass2) db.session.add(user) db.session.add(user1) db.session.commit() # adding testing project data project = Project(title="test", content="test", user_id=user.id) project1 = Project(title="test", content="test", user_id=user1.id) db.session.add(project) db.session.add(project1) db.session.commit() #adding test article data article = Article(title="test", content="test", user_id=user.id) article1 = Article(title="test", content="test", user_id=user1.id) db.session.add(article) db.session.add(article1) db.session.commit() #adding test comment data reply = Reply(content="test_comment",username=user.username, project_id=project.id) db.session.add(reply) db.session.commit() #adding test reply data tore = Tore(content="test_reply",username=user.username, reply_id=reply.id) db.session.add(tore) db.session.commit() # tests happen HERE! yield db db.session.close() db.drop_all()
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('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 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 register(): if current_user.is_authenticated: return redirect(url_for('posts.index')) form = RegisterForm() if form.validate_on_submit(): password_hash = bcrypt.generate_password_hash(form.password.data) \ .decode('utf-8') user = User(username=form.username.data, password=password_hash) db.session.add(user) db.session.commit() flash(f"Welcome {user.username}. " "Your account have create success", "success") login_user(user) return redirect(url_for('posts.index')) return render_template('auth/register.html', form=form)
def Register(): if current_user.is_authenticated: return redirect(url_for('Home')) form = RegisterForm() 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'successful created account for {form.username.data}', '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')) forms = RegistrationForm() if forms.validate_on_submit(): passhashed = bcrypt.generate_password_hash( forms.password.data).decode('utf-8') user = User(username=forms.username.data, email=forms.email.data, password=passhashed) db.session.add(user) db.session.commit() login_user(user) flash(f'Account Created For {forms.username.data}', 'success') return redirect(url_for('UserProfile', user_name=current_user.username)) return render_template('Register.html', title='Register', form=forms)
def register(): if current_user.is_authenticated: return redirect(url_for('main.project', user=current_user.username)) registration_form = RegistrationForm() if registration_form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( registration_form.password.data).decode('utf-8') user = User(username=registration_form.username.data, email=registration_form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash(f"Account has been created! Please Login", 'success') return redirect(url_for('users.login')) return render_template('register.html', form=registration_form, title='Register')
def register(): #chenck if user is already login if current_user.is_authenticated: return redirect('home') #end 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! Now you able to access account', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def reset_password(token): if current_user.is_authenticated: return redirect(url_for('main.project', user=current_user.username)) user = User.verify_reset_token(token) if not user: flash('That is an invalid or expired token', 'danger') return redirect(url_for('users.forgot_password')) reset_form = ResetPasswordForm() if reset_form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( reset_form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash(f"Your password has been updated", 'success') return redirect(url_for('users.login')) return render_template('reset_password.html', form=reset_form, title='Reset Password')