def create_user(): user = User() unencrypted_password = request.values['password'] user.name = request.values['name'] user.password = encrypt(unencrypted_password) user.mail = request.values['mail'] user.role = 'user' if 'role' in request.values: user.role = request.values['role'] if User.query.filter_by(name=user.name).first() is not None: return jsonify({'status': 'Name exists'}) if User.query.filter_by(mail=user.mail).first() is not None: return jsonify({'status': 'Name exists'}) db.session.add(user) db.session.commit() return jsonify({'id': user.id})
def createUser(request): if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): user = User() user.birth_date = form.cleaned_data.get('birth_date') user.randomId = form.cleaned_data.get('randomId') user.username = form.cleaned_data.get('username') user.password = form.cleaned_data.get('password') user.save() #import pdb; pdb.set_trace() # messages.success(request, 'Form submission successful') return redirect('list') else: form = UserForm(request.POST) return redirect('add')