aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r
diff options
context:
space:
mode:
Diffstat (limited to 'pyaggr3g470r')
-rw-r--r--pyaggr3g470r/forms.py15
-rw-r--r--pyaggr3g470r/templates/profile.html24
-rw-r--r--pyaggr3g470r/views.py26
3 files changed, 64 insertions, 1 deletions
diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py
index 0aed7da6..0fcb0c63 100644
--- a/pyaggr3g470r/forms.py
+++ b/pyaggr3g470r/forms.py
@@ -64,4 +64,19 @@ class AddFeedForm(Form):
def validate(self):
if not Form.validate(self):
return False
+ return True
+
+class ProfileForm(Form):
+ firstname = TextField("First name", [validators.Required("Please enter your first name.")])
+ lastname = TextField("Last name", [validators.Required("Please enter your last name.")])
+ email = TextField("Email", [validators.Required("Please enter your email.")])
+ password = TextField("Password", [validators.Required("Please enter your password.")])
+ submit = SubmitField("Save")
+
+ def __init__(self, *args, **kwargs):
+ Form.__init__(self, *args, **kwargs)
+
+ def validate(self):
+ if not Form.validate(self):
+ return False
return True \ No newline at end of file
diff --git a/pyaggr3g470r/templates/profile.html b/pyaggr3g470r/templates/profile.html
new file mode 100644
index 00000000..bbb7981d
--- /dev/null
+++ b/pyaggr3g470r/templates/profile.html
@@ -0,0 +1,24 @@
+{% extends "layout.html" %}
+{% block content %}
+<div class="container">
+ <div class="jumbotron">
+ <form action="" method="post" name="save">
+ {{ form.hidden_tag() }}
+
+ {{ form.firstname.label }}
+ {{ form.firstname(class_="form-control") }} {% for error in form.firstname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+
+ {{ form.lastname.label }}
+ {{ form.lastname(class_="form-control") }} {% for error in form.lastname.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+
+ {{ form.email.label }}
+ {{ form.email(class_="form-control") }} {% for error in form.email.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+
+ {{ form.password.label }}
+ {{ form.password(class_="form-control") }} {% for error in form.password.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %}
+
+ {{ form.submit(class_="btn") }}
+ </form>
+ </div>
+</div><!-- /.container -->
+{% endblock %} \ No newline at end of file
diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py
index 0390cbdc..98362d05 100644
--- a/pyaggr3g470r/views.py
+++ b/pyaggr3g470r/views.py
@@ -33,7 +33,7 @@ from wtforms import TextField, PasswordField, SubmitField, validators
from flask.ext.login import LoginManager, login_user, logout_user, login_required, current_user, AnonymousUserMixin
from collections import defaultdict
-from forms import SigninForm, AddFeedForm
+from forms import SigninForm, AddFeedForm, ProfileForm
from pyaggr3g470r import app, db
@@ -346,3 +346,27 @@ def delete_feed(feed_id=None):
user.feeds.remove(feed)
user.save()
return redirect(url_for('home'))
+
+@app.route('/profile/', methods=['GET', 'POST'])
+@login_required
+def profile():
+ """
+ Edit the profile of the user.
+ """
+ user = models.User.objects(email=g.user.email).first()
+ form = ProfileForm()
+
+ if request.method == 'POST':
+ if form.validate() == False:
+ return render_template('profile.html', form=form)
+
+ form.populate_obj(user)
+ if form.password.data != "":
+ user.set_password(form.password.data)
+ user.save()
+ flash('User "' + user.firstname + '" successfully updated', 'success')
+ return redirect('/profile/')
+
+ if request.method == 'GET':
+ form = ProfileForm(obj=user)
+ return render_template('profile.html', form=form) \ No newline at end of file
bgstack15