{svc['display_name']}
deleted successfully.", color='success')
return redirect(url_for('dashboard.list_services'))
+
+
+@bp.route('/invites/new', methods=['POST'])
+@admin_login_required
+def invite_create():
+ link = request.form['link'] if 'link' in request.form else None
+ code = request.form['code'] if 'code' in request.form else None
+
+ c = get_db().cursor()
+ c.execute('''
+ INSERT INTO Invites (app_id, service, link, code)
+ VALUES (?,?,?,?)
+ ''', [
+ request.form['app_id'],
+ request.form['service'],
+ link,
+ code
+ ])
+
+ c.connection.commit()
+
+ flasher('Created invite successfully!', color='success')
+
+ return redirect(url_for('dashboard.list_invites'))
+
+
+@bp.route('/invites/delete/+ { + "app_id": "applicant_id", + "service": "Service Name", + "code": "(optional) code", + "link": "(optional) link", + }+ ''' + + link = request.json['link'] if 'link' in request.json else None + code = request.json['code'] if 'code' in request.json else None + + if link is None and code is None: + return create_response({}, ok=False, message='Must have either link or code!') + + c = get_db().cursor() + c.execute(''' + INSERT INTO Invites (app_id, service, link, code) + VALUES (?,?,?,?) + ''', [ + request.json['app_id'], + request.json['service'], + link, + code + ]) + + c.connection.commit() + + return create_response({}) + +@bp.route('/invites/list') +@service_auth_required +def api_invite_list(): + ''' + List all the invites in the database. + + With an optional parameter `id`, this will return only the invites for the specified `user_id`. + ''' + + c = get_db().cursor() + + if request.args.get('id') is not None: + c.execute(''' + SELECT * FROM Invites WHERE app_id=? + ''', [request.args.get('id')]) + else: + c.execute(''' + SELECT * FROM Invites + ''') + + rows = c.fetchall() + if rows is None: + rows = [] + + return create_response(rows_to_objs(rows)) + api_routes = [ api_config, api_download_backup, api_get_by_id, api_get_by_email, api_get_all_applicants, - api_get_all_applicants_csv + api_get_all_applicants_csv, + api_invite_create, + api_invite_list ] diff --git a/app/templates/dashboard/base.html b/app/templates/dashboard/base.html index c8f749d..ab52210 100644 --- a/app/templates/dashboard/base.html +++ b/app/templates/dashboard/base.html @@ -36,19 +36,22 @@ diff --git a/app/templates/dashboard/invites.html b/app/templates/dashboard/invites.html new file mode 100644 index 0000000..09e48ed --- /dev/null +++ b/app/templates/dashboard/invites.html @@ -0,0 +1,90 @@ +{% extends "dashboard/base.html" %} + +{% block dashboard_content %} + +
Applicant ID | +Service | +Code | +Link | +Delete | +|
---|---|---|---|---|---|
{{invite.app_id}} | +{{invite.email}} | +{{invite.service }} | +{{invite.code}} |
+ {{ invite.link }} | ++ × + | + +
+ No invites in DB + | +
+ {% if invite['code'] %}
+ Invite code: {{ invite['code'] }}
+ {% endif %}
+ {% if invite['link'] %}
+ Link: {{ invite['link'] }}
+ {% endif %}
+