Esempio n. 1
0
 def create(self, validated_data):
     with transaction.atomic():
         instance = UserInfo()
         instance.role_id = validated_data.get("role_id", '')
         instance.username = validated_data.get("username", '')
         password = validated_data.get("password")
         instance.password = make_password(password)
         instance.save()
     return instance
Esempio n. 2
0
def register(request):
    username = request.POST.get('username')
    password = request.POST.get('password')
    users = UserInfo.objects.all()
    for user in users:
        if username == user.username:
            return JsonResponse({'res': 0})
    newuser = UserInfo()
    newuser.username = username
    newuser.password = password
    newuser.save()
    return JsonResponse({'res': 1})
Esempio n. 3
0
def register(request):
    username = request.POST.get("username")
    passwd = request.POST.get("password")
    confirm_passwd = request.POST.get("confirm_password")
    email= request.POST.get("email")
    if passwd==confirm_passwd and len(passwd) >= 8:
        user = UserInfo()
        passwd = gen_sec_passwd(passwd)
        confirm_passwd = gen_sec_passwd(confirm_passwd)
        user.username = username
        user.passwd = passwd
        user.confirm_passwd = confirm_passwd
        user.email = email
        user.save()
        print("加密后的密码是:%s"%passwd)

        return HttpResponse("注册成功")
    print("*"*50)
    print(username, passwd, confirm_passwd, email)

    return HttpResponse("密码输入不符合规范")
Esempio n. 4
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            email = request.POST.get('email', '')
            if UserInfo.objects.filter(email=email):
                return render(request, 'register.html', {
                    'register_form': register_form,
                    'message': '用户已经存在!'
                })
            pass_word = request.POST.get('password', '')

            user_profile = UserInfo()
            user_profile.username = email
            user_profile.email = email
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)
            user_profile.save()

            # 发送邮箱,这里会生成一个16位随机数并存储到EmailVerify中
            send_register_email(email, 'register')
            return HttpResponseRedirect(reverse('user:login'))
        else:
            return render(request, 'register.html',
                          {'register_form': register_form})