Repository: fossasia/open-event-server

Issue:
Secret is missing on initial run
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-server

**Current behavior:**
When the server is run initially, the `get_settings()` method does not correctly initialize the secret in the settings and the returning settings do not contain `secret` variable, which raises an exception whenever used, e.g., when creating event image is hashed requiring a salt for which the secret is used

**Expected behavior:**
The secret should be correctly initialized on the first use of the method

**Steps to reproduce:**

Start the web app in a new environment with default settings and do anything which requires the use of secret

**Related code:**

`app/settings/__init__.py`
```python
def get_settings():
    """
    Use this to get latest system settings
    """
    if 'custom_settings' in current_app.config:
        return current_app.config['custom_settings']
    s = Setting.query.order_by(desc(Setting.id)).first()
    if s is None:
        set_settings(secret='super secret key', app_name='Open Event')
    else:
        current_app.config['custom_settings'] = make_dict(s)
    return current_app.config['custom_settings']
```

**Other information:**
```
...
  File "/home/iamareebjamal/git/open-event-server/.venv/src/flask-rest-jsonapi/flask_rest_jsonapi/data_layers/alchemy.py", line 51, in create_object
    self.after_create_object(obj, data, view_kwargs)
  File "/home/iamareebjamal/git/open-event-server/app/api/events.py", line 117, in after_create_object
    uploaded_images = create_save_image_sizes(data['original_image_url'], 'event', event.id)
  File "/home/iamareebjamal/git/open-event-server/app/api/helpers/files.py", line 159, in create_save_image_sizes
    'original_image_url': create_save_resized_image(image_file, 0, 0, 0, original_upload_path, resize=False),
  File "/home/iamareebjamal/git/open-event-server/app/api/helpers/files.py", line 95, in create_save_resized_image
    temp_file_relative_path = 'static/media/temp/' + generate_hash(str(image_file)) + get_file_name() + '.jpg'
  File "/home/iamareebjamal/git/open-event-server/app/api/helpers/storage.py", line 251, in generate_hash
    phash = generate_password_hash(key, get_settings()['secret'])
  File "/home/iamareebjamal/git/open-event-server/.venv/lib/python2.7/site-packages/flask_scrypt.py", line 95, in generate_password_hash
    salt = salt.encode('utf-8')
AttributeError: 'NoneType' object has no attribute 'encode'

```


Discussion:
I want to work on this :+1: 
@ParthS007 Any progress on it?

Resolving patch:
diff --git a/app/settings/__init__.py b/app/settings/__init__.py
--- a/app/settings/__init__.py
+++ b/app/settings/__init__.py
@@ -17,6 +17,8 @@ def get_settings():
         set_settings(secret='super secret key', app_name='Open Event')
     else:
         current_app.config['custom_settings'] = make_dict(s)
+        if not current_app.config['custom_settings'].get('secret'):
+            set_settings(secret='super secret key', app_name='Open Event')
     return current_app.config['custom_settings']
 
 


Test patch: