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('index')) form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() flash('You are now registered.') return redirect(url_for('auth.login')) return render_template('auth/register.html', form=form)
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 register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email=form.email.data, username=form.username.data, password=form.password.data) db.session.add(user) db.session.commit() flash('Thank you for registration!') return redirect(url_for('users.login')) return render_template('register.html', 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('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 register(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): cd = form.cleaned_data u = User( username=cd['username'], password=cd['password'], email=cd['email'] ) u.save() return HttpResponseRedirect('/register_success') else: form = RegisterForm( initial={'my_code': 'guess'} ) return render_to_response('user/register.html', {'form': form}, context_instance=RequestContext(request))
def post_add(request): user_id = request.session["user_id"] if (user_id == None): return HttpResponseRedirect("/login") if (request.method == 'POST'): form = ArticleForm(request.POST) if form.is_valid(): cd = form.cleaned_data post = Article(title=cd["title"], content=cd["content"], tags=cd["tags"], types=cd["types"], author=User(id=user_id)) post.save() return HttpResponseRedirect("/articles/%d" % post.id) else: form = ArticleForm() return render_to_response("article/post_edit.html", {'form': form}, context_instance=RequestContext(request))
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') pw_salt = secrets.token_urlsafe(10) hashed_password = hashlib.pbkdf2_hmac( 'sha256', str.encode(form.password.data), str.encode(pw_salt + secrets.choice(peppers)), 10000).hex() user = User(username=form.username.data, email=form.email.data, password=hashed_password, salt=pw_salt) db.session.add(user) db.session.commit() flash('Your accoutn 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 comment_add(request, id): article = get_object_or_404(Article, pk=id) #add comment if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): cd = form.cleaned_data #comment_parent=Comment(id=cd["comment_parent_id"]), post = Comment(article=Article(id=id), user=User(id=cd["user_id"]), email=cd["email"], author=cd["author"], content=cd["content"]) if cd["comment_parent_id"] != None: post.comment_parent = Comment(id=cd["comment_parent_id"]) post.save() article.comment_count += 1 article.save() print("%r" % form.errors) return HttpResponseRedirect("/articles/%d#comment" % int(id))
from myblog.database import db_session, init_db, drop_db from myblog.models import Post, User drop_db() init_db() user = User(username='******', email='*****@*****.**', password='******') db_session.add(user) db_session.commit() post1 = Post(title='첫 번째 게시물', content='첫 번째 게시물 내용', author=user) post2 = Post(title='두 번째 게시물', content='두 번째 게시물 내용', author=user) db_session.add(post1) db_session.add(post2) db_session.commit()