File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 11# coding=utf-8
22from __future__ import absolute_import
33from flask_wtf import Form
4+ from flask_login import current_user
45from wtforms import StringField , PasswordField
5- from wtforms .validators import ValidationError , Email , Required
6+ from wtforms .validators import ValidationError , Email , Required , URL
67
78from 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 ()
Original file line number Diff line number Diff line change 11# coding=utf-8
22from __future__ import absolute_import
33
4+ from flask import url_for , redirect
5+
46from flask .views import MethodView
57from 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
813bp = 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+
1532bp .add_url_rule ('/<id>/' , view_func = UserView .as_view ('detail' ))
33+ bp .add_url_rule ('/settings' , view_func = UserSettingsView .as_view ('settings' ))
You can’t perform that action at this time.
0 commit comments