From e891287d3ed869aabfd97c4d431fc9dde03b06eb Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 18 Dec 2011 12:09:13 +0100 Subject: [PATCH] Save password as md5 --- couchpotato/core/_base/_core/main.py | 7 ++++++- couchpotato/core/auth.py | 3 ++- couchpotato/core/settings/__init__.py | 7 +++++-- couchpotato/static/scripts/page/settings.js | 7 ++++++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/couchpotato/core/_base/_core/main.py b/couchpotato/core/_base/_core/main.py index f17fa58f..179aa2a9 100644 --- a/couchpotato/core/_base/_core/main.py +++ b/couchpotato/core/_base/_core/main.py @@ -2,7 +2,7 @@ from couchpotato import app from couchpotato.api import addApiView from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.helpers.request import jsonified -from couchpotato.core.helpers.variable import cleanHost +from couchpotato.core.helpers.variable import cleanHost, md5 from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env @@ -28,8 +28,13 @@ class Core(Plugin): addEvent('app.load', self.launchBrowser, priority = 100) addEvent('app.base_url', self.createBaseUrl) + addEvent('setting.save.core.password', self.md5Password) + self.removeRestartFile() + def md5Password(self, value): + return md5(value) + def available(self): return jsonified({ 'succes': True diff --git a/couchpotato/core/auth.py b/couchpotato/core/auth.py index 325a575c..743a4c79 100644 --- a/couchpotato/core/auth.py +++ b/couchpotato/core/auth.py @@ -1,3 +1,4 @@ +from couchpotato.core.helpers.variable import md5 from couchpotato.environment import Env from flask import request, Response from functools import wraps @@ -16,7 +17,7 @@ def requires_auth(f): @wraps(f) def decorated(*args, **kwargs): auth = getattr(request, 'authorization') - if Env.setting('username') and (not auth or not check_auth(auth.username, auth.password)): + if Env.setting('username') and (not auth or not check_auth(auth.username, md5(auth.password))): return authenticate() return f(*args, **kwargs) diff --git a/couchpotato/core/settings/__init__.py b/couchpotato/core/settings/__init__.py index cddfe3e4..d1a1b0b0 100644 --- a/couchpotato/core/settings/__init__.py +++ b/couchpotato/core/settings/__init__.py @@ -1,5 +1,5 @@ from couchpotato.api import addApiView -from couchpotato.core.event import addEvent +from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.helpers.encoding import isInt, toUnicode from couchpotato.core.helpers.request import getParams, jsonified from couchpotato.core.helpers.variable import mergeDicts @@ -137,7 +137,10 @@ class Settings(): option = params.get('name') value = params.get('value') - self.set(section, option, value) + # See if a value handler is attached, use that as value + new_value = fireEvent('setting.save.%s.%s' % (section, option), value, single = True) + + self.set(section, option, new_value if new_value else value) self.save() return jsonified({ diff --git a/couchpotato/static/scripts/page/settings.js b/couchpotato/static/scripts/page/settings.js index 3dcfde3e..fbf5df7b 100644 --- a/couchpotato/static/scripts/page/settings.js +++ b/couchpotato/static/scripts/page/settings.js @@ -205,7 +205,7 @@ var OptionBase = new Class({ self.section = section; self.name = name; - self.value = value; + self.value = self.previous_value = value; self.createBase(); self.create(); @@ -414,6 +414,11 @@ Option.Password = new Class({ self.parent() self.input.set('type', 'password') + + self.input.addEvent('focus', function(){ + self.input.set('value', '') + }) + } });