Skip to content

Commit 8b43753

Browse files
committed
add user setting form and view class
1 parent 822c5fc commit 8b43753

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from flask.views import MethodView
55
from flask.blueprints import Blueprint
6+
from flask_login import login_required
67

78

89
bp = Blueprint('user', __name__, url_prefix='/user')
@@ -12,4 +13,14 @@ class UserView(MethodView):
1213
def get(self, id):
1314
return ''
1415

16+
17+
class UserSettingsView(MethodView):
18+
decorators = [login_required]
19+
20+
def get(self):
21+
return ''
22+
23+
def post(self):
24+
return ''
25+
1526
bp.add_url_rule('/<id>/', view_func=UserView.as_view('detail'))

0 commit comments

Comments
 (0)