A flask app for HackNC registration using MyMLH for auth.
Registration is a Flask app built to extend the MyMLH object model. Your hackathon users will "Sign in with MLH" and then get redirected back to the Registration dashboard. It maintains the extended object model in a postgres database. It also manages application status, and changes the view as applications are open, accepted, rejected, and checked in.
This enables you to do things like:
- Not worry about logins / password security / account recovery
- Accept resumes
- Ask additional questions and collect info not included in the MLH form.
- Trigger any python callbacks for:
- New user creation
- User info updates
- Trigger transactional email and slack notifications (optional)
- Manage applicants with an admin panel.
- Provide dashboard for acceptances and check-ins
- Create a new MLH app and take note of your client_id and secret.
- Set an application callback to my_server.domain/login, where my_server.domain points to the root '/' for this app.
You'll need a public-facing host to run this app. The developers here like DigitalOcean, but you could host anywhere! The remainder of this README assumes your server is running a modern version of Ubuntu.
use apt to install the following packages:
sudo apt-get install python3 python3-dev python-dev libpq-dev virtualenv postgresql nginx
- after installing postgres, log in as the postgres user.
sudo su postgres && psql
- Create a user for the application.
CREATE ROLE registration WITH PASSWORD {passwd} CREATEDB;
- Create a database for that role.
CREATE DATBASE registration OWNER registration
; - Edit
/etc/postgres/{version}/main/pg_hba.conf
: add the linelocal all registration md5
- Restart postgres.
sudo service postgresql restart
- clone the code and checkout a branch. It's a good idea to put apps in
/opt/<app_name/
- Create a virtual environment:
virtualenv -p python3 .
- Activate
source bin/activate
- run a development install
pip install -e .
- Move settings_example.py to settings.py and fill out all the fields
- After the database creation, you'll need to build the schema.
python registration.py migrate
will do this for you.
To run in prod, it's highly recommended that you sit flask behind nginx using uwsgi.
uwsgi --ini registration.ini
will start the server. Do not run this as root.
python registration.py debug
will start a single thread in debug mode. DEBUG MODE IS NOT SAFE FOR PRODUCTION
HackNC uses a couple of callback which require some other api keys/setup.
-
SparkPost API: sparkpost does transactional email. You will need to set up an account, generate an API key that can WRITE transmissions and read templates, and create a template. you can send it the "name" substitution data.
-
Slack Webhooks: Create a new custom slack integration, pick the channel, and paste the url into settings.py
You'll need to read and modify the code in these files to create a custom registration app:
- models.py - Modify User, HackerUser to reflect the desired schema
- forms.py - modify the forms.
- views.py - Example of a views file. You can create new micro-apps in their own submodules by following the design pattern in registration.hacker
This system exposes the following endpoints:
/
GET - Will render the index page if the requesting user does not have an active session.
- else, will redirect to settings.DEFAULT_VIEW
/login
GET - should be registered as the MLH callback. Never call this on your own.
/logout
GET - logs the user out. Redirects to /
/dashboard
GET - returns the user's current status and team.
/apply
GET - renders the current user's application state.
POST - update the current user's application state.
/api/me
GET - gets the logged in user's JSON representation.
/admin
GET - returns admin interface
/admin/user/{user_email}
GET - gets any specified user's JSON respresentation.
POST - adminstrative endpoint to set any user field, then redirect back to /admin
To give a user administrative privileges, log into a postgres prompt and run:
UPDATE public."user" SET is_admin = true WHERE email = '{user email}';
This project is chill. Fork it - code it - pull request it with docs. No fuss, no muss.