Skip to content

Commit 791f213

Browse files
committed
add user setting form and view class
1 parent 20b5eca commit 791f213

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

firefly/forms/user.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# coding=utf-8
22
from __future__ import absolute_import
33
from flask_wtf import Form
4+
from flask_login import current_user
45
from wtforms import StringField, PasswordField
5-
from wtforms.validators import ValidationError, Email, Required
6+
from wtforms.validators import ValidationError, Email, Required, URL
67

78
from firefly.models.user import User
89

@@ -39,3 +40,17 @@ def validate_password(self, field):
3940
self.user = user
4041
else:
4142
raise ValidationError('邮箱或密码错误')
43+
44+
45+
class ProfileForm(Form):
46+
location = StringField('Location')
47+
website = StringField('URL', [URL()])
48+
github_id = StringField('Github')
49+
50+
def save(self):
51+
user = current_user
52+
if user and not user.is_anonymous():
53+
user.location = self.location.data
54+
user.website = self.website.data
55+
user.github_id = self.github_id.data
56+
user.save()

firefly/views/user.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# coding=utf-8
22
from __future__ import absolute_import
33

4+
from flask import url_for, redirect
5+
46
from flask.views import MethodView
57
from flask.blueprints import Blueprint
8+
from flask.ext.login import login_required, current_user
9+
from firefly.libs.template import render_template
10+
from firefly.forms.user import ProfileForm
611

712

813
bp = Blueprint('user', __name__, url_prefix='/user')
@@ -12,4 +17,17 @@ class UserView(MethodView):
1217
def get(self, id):
1318
return ''
1419

20+
21+
class UserSettingsView(MethodView):
22+
decorators = [login_required]
23+
24+
def get(self):
25+
return render_template('user/settings.html', user=current_user)
26+
27+
def post(self):
28+
form = ProfileForm()
29+
form.save()
30+
return redirect(url_for('user.settings'))
31+
1532
bp.add_url_rule('/<id>/', view_func=UserView.as_view('detail'))
33+
bp.add_url_rule('/settings', view_func=UserSettingsView.as_view('settings'))

0 commit comments

Comments
 (0)