Chris Jones avatar 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 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'))
 

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%;

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 %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.