-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* version 1.0 - initial push * Version 1.0 potpourri (#40) * track ip address * collate nivturk plugins * update error page * fix bot detection bug * error catching on missing session info * per user completion code + asynchronous completion bug * cleaned up config file / changed default completion code behavior * redirects from all pages on previous completion * intelligent incognito handling * add monitor script * update error codes * add additional catch for repeat visits * Update 1004 error text Co-authored-by: Daniel Bennett <danielbrianbennett@gmail.com>
- Loading branch information
1 parent
ed0981e
commit a75dc35
Showing
14 changed files
with
434 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
[FLASK] | ||
|
||
# Flask secret key for encrypting session objects | ||
# Suggested: get key from https://randomkeygen.com | ||
SECRET_KEY = PLEASE_CHANGE_THIS | ||
COMPLETION_CODE = PROLIFIC_CODE_GOES_HERE | ||
DECOY_CODE = D60F2155 | ||
DEBUG = TRUE | ||
|
||
# Toggle debug mode (allow repeat visits from same session) | ||
# Accepts true or false | ||
DEBUG = true | ||
|
||
[PROLIFIC] | ||
|
||
# Participant completion code on success | ||
# Accepts string, or comment out for per-user codes | ||
CODE_SUCCESS = PROLIFIC_CODE_GOES_HERE | ||
|
||
# Participant completion code on reject | ||
# Accepts string, or comment out for per-user codes | ||
CODE_REJECT = D60F2155 | ||
|
||
[IO] | ||
DATA = ../data | ||
|
||
# Path to metadata folder [default: ../metadata] | ||
METADATA = ../metadata | ||
|
||
# Path to data folder [default: ../data] | ||
DATA = ../data | ||
|
||
# Path to reject folder [default: ../reject] | ||
REJECT = ../reject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,59 @@ | ||
import os, configparser | ||
from flask import (Blueprint, redirect, render_template, request, session, url_for) | ||
from .io import write_metadata | ||
|
||
## Initialize blueprint. | ||
bp = Blueprint('complete', __name__) | ||
|
||
## Define root directory. | ||
ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
## Load and parse configuration file. | ||
cfg = configparser.ConfigParser() | ||
cfg.read(os.path.join(ROOT_DIR, 'app.ini')) | ||
|
||
## Specify completion URLs (real and decoy). | ||
url_stem = "https://app.prolific.co/submissions/complete?cc=" | ||
complete_url = url_stem + cfg['FLASK']['COMPLETION_CODE'] | ||
decoy_url = url_stem + cfg['FLASK']['DECOY_CODE'] | ||
|
||
@bp.route('/complete') | ||
def complete(): | ||
"""Present completion screen to participant.""" | ||
|
||
## Case 1: navigation to completion page without completion flag | ||
if 'complete' not in session or session['complete'] == False: | ||
## Error-catching: screen for missing session. | ||
if not 'workerId' in session: | ||
|
||
## Redirect participant to error (missing workerId). | ||
return redirect(url_for('error.error', errornum=1000)) | ||
|
||
## Case 1: visit complete page without previous completion. | ||
elif 'complete' not in session: | ||
|
||
## Flag experiment as complete. | ||
session['ERROR'] = "1005: Visited complete page before completion." | ||
session['complete'] = 'reject' | ||
write_metadata(session, ['ERROR','complete','code_reject'], 'a') | ||
|
||
## Redirect participant with decoy code. | ||
url = "https://app.prolific.co/submissions/complete?cc=" + session['code_reject'] | ||
return redirect(url) | ||
|
||
## Update participant metadata. | ||
session['ERROR'] = "1012: Visited completion page without valid completion flag." | ||
write_metadata(session, ['ERROR'], 'a') | ||
return redirect(decoy_url) | ||
## Case 2: visit complete page with previous rejection. | ||
elif session['complete'] == 'success': | ||
|
||
## Case 2: data_pass | ||
## Update metadata. | ||
session['WARNING'] = "Revisited complete." | ||
write_metadata(session, ['WARNING'], 'a') | ||
|
||
## Redirect participant with completion code. | ||
url = "https://app.prolific.co/submissions/complete?cc=" + session['code_success'] | ||
return redirect(url) | ||
|
||
## Case 3: visit complete page with previous rejection. | ||
elif session['complete'] == 'reject': | ||
|
||
## Update metadata. | ||
session['WARNING'] = "Revisited complete." | ||
write_metadata(session, ['WARNING'], 'a') | ||
|
||
## Redirect participant with decoy code. | ||
url = "https://app.prolific.co/submissions/complete?cc=" + session['code_reject'] | ||
return redirect(url) | ||
|
||
## Case 4: visit complete page with previous error. | ||
else: | ||
|
||
## Update participant metadata. | ||
write_metadata(session, ['complete'], 'a') | ||
return redirect(complete_url) | ||
## Update metadata. | ||
session['WARNING'] = "Revisited complete." | ||
write_metadata(session, ['WARNING'], 'a') | ||
|
||
## Redirect participant to error (unusual activity). | ||
return redirect(url_for('error.error', errornum=1005)) |
Oops, something went wrong.