Exemplo n.º 1
0
def user_register():
    form = forms.UserRegisterForm(request.form)

    if request.method == "GET":
        return render_template('webui/user_register.html', form=form)

    if request.method == "POST":
        if not form.validate():
            return render_template('webui/user_register.html',
                                   register_description="フォームを正しく入力してください。",
                                   form=form)

        username = form.username.data
        password = form.password.data

        model = UserModel()
        if model.user_isExist(username)[0]:
            return render_template('webui/user_register.html',
                                   register_description="既に同じ名前のユーザが存在します。",
                                   form=form)

        msg, code = model.user_register(username, password)

        if code == ResultCode.Success:
            return render_template('webui/success_user_register.html')
        else:
            return render_template('webui/user_register.html',
                                   register_description="ユーザ登録に失敗しました: %s" %
                                   msg,
                                   form=form)
Exemplo n.º 2
0
def api_userid_isExist(username):
    model = UserModel()
    msg, code = model.user_isExist(username)

    if code == ResultCode.Success:
        return jsonify(_makeResponseMessage(msg))
    else:
        return jsonify(_makeErrorMessage(code))
Exemplo n.º 3
0
def api_admin_user_delete(username):
    if Util.DebugMode is False:
        return jsonify(_makeErrorMessage(0))

    model = UserModel()

    if not model.user_isExist(username)[0]:
        return jsonify(_makeErrorMessage(ResultCode.ValueError))

    msg, code = model.user_delete(username)

    if code == ResultCode.Success:
        return jsonify(_makeResponseMessage(msg))
    else:
        return jsonify(_makeErrorMessage(code))
Exemplo n.º 4
0
def api_user_register():
    username = request.args.get('username', None)
    password = request.args.get('password', None)

    if username is None or password is None:
        return jsonify(_makeErrorMessage(ResultCode.FormatError))

    if len(username) > Util.MaxUsernameLength or len(
            password) > Util.MaxUserPassLength:
        return jsonify(_makeErrorMessage(ResultCode.FormatError))

    model = UserModel()

    # get first element, because user_isExist returns "True/False, code".
    if model.user_isExist(username)[0]:
        return jsonify(_makeErrorMessage(ResultCode.ValueError))

    msg, code = model.user_register(username, password)

    if msg is None:
        return jsonify(_makeErrorMessage(code))

    return jsonify(_makeResponseMessage(msg))