Chris Jones committed 761e3e3

Added support for Redis AUTH. Catching the ResponseError as thats the only thing it throws when Redis is setup with a password. Fixed context processor to send back a basic dict so it does not fail when the Redis connection is dead. Added password field to the setup page. Little CSS and form love.

Comments (0)

Files changed (3)

 from import Form, TextField, Required
 import redis
-from redis.exceptions import ConnectionError
+from redis.exceptions import ConnectionError, ResponseError
 import settings
 def get_db_size():
     r = get_redis_connection(session)
+    if not r:
+        return {'db_size':0}
     return dict(db_size=r.dbsize())
 @app.route('/new', methods=['GET', 'POST'])
     r = redis.Redis(
         host=session.get('redis_host', settings.REDIS_HOST),
         port=session.get('redis_port', settings.REDIS_PORT),
-        db=session.get('redis_db', settings.REDIS_DB))
+        db=session.get('redis_db', settings.REDIS_DB),
+        password=session.get('redis_password', ''))
-    except ConnectionError:
+    except (ConnectionError, ResponseError):
         return None
     return r
     if request.method == 'POST':
         host = request.form['host'] or settings.REDIS_HOST
+        password = request.form['password']
             port = int(request.form['port'])
         except ValueError:
         session['redis_host'] = host
         session['redis_port'] = port
+        session['redis_password'] = password
         return redirect(url_for('index'))
-    #setup_form input[type=text], #new_key_form input[type=text] {
+    #setup_form input[type=text], #setup_form input[type=password], #new_key_form input[type=text] {
       border:1px solid rgba(30,30,30,0.5);
       padding:1em 2%;
 		<label for="port">Port:</label>
 		<input type="text" name="port" placeholder="{{ session.redis_port }}">
+	<fieldset>
+		<label for="port">Password:</label>
+		<input type="password" name="password">
+	</fieldset>
 	<input type="submit" value="Submit">
 {% endblock %}