Exemplo n.º 1
0
def register():
    print(this_function_name)
    if request.method == 'GET':
        return render_template('register.html', title='Register Your Account')

    req_json = util.request_form_to_json(request)

    if req_json['action'] == 'getcode' and req_json['username'] != "":
        api.get_code(req_json['username'])
        warning = "Email Sent!"
        return render_template('register.html',
                               title="Get Code",
                               warning=warning)

    elif req_json['action'] == 'register':
        if req_json['code'] != "" and req_json['password'] != "" and req_json[
                'username'] != "":
            res = api.register_user(req_json)
            if not res:
                return render_template('register.html',
                                       title="Get Code",
                                       warning='Entered Wrong Code')
            else:
                return redirect(url_for('login'))
        else:
            warning = "Click Get Code first, Enter code from your email"
            return render_template('register.html',
                                   title="Get Code",
                                   warning=warning)
    else:
        warning = "Click Get Code first, Enter code from your email"
        return render_template('register.html',
                               title="Get Code",
                               warning=warning)
Exemplo n.º 2
0
def register():
    if request.method == 'GET':
        return render_template('register.html', title='Register Your Account')

    inputs = util.request_form_to_json(request)
    if inputs['password'] != "" and inputs['username'] != "":
        user = User(inputs['username'], inputs['password'])
        print(user)
        existed_users = User.query.filter_by(username=inputs['username']).all()
        if len(existed_users) > 0:
            message = "{} already existed in db.".format(inputs['username'])
            flash("{} already existed in db.".format(inputs['username']))
            return render_template('register.html', warning=message)
        try:
            db.session.add(user)
            db.session.commit()
            flash("{0} saved successfully.".format(user.username))
            return redirect(url_for('login'))
        except Exception as e:
            print(e)
            return render_template('register.html', warning=str(e))
    else:
        warning = "Username and password is empty"
        return render_template('register.html',
                               title="Get Code",
                               warning=warning)
Exemplo n.º 3
0
def upload(sid):
    """Handle the upload of a file."""
    question_json = util.request_form_to_json(request)
    if question_json['question'] == '':
        return "Pls input quesiton"
    print("=== Form Data ===")

    exact_path = os.path.join(os.getcwd(), "static/uploads")
    # try:
    #     os.makedirs(target)
    # except:
    #     return "Couldn't create upload directory: {}".format(target)
    images = []
    for f in request.files.getlist("file"):
        upload_key = str(uuid4())
        print(f)
        filename = f.filename.rsplit("/")[0]
        print(filename)
        newname = upload_key + '.' + filename.split('.')[-1]
        destination = "/".join([exact_path, newname])
        f.save(destination)
        images.append('static/uploads/' + newname)

    if len(images) == 0:
        return "No Image uploaded!"
    question_json['questionContent'] = ';'.join(images)
    rev_json = api.create_question(question_json)

    if rev_json is False:
        return "Add New Question Failed"
    survey = api.get_survey_by_id(int(sid))
    survey = util.extract_survey_json(survey)
    return render_template('surveydetail.html',
                           title="Survey_Adding_Questions",
                           survey=survey)
Exemplo n.º 4
0
def send_invitations(id):
    json = util.request_form_to_json(request)
    json['surveyId'] = id
    user_id = api.get_user_id(username=current_user.username)
    if user_id:
        json['userId'] = api.get_user_id(username=current_user.username)
        print(json)
        return api.send_invitations(json)
Exemplo n.º 5
0
def save_answer_form(id):
    '''
    :param id:
    :return:
    accept answer_a_survey page submission;
    '''
    answer_json = util.request_form_to_json(request)
    survey = api.get_survey_by_id(id)
    answer_json['surveyLink'] = api.get_survey_by_id(id)['link']
    answer = util.parse_answer_json(answer_json)
    rev = api.create_answer(answer)
    return str(rev)
Exemplo n.º 6
0
def send_new_question(sid):
    '''
    Get question data and send to backend db
    '''
    print(this_function_name)
    question_json = util.request_form_to_json(request)
    print(question_json)
    rev_json = api.create_question(question_json)
    if rev_json is False:
        return "Add New Question Failed"
    survey = api.get_survey_by_id(int(sid))
    survey = util.extract_survey_json(survey)
    return render_template('surveydetail.html',
                           title="Survey_Adding_Questions",
                           survey=survey)
Exemplo n.º 7
0
def add_new_question(sid):
    '''
    GET: return selectQuestionType.html to let user choose question type
    POST: return createQuestion.html to let user create question content
    '''
    print(this_function_name)
    if request.method == 'GET':
        print("GET Questions")
        return render_template('selectQuestionType.html',
                               title="New Question",
                               surveyId=sid)
    survey_json = util.request_form_to_json(request)
    print(survey_json)
    question_type = survey_json['questionType']
    return render_template('createQuestion.html',
                           title='New Question',
                           surveyId=sid,
                           questionType=question_type)
Exemplo n.º 8
0
def add_new_survey():
    print(this_function_name)
    if request.method == 'GET':
        print("GET Surveys")
        return render_template('newSurveyForm.html', title="Create Survey")

    survey_json = util.request_form_to_json(request)
    print(survey_json)
    if survey_json and survey_json['surveyType']:
        if survey_json['startTime'] == '':
            survey_json['startTime'] = strftime("%Y-%m-%d %H:%M", localtime())

        if survey_json['endTime'] == '':
            end_time = datetime.datetime.now() + datetime.timedelta(days=30)
            endTime = end_time.strftime("%Y-%m-%d %H:%M")
            survey_json['endTime'] = endTime

        rev = api.create_survey(survey_json)
        return redirect(url_for('get_survey_by_id', id=rev['id']))
    return render_template('newSurveyForm.html', title='CREATE SURVEY')
Exemplo n.º 9
0
def save_answer_form_link(uuid):
    answer_json = util.request_form_to_json(request)
    answer_json['surveyLink'] = uuid
    answer = util.parse_answer_json(answer_json)
    rev = api.create_answer(answer)
    return str(rev)