aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-01-10 18:23:51 +0100
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-01-10 18:23:51 +0100
commitc68b08ba39e7f5ef83eccb57168cf28cb64dac71 (patch)
tree180bdc6169e72468d9cb23cce6e51ae2f107b1cb
parenterror() is called when the password can't be changed. (diff)
downloadnewspipe-c68b08ba39e7f5ef83eccb57168cf28cb64dac71.tar.gz
newspipe-c68b08ba39e7f5ef83eccb57168cf28cb64dac71.tar.bz2
newspipe-c68b08ba39e7f5ef83eccb57168cf28cb64dac71.zip
Added possibility to change the username.
-rwxr-xr-xsource/auth.py19
-rwxr-xr-xsource/pyAggr3g470r.py19
-rw-r--r--source/templates/management.html4
3 files changed, 40 insertions, 2 deletions
diff --git a/source/auth.py b/source/auth.py
index 33fafcda..9ca1c46f 100755
--- a/source/auth.py
+++ b/source/auth.py
@@ -49,6 +49,25 @@ class excel_french(csv.Dialect):
csv.register_dialect('excel_french', excel_french)
+def change_username(username, new_username, password_file='./var/password'):
+ """
+ Change the password corresponding to username.
+ """
+ users_list = []
+ result = False
+ with open(password_file, 'r') as csv_readfile_read:
+ cr = csv.reader(csv_readfile_read, 'excel_french')
+ users_list = [elem for elem in cr]
+ with open(password_file, 'w') as csv_file_write:
+ cw = csv.writer(csv_file_write, 'excel_french')
+ for user in users_list:
+ if user[0] == username:
+ cw.writerow([new_username, user[1]])
+ result = True
+ else:
+ cw.writerow(user)
+ return result
+
def change_password(username, new_password, password_file='./var/password'):
"""
Change the password corresponding to username.
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index df63ff99..6527161e 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -54,7 +54,7 @@ import utils
import export
import mongodb
import feedgetter
-from auth import AuthController, require, member_of, name_is, change_password
+from auth import AuthController, require, member_of, name_is, change_username, change_password
#from qrcode.pyqrnative.PyQRNative import QRCode, QRErrorCorrectLevel, CodeOverflowException
#from qrcode import qr
@@ -518,9 +518,24 @@ class pyAggr3g470r(object):
change_feed_logo.exposed = True
@require()
+ def change_username(self, new_username):
+ """
+ Enables to change the username of a user.
+ """
+ result = change_username(self.auth.username, new_username)
+ if result:
+ message = "<p>Your username has been changed.</p>"
+ tmpl = lookup.get_template("confirmation.html")
+ return tmpl.render(message=message)
+ else:
+ return self.error("<p>Impossible to change the username.</p>")
+
+ change_username.exposed = True
+
+ @require()
def change_password(self, new_password):
"""
- Enables to change the name of a feed.
+ Enables to change the password of a user.
"""
result = change_password(self.auth.username, new_password)
if result:
diff --git a/source/templates/management.html b/source/templates/management.html
index 38318d7c..553982fb 100644
--- a/source/templates/management.html
+++ b/source/templates/management.html
@@ -34,6 +34,10 @@
<hr />
<h1>Account</h1>
+ <form method=get action="/change_username/">
+ <input type="text" name="new_username" value="" placeholder="Enter a new username." />
+ </form>
+ <br />
<form method=get action="/change_password/">
<input type="password" name="new_password" value="" placeholder="Enter a new password." />
</form>
bgstack15