Example #1
0
def api_register_put():
    username = request.form.get('username')
    email = request.form.get('email')
    new_password = request.form.get('new-password')

    username_exists = check_username(username)
    email_exists = check_email(email)
    email_syntax_ok = syntax_check.check_email_syntax(email)
    username_syntax_ok = syntax_check.check_username_syntax(username)
    password_syntax_ok = syntax_check.check_password_syntax(new_password)
    form_filled = username and new_password and email

    if not form_filled:
        return make_response('MISSING ARGS', 422)
    elif not email_syntax_ok:
        return make_response('INVALID EMAIL SYNTAX', 422)
    elif not username_syntax_ok:
        return make_response('INVALID USERNAME SYNTAX', 422)
    elif not password_syntax_ok:
        return make_response('INVALID PASSWORD SYNTAX', 422)
    elif username_exists:
        return make_response('USERNAME EXISTS', 422)
    elif email_exists:
        return make_response('EMAIL EXISTS', 422)
    else:
        cookie_id = generate_hash()
        add_new_user(username, email, new_password, cookie_id)
        resp = make_response(make_response('OK', 201))
        resp.set_cookie(COOKIE_NAME, cookie_id, max_age=60 * 60 * 24 * 30)
        return resp
Example #2
0
def web_email_exists():
    email = request.form.get('email')
    email = email.strip() if email else None
    email_syntax_ok = check_email_syntax(email)

    if not email:
        return 'NO EMAIL'
    elif not email_syntax_ok:
        return 'INVALID SYNTAX'
    elif check_email(email):
        return 'ALREADY EXISTS'
    else:
        return 'OK'
Example #3
0
def api_email_exists_get():
    email = request.form.get('email')
    email = email.strip() if email else None
    email_syntax_ok = check_email_syntax(email)

    if not email:
        return make_response('NO EMAIL', 422)
    elif not email_syntax_ok:
        return make_response('INVALID SYNTAX', 200)
    elif check_email(email):
        return make_response('ALREADY EXISTS', 200)
    else:
        return make_response('OK', 200)
Example #4
0
def web_settings_processor():
    username = request.form.get('username')
    email = request.form.get('email')
    repeat_email = request.form.get('repeat-email')
    new_password = request.form.get('new-password')
    repeat_new_password = request.form.get('repeat-new-password')

    user = get_user()
    new_password_check = new_password == repeat_new_password
    email_check = email == repeat_email
    username_exists = check_username(username)
    email_exists = check_email(email)
    email_syntax_ok = syntax_check.check_email_syntax(email)
    username_syntax_ok = syntax_check.check_username_syntax(username)
    password_syntax_ok = syntax_check.check_password_syntax(new_password)

    if not user:
        return redirect('/logout/', code=302)
    elif email and not email_syntax_ok:
        return render_template('status/error.html', code='wrong_email_syntax')
    elif username and not username_syntax_ok:
        return render_template('status/error.html',
                               code='wrong_username_syntax')
    elif new_password and not password_syntax_ok:
        return render_template('status/error.html',
                               code='wrong_password_syntax')
    if not new_password_check:
        return render_template('status/error.html',
                               code='passwords_do_not_match')
    elif not email_check:
        return render_template('status/error.html', code='emails_do_not_match')
    elif username_exists:
        return render_template('status/error.html', code='username_exists')
    elif email_exists:
        return render_template('status/error.html', code='email_exists')

    if username:
        update_user(user, username=username)
    if email:
        update_user(user, email=email)
    if new_password:
        cookie_id = generate_hash()
        update_user(user, new_password=new_password, cookie_id=cookie_id)
        resp = make_response(
            render_template('status/success.html', code='edit_success'))
        resp.set_cookie(COOKIE_NAME, cookie_id, max_age=60 * 60 * 24 * 30)
        return resp

    return render_template('status/success.html', code='edit_success')
Example #5
0
def api_settings_post():
    username = request.form.get('username')
    email = request.form.get('email')
    new_password = request.form.get('new-password')

    user = get_user()
    username_exists = check_username(username)
    email_exists = check_email(email)
    email_syntax_ok = syntax_check.check_email_syntax(email)
    username_syntax_ok = syntax_check.check_username_syntax(username)
    password_syntax_ok = syntax_check.check_password_syntax(new_password)

    if not user:
        return make_response('NO USER', 422)
    elif email and not email_syntax_ok:
        return make_response('INVALID EMAIL SYNTAX', 422)
    elif username and not username_syntax_ok:
        return make_response('INVALID USERNAME SYNTAX', 422)
    elif new_password and not password_syntax_ok:
        return make_response('INVALID PASSWORD SYNTAX', 422)
    elif username_exists:
        return make_response('USERNAME EXISTS', 422)
    elif email_exists:
        return make_response('EMAIL EXISTS', 422)

    if username:
        update_user(user, username=username)
    if email:
        update_user(user, email=email)
    if new_password:
        cookie_id = generate_hash()
        update_user(user, new_password=new_password, cookie_id=cookie_id)
        resp = make_response(make_response('OK', 200))
        resp.set_cookie(COOKIE_NAME, cookie_id, max_age=60 * 60 * 24 * 30)
        return resp

    return make_response('OK', 200)
Example #6
0
def web_register_processor():
    username = request.form.get('username')
    email = request.form.get('email')
    new_password = request.form.get('new-password')
    repeat_new_password = request.form.get('repeat-new-password')

    username_exists = check_username(username)
    email_exists = check_email(email)
    email_syntax_ok = syntax_check.check_email_syntax(email)
    username_syntax_ok = syntax_check.check_username_syntax(username)
    password_syntax_ok = syntax_check.check_password_syntax(new_password)
    form_filled = username and new_password and repeat_new_password and email

    if not form_filled:
        return render_template('status/error.html', code='form_not_filled')
    elif not email_syntax_ok:
        return render_template('status/error.html', code='wrong_email_syntax')
    elif not username_syntax_ok:
        return render_template('status/error.html',
                               code='wrong_username_syntax')
    elif not password_syntax_ok:
        return render_template('status/error.html',
                               code='wrong_password_syntax')
    elif username_exists:
        return render_template('status/error.html', code='username_exists')
    elif email_exists:
        return render_template('status/error.html', code='email_exists')
    elif new_password != repeat_new_password:
        return render_template('status/error.html',
                               code='passwords_do_not_match')
    else:
        cookie_id = generate_hash()
        add_new_user(username, email, new_password, cookie_id)
        resp = make_response(
            render_template('status/success.html', code='register_success'))
        resp.set_cookie(COOKIE_NAME, cookie_id, max_age=60 * 60 * 24 * 30)
        return resp