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)
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))