Example #1
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")
Example #2
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)
Example #3
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')
Example #4
0
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())
Example #5
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')
Example #6
0
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})