コード例 #1
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST or None)
        form.need_confirm = False
        if form.is_valid():
            clean_data = form.cleaned_data
            email = clean_data.get('email', None)
            password = clean_data.get('password', None)
            validate_code = clean_data.get('validate_code', None)
            invite_code = clean_data.get('invite_code', None)

            user = UserModel.objects.filter(email=email)
            if user:
                return Response(status=status.HTTP_409_CONFLICT)
            else:
                user = UserModel()
                user.email = email
                encode_password = make_password(password)
                user.password = encode_password
                records = MailCodeModel.objects.filter(code=validate_code)
                if records:
                    user.active = True

                invitation = InvitationCodeModel.objects.filter(
                    code=invite_code, active=False)
                if invitation:
                    invitation.active = True
                    user.invite = True
                    invitation.save()
                user.save()
                return Response(status=status.HTTP_200_OK)
    return Response(status=status.HTTP_400_BAD_REQUEST)
コード例 #2
0
def register(request):
    """注册接口"""
    cookie = request.COOKIES
    print(cookie)
    if request.method == "POST":
        # 忽略参数为空的情况
        username = request.POST.get("username", "")
        if not username:
            return JsonResponse({"error": "请输入用户名"})
        password = request.POST.get("password", "")
        phone = request.POST.get("phone", "")
        address = request.POST.get("address", "")
        email = request.POST.get("email", "")

        # 新建用户
        user = UserModel()
        user.username = username
        # 密码加密后存储
        user.password = make_password(password)
        user.phone = phone
        user.address = address
        user.email = email
        user.save()

        return JsonResponse({"user": "******"})

    return render(request, "user/register.html")
コード例 #3
0
 def post(self, request):
     username = request.data["nickName"]
     userrole = request.data["role"]
     userlevel = request.data["level"]
     print(username)
     print(userrole)
     print(request.data)
     try:
         find1 = UserModel.objects.filter(U_name=username).first()
     except:
         find1 = None
     if (find1):
         find2 = UserModel.objects.filter(U_name=username, U_role=userrole).first()
         # find2 = find1.objects.filter(U_role=userrole).first()
         if find2:
             if int(userlevel) > int(find2.U_level):
                 find2.U_level = userlevel
                 find2.save()
         else:
             user = UserModel()
             user.U_name = username
             user.U_level = userlevel
             user.U_role = userrole
             user.save()
             return HttpResponse(status=200)
     else:
         user = UserModel()
         user.U_name= username
         user.U_level = userlevel
         user.U_role = userrole
         # print(user.role)
         user.save()
         return HttpResponse(status=200)
     return HttpResponse(status=200)
コード例 #4
0
def regist(request):
    """注册接口"""
    cookie = request.COOKIES
    print(cookie)

    if request.method == 'POST':
        # 格式验证在前端
        username = request.POST.get('username','')
        password = request.POST.get('password','')
        phone = request.POST.get('phone','')
        address = request.POST.get('address','')
        email = request.POST.get('email','')

        # 保存到数据库
        user = UserModel()
        user.username = username
        # 密码加密后存储
        user.password = make_password(password)
        user.phone = phone
        user.address = address
        user.email = email
        user.save()
        return JsonResponse({'user':'******'})

    return render(request,'user/regist.html')
コード例 #5
0
    def mutate(self, info, name, last_name):
        user = UserModel(name=name, last_name=last_name)
        user.save()

        NewUsersSubscription.broadcast(
            # Subscription group to notify clients in.
            group='group42',

            # Dict delivered to the `publish` method.
            # Can not pass objects, So pass id And resolve it on Subscription
            payload=user.id)

        return CreateUserMutation(user=user)
コード例 #6
0
    def post(self, request):
        form = RegisterForm(request.POST)
        if form.is_valid() is False:
            return HttpResponse(render(request, template_name='register.html', context={'form': form}), status=400)

        data = form.cleaned_data
        print(data)

        new_model = UserModel(name=data['name'], email=data['email'],
                              password=data['password'], age=data['age'], gender=data['gender'])
        new_model.save()
        request.session['logged-in'] = True
        request.session['logged-in-user'] = new_model.name
        return HttpResponseRedirect('/')
