예제 #1
0
파일: views.py 프로젝트: vllbc/flask_learn
def settings():
    form = SettingForm()
    if form.validate_on_submit():
        user = UserModel.query.first()
        username = request.form['username']
        if len(username) > 20:
            flash("用户名过长!")
            return redirect(url_for("settings"))
        user.username = username
        db.session.commit()
        return redirect(url_for("index"))
    return render_template("setting.html", form=form)
예제 #2
0
def settings():
    form = SettingForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.blog_title = form.blog_title.data
        current_user.about = form.about.data
        db.session.commit()
        flash('Setting updated.', 'success')
        return redirect(url_for('blog.index'))
    form.name.data = current_user.name
    form.blog_title.data = current_user.blog_title
    form.about.data = current_user.about
    return render_template('admin/settings.html', form=form)
예제 #3
0
def PersonalSetting():
    form = SettingForm()
    if request.method=="POST":
        if form:
            #修改密码
            if form.old_password.data and form.password1.data and form.password2.data:
                if current_user.password_verification(form.old_password.data) and form.password2.data:
                    current_user.password_hash = generate_password_hash(form.password2.data)
                    db.session.commit()
                    flash('修改密码成功')
                else :
                    flash('与原密码不匹配,无法修改')
                    return redirect(url_for("PersonalSetting"))
            #修改邮箱地址
            if form.email.data:
                current_user.email = form.email.data
                db.session.commit()
                flash('修改邮箱成功')
            #修改电话号码
            if form.phone.data:
                current_user.phone = form.phone.data
                db.session.commit()
                flash('修改电话号码成功')
        return redirect(url_for("Home"))
    else:
        return render_template('PersonalSetting.html', form=form)
예제 #4
0
def settings():
    form = SettingForm(obj=current_user)
    change_pwd_form = ChangePasswordForm(prefix='pwd')

    if form.has_been_submitted(request):
        if form.validate_on_submit():
            current_user.blog_title = form.blog_title.data
            current_user.blog_description = form.blog_description.data
            current_user.blog_image = form.blog_image.data
            current_user.blog_image_rounded = form.blog_image_rounded.data
            current_user.blog_bg = form.blog_bg.data
            current_user.blog_bg_public = form.blog_bg_public.data
            current_user.blog_bg_everywhere = form.blog_bg_everywhere.data
            current_user.blog_bg_override = form.blog_bg_override.data
            current_user.blog_bg_repeat = form.blog_bg_repeat.data
            current_user.blog_paginate = form.blog_paginate.data
            current_user.blog_paginate_by = form.blog_paginate_by.data
            current_user.blog_public = form.blog_public.data
            current_user.blog_truncate_posts = form.blog_truncate_posts.data
            current_user.blog_syntax_highlighter_css = form.blog_syntax_highlighter_css.data
            current_user.linkedin_url = form.linkedin_url.data
            current_user.gplus_url = form.gplus_url.data
            current_user.github_url = form.github_url.data
            current_user.twitter_url = form.twitter_url.data
            saved = current_user.save()
            if saved:
                flash("Saved your settings.")
                return redirect(
                    url_for("blog.index", user_slug=current_user.blog_slug))
            else:
                flash("Something went wrong...")

    elif change_pwd_form.has_been_submitted(request):
        if change_pwd_form.validate_on_submit():
            current_user.set_password(change_pwd_form.new_password.data)
            saved = current_user.save()
            if saved:
                flash("Changed your password.")
            else:
                flash("Something went wrong...")
    return render_template("settings.html",
                           form=form,
                           change_pwd_form=change_pwd_form)
예제 #5
0
def settings():
    form = SettingForm(obj=current_user)
    change_pwd_form = ChangePasswordForm(prefix='pwd')

    if form.has_been_submitted(request):
        if form.validate_on_submit():
            current_user.blog_title = form.blog_title.data
            current_user.blog_description = form.blog_description.data
            current_user.blog_image = form.blog_image.data
            current_user.blog_image_rounded = form.blog_image_rounded.data
            current_user.blog_bg = form.blog_bg.data
            current_user.blog_bg_public = form.blog_bg_public.data
            current_user.blog_bg_everywhere = form.blog_bg_everywhere.data
            current_user.blog_bg_override = form.blog_bg_override.data
            current_user.blog_bg_repeat = form.blog_bg_repeat.data
            current_user.blog_paginate = form.blog_paginate.data
            current_user.blog_paginate_by = form.blog_paginate_by.data
            current_user.blog_public = form.blog_public.data
            current_user.blog_truncate_posts = form.blog_truncate_posts.data
            current_user.blog_syntax_highlighter_css = form.blog_syntax_highlighter_css.data
            current_user.linkedin_url = form.linkedin_url.data
            current_user.gplus_url = form.gplus_url.data
            current_user.github_url = form.github_url.data
            current_user.twitter_url = form.twitter_url.data
            saved = current_user.save()
            if saved:
                flash("Saved your settings.")
                return redirect(url_for("blog.index", user_slug=current_user.blog_slug))
            else:
                flash("Something went wrong...")

    elif change_pwd_form.has_been_submitted(request):
        if change_pwd_form.validate_on_submit():
            current_user.set_password(change_pwd_form.new_password.data)
            saved = current_user.save()
            if saved:
                flash("Changed your password.")
            else:
                flash("Something went wrong...")
    return render_template("settings.html", form=form, change_pwd_form=change_pwd_form)
예제 #6
0
def save(request):
    if request.method == 'POST':
        instance = get_object_or_404(UserSettings, name=request.user.username)
        setting_form = SettingForm(request.POST)

        if setting_form.is_valid():
            if setting_form.cleaned_data['news'] == 'T':
                instance.wNews = 1
                request.session['news'] = 1
            else:
                instance.wNews = 0
                request.session['news'] = 0
            if setting_form.cleaned_data['stock'] == 'T':
                instance.wStock = 1
                request.session['stock'] = 1
            else:
                instance.wStock = 0
                request.session['stock'] = 0
            if setting_form.cleaned_data['weather'] == 'T':
                instance.wWeather = 1
                request.session['weather'] = 1
            else:
                instance.wWeather = 0
                request.session['weather'] = 0
            if setting_form.cleaned_data['mail'] == 'T':
                instance.wMail = 1
                request.session['mail'] = 1
            else:
                instance.wMail = 0
                request.session['mail'] = 0
            if setting_form.cleaned_data['calendar'] == 'T':
                instance.wCalendar = 1
                request.session['calendar'] = 1
            else:
                instance.wCalendar = 0
                request.session['calendar'] = 0
            instance.save()

    return render(request, 'page-user.html',
                  request.session.__dict__['_session_cache'])
예제 #7
0
def setting():
    global tmail, username, commentary, origin, tname
    origin = username
    users = User.query.all()
    for u in users:
        if u.username == username:
            form = SettingForm(current_user.username, current_user.email)
            if form.validate_on_submit():
                usernam = form.username.data
                password = form.password.data
                login = form.login.data
                fullname = form.fullname.data
                email = form.email.data
                picture = form.file_object.data
                commentar = form.commentary.data
                if commentar != "":
                   u.commentary = commentar
                   commentary = commentar
                if picture != None:
                   picture.save(app.root_path + '/static/' + picture.filename)
                   u.picture = picture.filename
                if email != "":
                   tmail = email
                   u.email = email
                if fullname != "":
                   u.fullname = fullname
                if login != "":
                   u.login = login
                   tname = login
                if usernam != "":
                   u.username = usernam
                   username = usernam
                if password != "":
                   u.password_hash = password
                db.session.commit()
                return redirect('/profile')
            return render_template('setting.html', form=form)