def create(): form = BookmarkForm() if request.method == 'GET': return render_template('bookmarks/create.html', form=form) else: if form.validate_on_submit(): bookmark = Bookmark(title=form.title.data, is_private=form.is_private.data, description=form.description.data, user=current_user.user) bookmark.save() return redirect( url_for('bookmark_app.view', hash_id=bookmark.hash_id)) return render_template('bookmarks/create.html', form=form)
def create(): form = BookmarkForm() if request.method == 'GET': return render_template('bookmarks/create.html', form=form) else: if form.validate_on_submit(): bookmark = Bookmark(title=form.title.data, is_private=form.is_private.data, description=form.description.data, user=current_user.user) bookmark.save() return redirect(url_for('bookmark_app.view', hash_id=bookmark.hash_id)) return render_template('bookmarks/create.html', form=form)
def signup(): form = SignupForm() if request.method == 'GET': return render_template('users/signup.html', form=form) else: if form.validate_on_submit(): user = User() form.populate_obj(user) user.save() bookmark = Bookmark(user=user, title=u"%s 的收藏夹" % user.username, is_default=True) bookmark.save() user_mixin = LoginManagerUser(user) login_user(user_mixin) send_confirm_email(current_app.config, user.email) return redirect(url_for('site_app.index')) return render_template('users/signup.html', form=form)
def manage(): form = UserInfoForm(request.form) if form.validate(): if current_user.is_authenticated: current_user.user.username = form.username.data return redirect('/') else: user = User(email=form.email.data, username=form.username.data, is_email_confirmed=True) user.save() bookmark = Bookmark(user=user, title=u"%s 的收藏夹" % user.username, is_default=True) bookmark.save() user_mixin = LoginManagerUser(user) login_user(user_mixin) if 'email' in session: del(session['email']) return redirect('/') return render_template('users/manage.html', form=form)