예제 #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")
예제 #2
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')
예제 #3
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())
예제 #4
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')