コード例 #7
0
ファイル: views.py プロジェクト: breeze1355/sealion
def register(request):
    """
    用户注册
    :param request:POST
    :return: 注册成功返回登陆页面 注册失败返回提示信息
    """
    if request.method == 'POST':
        register_form = forms.RegisterForm(request.POST)
        register_error = "请检查填写的内容!"
        if register_form.is_valid():
            nick_name = register_form.cleaned_data['nick_name']
            password = register_form.cleaned_data['password']
            tel = register_form.cleaned_data['tel']
            email = register_form.cleaned_data['email']
            username = register_form.cleaned_data['username']
            std_num = register_form.cleaned_data['std_num']
            std_class = register_form.cleaned_data['std_class']
            same_tel = UserModel.objects.filter(tel=tel)
            nick_name_only = UserModel.objects.filter(nick_name=nick_name)
            if same_tel:
                register_error = '该手机号已被注册,请使用别的手机号码!'
                return render(request, 'login/register.html', locals())
            if nick_name_only:
                register_error = '此昵称已存在!'
                return render(request, 'login/register.html', locals())
            new_user = UserModel()
            new_user.nick_name = nick_name
            new_user.username = username
            new_user.password = hash_code(password)
            new_user.tel = hash_code(tel)
            new_user.email = email
            new_user.std_num = std_num
            new_user.std_class = std_class
            new_user.save()
            avatar = UserAvatar(user=new_user)
            avatar.save()
            return redirect("userApp:login")
        else:
            return render(request, 'login/register.html', locals())
    register_form = forms.RegisterForm()
    return render(request, 'login/register.html', locals())
コード例 #8
0
def register(request):
    """注册接口"""
    if request.method == 'POST':
        # 忽略参数为空
        username = request.POST.get('username', '')
        if not username:
            return JsonResponse({'error': '请输入用户名'})
        password = request.POST.get('password', '')
        phone = request.POST.get('phone', '')
        address = request.POST.get('address', '')
        email = request.POST.get('email', '')

        # 新建用户
        user = UserModel()
        user.username = username
        # 密码加密后存储
        user.password = make_password(password)
        user.phone = phone
        user.address = address
        user.email = email
        user.save()
        return HttpResponseRedirect('/account/login')
    return render(request, 'user/register.html')
コード例 #9
0
ファイル: views.py プロジェクト: persenlee/rainbow_server
def sign_up(request):

    form = RegisterForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        clean_data = form.cleaned_data
        email = clean_data.get('email', None)
        password = clean_data.get('password', None)
        validate_code = clean_data.get('validate_code', None)
        invite_code = clean_data.get('invite_code', None)

        user = UserModel.objects.filter(email=email)
        if user:
            form.add_error(None, '邮箱已注册')
        else:
            user = UserModel()
            user.email = email
            encode_password = make_password(
                password
            )
            user.password = encode_password
            records = MailCodeModel.objects.filter(code=validate_code)
            if records:
                user.active = True

            invitation = InvitationCodeModel.objects.filter(code=invite_code, active=False)
            if invitation:
                invitation.active = True
                user.invite = True
                invitation.save()
            user.save()
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
                request.session['user_id'] = user.id
            return HttpResponseRedirect(reverse('image_browser:home'))

    return render(request, 'register.html', {'form': form})
コード例 #10
0
def register(request):
    """
    注册
    """
    if request.method == 'GET':
        return render(request, 'user/user_register.html')
    if request.method == 'POST':
        username = request.POST.get('username')
        email = request.POST.get('email')
        password = request.POST.get('password')
        icon = request.FILES.get('icon')
        # 加密
        password = make_password(password)  # 加密
        if not all([username, password, icon]):
            msg = '不能为空'
            return render(request, 'user/user_register.html', {'msg': msg})
        #创建用户
        user = UserModel(username=username,
                         email=email,
                         password=password,
                         icon=icon)
        if user:
            user.save()
        return HttpResponseRedirect(reverse('axf:mine'))