コード例 #1
0
ファイル: views.py プロジェクト: sourcery/xperiences
def preconfigured_merchant(request):
    if request.method == 'GET':
        form_user = UserForm()
        form_user_extension = UserExtensionForm()
        context = {'form_user' : form_user, 'form_user_extension' : form_user_extension }
        return render_to_response('preconfigured_merchant_form.html', context_instance=RequestContext(request, context))
    else:
        user= User()
        user.is_active = False
        form_user = UserForm(request.POST,request.FILES, instance=user)
        if form_user.is_valid():
            form_user.save()
            user_extension = UserExtension.create_from_user(user)
            user_extension.is_merchant = True



            form_user_extension = UserExtensionForm(request.POST,request.FILES,instance=user_extension)

            if form_user_extension.is_valid():
                form_user_extension.save()
                utils.send_email_for_preconfigured_merchant(user_extension)
                context = { 'message' : 'Settings saved successfuly', 'return_url' : '/admin/', 'return_title' : 'Back to admin home' }
                return render_to_response('admin_form_saved.html',context_instance=RequestContext(request, context ))
        else:
            form_user_extension = UserExtensionForm()
            context = {'form_user' : form_user, 'form_user_extension' : form_user_extension }
            return render_to_response('preconfigured_merchant_form.html', context_instance=RequestContext(request, context))
コード例 #2
0
ファイル: user_view.py プロジェクト: llldddbbb/LivePlatform
def signupSubmit(request):
    body = bi2obj(request)
    form = UserForm(body)
    if (form.is_valid()):
        instance = form.save(commit=False)
        if (create_user_folder(instance.username)):
            user = User.objects.create_user(
                username=instance.username,
                password=instance.password,
                gender=instance.gender,
                nickname=instance.nickname,
                email=instance.username
                if test_email(instance.username) else None,
                phone=instance.username
                if test_phone(instance.username) else None)
            form.save(commit=False)
            user.save()
            auth.login(request, user)
            session_key = get_session_key(request)
            return JsonResponse({
                'user': wrap_user(user),
                'session_key': session_key
            })
        else:
            return HttpResponse(content=CODE['1'], status=500)
    else:
        return HttpResponse(content=CODE['4'], status=400)
コード例 #3
0
def base_info(request):
    """后台个人信息"""
    username = request.session.get("username")  # 获取用户名
    userobj = models.User.objects.using("default").filter(
        username=username).first()  # 获取用户对象
    if request.method == "GET":
        userform_obj = UserForm({"username": username, "qq": userobj.qq})
        return render(request, "backend_base_info.html", {
            "username": username,
            "userform_obj": userform_obj,
            "userobj": userobj
        })
    elif request.method == "POST":
        userform_obj = UserForm(request.POST)
        if userform_obj.is_valid():
            new_username = userform_obj.cleaned_data.get("username")
            new_qq = userform_obj.cleaned_data.get("qq")
            obj1 = models.User.objects.filter(
                username=new_username).first()  # 通过用户输入用户名获取用户对象
            obj2 = models.User.objects.filter(
                qq=new_qq).first()  # 通过用户输入qq号获取用户对象
            if obj1:
                if obj1.id != userobj.id:  # 用户输入的名称能获取到对象但不是该用户本身,则用户输入名称已经存在
                    userform_obj.add_error("username", "用户名称已经存在!请重新输入!")
            else:
                userobj.username = new_username  # 用户输入名称没人用过,则直接更新用户名称, 并直接导向登录页面
                userobj.save()
                return redirect("/backend/login/")
            if obj2:
                if obj2.id != userobj.id:  # 用户输入的qq号能获取到对象但不是该用户本身,则用户输入qq号已经存在
                    userform_obj.add_error("qq", "qq号已经存在!请重新输入!")
            else:
                userobj.qq = new_qq  # 用户输入qq号没人用过,则直接更新用户qq号
                userobj.save()
        return render(request, "backend_base_info.html", {
            "username": username,
            "userform_obj": userform_obj,
            "userobj": userobj
        })
コード例 #4
0
def index(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)

        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            registered = True
        else:
            print(user_form.errors)
    else:
        user_form = UserForm()
    return render(request, "backend/index.html", {
        'user_form': user_form,
        'registered': registered
    })
コード例 #5
0
ファイル: views.py プロジェクト: Nealium/ffd
 def post(self, request):
     uf = UserForm(request.POST, prefix='user')
     print uf
     if uf.is_valid():
         user = uf.save()
         return django.http.HttpResponseRedirect()