Commits

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.

  • Participants
  • Parent commits 25a1ea8

Comments (0)

Files changed (3)

 from flaskext.wtf import Form, TextField, Required
 
 import redis
-from redis.exceptions import ConnectionError
+from redis.exceptions import ConnectionError, ResponseError
 
 import settings
 
 @app.context_processor
 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', ''))
 
     try:
         r.ping()
-    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']
         try:
             port = int(request.form['port'])
         except ValueError:
 
         session['redis_host'] = host
         session['redis_port'] = port
+        session['redis_password'] = password
 
         return redirect(url_for('index'))
 

File static/css/style.css

       font-weight:bold;
       margin-bottom:10px;
     }
-    #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%;
       width:96%;

File templates/setup.html

 		<label for="port">Port:</label>
 		<input type="text" name="port" placeholder="{{ session.redis_port }}">
 	</fieldset>
+	<fieldset>
+		<label for="port">Password:</label>
+		<input type="password" name="password">
+	</fieldset>
 	<input type="submit" value="Submit">
 </form>
 {% endblock %}