Exemplo n.º 1
0
def register_user():
    username = request.form['username']
    password = request.form['password']
    repeated_password = request.form['repeated_password']
    try:
        user.register_user(username, password, repeated_password)
        return redirect(
            '/registration?info_message=You have been successfully registered, please sign in now'
        )
    except Exception as e:
        return redirect('/registration?info_message=' + str(e))
Exemplo n.º 2
0
def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'd76b9af7-0caf-4749-b671-65912beea187'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

    register_bootstrap(app)
    register_log(app)
    register_db(app)
    register_user(app)
    register_admin(app)

    return app
Exemplo n.º 3
0
def admin_setup():
	global user
	params = utils.flat_multi(request.form)
	if utils.is_setup_complete(): raise WebException("Setup has already been complete.")

	if params.get("verification") != Config.query.filter_by(key="setup_verification").first().value:
		raise WebException("Verification does not match.")

	if params.get("password") != params.get("password_confirm"):
		raise WebException("Passwords do not match.")
	verify_to_schema(user.UserSchema, params)

	name = params.get("name")
	email = params.get("email")
	username = params.get("username")
	password = params.get("password")
	password_confirm = params.get("password_confirm")
	utype = int(params.get("type"))

	setup_vars = [
		Config("ctf_name", params.get("ctf_name")),
		Config("start_time", params.get("start_time")),
		Config("end_time", params.get("end_time")),
		Config("team_size", params.get("team_size")),
		Config("stylesheet", "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"),
		Config("setup_complete", True)
	]

	#  _user = Users(name, username, email, password, utype=utype, admin=True)
	user.register_user(name, username, email, password, utype=utype, admin=True)
	with app.app_context():
		for var in setup_vars:
			db.session.add(var)
			db.session.commit()
			db.session.close()

	logger.log(__name__, "%s registered with %s" % (name.encode("utf-8"), email.encode("utf-8")))
	user.login_user(username, password)

	return { "success": 1, "message": "Success!" }
Exemplo n.º 4
0
 def POST(self):
     f = register_form()
     if not f.validates():
         return render.register(f)
     else:
         post_data = web.input()
         username = post_data['username']
         password = post_data['password']
         email = post_data['email']
         if register_user(username, password, email):
             return render.reg_finish('注册成功')
         else:
             return render.reg_finish('注册失败,请重试')
Exemplo n.º 5
0
def register():
    data = request.json

    err_msg = None
    if 'id' not in data:
        err_msg = 'Mandatory field "id" not present!'
    elif 'username' not in data:
        err_msg = 'Mandatory field "username" not present!'
    elif 'firstName' not in data:
        err_msg = 'Mandatory field "firstName" not present!'
    elif 'chatId' not in data:
        err_msg = 'Mandatory field "chatId" not present!'

    if err_msg is not None:
        return jsonify({"error": err_msg}), 400

    # call service, check id
    if user_exists(data['id']):
        update_user(data['id'], data)
    else:
        register_user(data)
    return jsonify({"msg": "OK"}), 200
Exemplo n.º 6
0
def index():
    '''
    The index; a simple interface for allowing a user to submit an image
    to query
    methods:
        GET: The main page, has a 'submit image' button
        POST: After the submit/query/request button is hit, the file will be saved
        to the server and the user will be redirected to the uploads page
    '''

    # Get method type
    method = flask.request.method

    # Get
    if method == 'GET':
        if 'username' in flask.session:
            print(flask.session)
            print('user (index!)', flask.session['user_id'])
            return flask.render_template('index.html')
        else:
            return flask.render_template('login.html')

    elif method == 'POST':

        request_json = get_request_json(flask.request)

        # Log in user
        if 'login' in request_json.keys():
            email = request_json['login_email_address'][0]
            password = request_json['login_password'][0]

            user_id = user.login_user(email, password)

        # Register user
        elif 'register' in request_json.keys():
            email = request_json['register_email_address'][0]
            password = request_json['register_password'][0]
            name = request_json['register_name'][0]

            user_id = user.register_user(email, password, name)

        if user_id != None:
            flask.session['username'] = email
            flask.session['user_id'] = user_id

            print('user id!!!', flask.session['user_id'])

            return flask.render_template('index.html')

        else:
            return flask.render_template('login.html')
Exemplo n.º 7
0
def signup():
    if request.method == "GET":
        form = SignupForm()
        return render_template("register.html", form=form)
    else:
        form = SignupForm(formdata=request.form)
        if form.validate():
            user = register_user(mongo=mongo, data=form.data)
            if user:
                flask.flash('Register successful. Please login now.')
                return redirect(url_for('login'))
            else:
                print('failed.')
                flask.flash('Username exist.')
        else:
            print(form.errors, "signup error")
        return render_template("register.html", form=form)
Exemplo n.º 8
0
def registration():
    ans = check_login()
    if ans:
        return ans
    if flask.request.method == "POST":
        email = flask.request.form['email']
        password = flask.request.form['pwd']
        abilities = flask.request.form['abilities']
        name = flask.request.form['name']
        surname = flask.request.form['surname']
        bio = flask.request.form['bio']
        if register_user(email, password, abilities, name, surname,
                         bio) is True:
            session['logined'] = True
            session['email'] = email
            return redirect('/')
    return render_template('registration.html', page_title="Регистрация")
Exemplo n.º 9
0
def register_user():

    data = json.loads(request.data)
    user_id = data['user_id']
    password = data['password']

    register_status = user.register_user(user_id, password)
    rank_status = rank_user.add_new_user(user_id)
    savvy_rank_status = savvy_user.add_new_user(user_id)

    result_dict = {
        "register_status": register_status,
        "rank_status": rank_status,
        "savvy_rank_status": savvy_rank_status
    }

    return jsonify(result_dict)
Exemplo n.º 10
0
def signup():
    if request.method == "GET":
        form = SignupForm()
        return render_template("register.html", form=form)
    else:
        form = SignupForm(formdata=request.form)
        if form.validate():
            data = form.data
            if data['name'] == data['pwd']:
                flask.flash('Cannot use username as password.', 'alert-danger')
                return redirect(url_for('signup'))
            user = register_user(mongo=mongo, data=form.data)
            if user:
                flask.flash('Register successful. Please login now.',
                            'alert-success')
                return redirect(url_for('login'))
            else:
                print('failed.')
                flask.flash('Username exist.', 'alert-danger')
        else:
            print(form.errors, "signup error")
        return render_template("register.html", form=form)
Exemplo n.º 11
0
def register_user_action():
    try:
        args = parse_args(4, 1)
        pprint.pprint(register_user(*args))
    except ValidationError:
        print("Please inform email, password, first and last name")
Exemplo n.º 12
0
def register_user():
    try:
        user.register_user(request.form)
        return redirect('/')
    except Exception as e:
        return redirect('/registration?info_message=' + str(e))
Exemplo n.º 13
0
 def test_register_user_invalid_response(self, mock_res):
     response = register_user("*****@*****.**", "samplepassword",
                              "Some name", "Some last name")
     self.assertEqual(response, {'message': 'validation_error'})
Exemplo n.º 14
0
 def test_register_user(self, mock_res):
     response = register_user("*****@*****.**", "samplepassword",
                              "Some name", "Some last name")
     self.assertEqual(response, "User registered.")