Beispiel #1
0
def register(request):
    if request.method == 'GET':
        data = {
            'title': '注册',
        }

        return render(request, 'user/register.html', context=data)
    elif request.method == "POST":
        username = request.POST.get('username')
        email = request.POST.get('email')
        password = request.POST.get('password')
        icon = request.FILES.get('icon')

        password = hash_str(password)

        user = AXFUser()
        user.u_username = username
        user.u_password = password
        user.u_email = email
        user.u_icon = icon

        user.save()

        u_token = uuid.uuid4().hex

        cache.set(u_token, user.id, timeout=68 * 60 * 24)

        send_email_activate(username, email, u_token)

        return redirect(reverse('axf:login'))
Beispiel #2
0
def register(request):
    if request.method =="GET":
        data = {
            "title": "注册"
        }
        return render(request, "user/register.html", context=data)
    elif request.method == "POST":
        username = request.POST.get("username")
        email = request.POST.get("email")
        password = request.POST.get("password")
        icon = request.FILES.get("icon")
        print(password)

        # password = hash_str(password)
        password = make_password(password)

        user = AXFUser()
        user.u_username= username
        user.u_password= password
        user.u_email= email
        user.u_icon= icon
        print(user.u_password)

        user.save()
        u_token = uuid.uuid4().hex
        cache.set(u_token, user.id, timeout=60*60*24)
        print(u_token)

        send_email_activate(username, email, u_token)

        # return HttpResponse("注册成功")
        return redirect(reverse("axf:login"))
Beispiel #3
0
def register(request):
    if request.method == 'GET':
        data = {
            'title': '注册',
        }
        return render(request, 'user/register.html', context=data)
    elif request.method == "POST":
        name = request.POST.get("name")
        email = request.POST.get("email")
        password = request.POST.get("password")
        icon = request.FILES.get("icon")

        user = AXFUser()
        user.u_username = name
        user.u_email = email
        user.u_password = make_password(password)
        user.u_icon = icon
        user.save()

        # 发送激活邮件
        u_token = uuid.uuid4().hex

        cache.set(u_token, user.id, timeout=60 * 60 * 24)

        send_email_activate(name, email, u_token)

        return render(request, 'user/login.html')
Beispiel #4
0
def register(request):
    if request.method=='GET':
        data={
            'title':'注册'
        }
        return render(request,'user/register.html',context=data)
    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=has_str(password)
        password=make_password(password)

        user=AXFUser()
        user.u_username=username
        user.u_email=email
        user.u_password=password
        user.u_icon=icon
        user.save()
        u_token=uuid.uuid4().hex
        cache=caches['redis_backend']
        cache.set(u_token,user.id,timeout=60*60*24)
        receive_email=email
        send_email_activate(username,receive_email,u_token)
        return HttpResponse('注册成功,请前往邮箱进行激活')
Beispiel #5
0
def register(request):
    if request.method == "GET":

        data = {
            'title': '注册',
        }

        return render(request, 'user/register.html', context=data)

    elif request.method == "POST":
        username = request.POST.get("username")
        email = request.POST.get("email")
        password = request.POST.get("password")
        icon = request.FILES.get("icon")

        #自己做的混淆密码机制
        # password = hash_str(password)
        #Django自带的
        password = make_password(password)

        user = User()
        user.username = username
        user.password = password
        user.u_email = email
        user.u_icon = icon

        user.save()

        u_token = uuid.uuid4().hex

        cache.set(u_token, user.id, timeout=60 * 60 * 24)

        send_email_activate(username, email, u_token)

        return redirect(reverse('app:login'))
Beispiel #6
0
def register(request):
    if request.method == 'GET':
        data = {
            "title": "注册",
        }
        return render(request, 'user/register.html', context=data)
    elif request.method == 'POST':
        username = request.POST.get("username")
        email = request.POST.get("email")
        password = request.POST.get("password")
        icon = request.FILES.get("icon")

        # password = hash_str(password)
        password = make_password(password)

        user = AXFUser()
        user.u_username = username
        user.u_email = email
        user.u_password = password
        user.u_icon = icon
        user.save()

        u_token = uuid.uuid4().hex
        cache.set(u_token, user.id, timeout=60 * 60 * 24)

        send_email_activate(username, email, u_token)

        return redirect(reverse('axf:login'))
Beispiel #7
0
def register(request):
    if request.method == 'GET':

        data = {
            'title': '注册',
        }

        error_message = request.session.get('error_message')

        if error_message:
            del request.session['error_message']
            data['error_message'] = error_message

        return render(request, 'user/register.html', context=data)

    elif request.method == 'POST':

        if str(request.POST['verify_code']).lower() != request.session.get(
                'verify_code'):
            request.session['error_message'] = '验证码不正确'

            return redirect(reverse('App:register'))

        user = Users()

        user.u_username = request.POST['username']

        user.u_email = request.POST['email']

        password = request.POST['password']
        user.u_password = hash_str(password)

        user.u_icon = request.FILES['icon']

        user.save()

        u_token = uuid.uuid4().hex

        cache.set(u_token, user.id, timeout=60 * 60 * 3)

        send_email_activate(username=user.u_username,
                            email=user.u_email,
                            u_token=u_token)

        return redirect(reverse('App:login'))
Beispiel #8
0
def register(request):
    if request.method == "GET":

        data = {
            "title": "注册",
        }

        return render(request, "user/register.html", context=data)

    elif request.method == "POST":

        username = request.POST.get("username")

        password = request.POST.get("password")

        email = request.POST.get("email")

        icon = request.FILES.get("icon")

        if not icon:
            icon = "icons/default/R9VPA(Y_G{~C_UE~DD[~F%P.png"

        # password = hash_str(password)

        password = make_password(password)  # 用官方包加密

        user = YuzuhiUser()
        user.u_username = username
        user.u_email = email
        user.u_password = password
        user.u_icon = icon
        user.save()

        u_token = uuid.uuid4().hex

        cache.set(u_token, user.id, timeout=60 * 60 * 24)

        print(u_token)

        send_email_activate(username, email, u_token)

        return redirect(reverse("yuzuhi:login"))
Beispiel #9
0
def re_activate(request):
    username = request.POST.get('username')

    user = AXFUser.objects.get(u_username=username)

    if user:

        # .hex将uuid的格式变成字符串
        u_token = uuid.uuid4().hex

        # 将用户的id做为缓存的值 在激活的时候用id去看是哪个用户 然后并激活
        cache.set(u_token, user.id, timeout=60 * 60 * 24)

        send_email_activate(username=username,
                            receive=user.u_email,
                            u_token=u_token)

        return HttpResponse('邮件已发送,请注意查收并再次激活')
    else:
        return HttpResponse('用户不存在')
Beispiel #10
0
    def post(self, request, *args, **kwargs):
        action = request.query_params.get('action')
        if action == "register":
            try:
                # 判断验证码
                code_data = check_code(request.POST.get("verify_code"),
                                       request.session.get("the_code"))
                if code_data["status"] != 200:
                    return Response(code_data)
                u_name = request.POST.get("u_name")
                print(type(u_name))
                u_email = request.POST.get("u_email")
                u_phone = request.POST.get("u_phone")
                password = request.POST.get("u_password")
                # 判断用户名、邮箱、电话是否符合条件
                name_data = check_user(u_name)
                email_data = check_email(u_email)
                phone_data = check_phone(u_phone)
                if name_data["status"] != 200:
                    return Response(name_data)
                if email_data["status"] != 200:
                    return Response(email_data)
                if phone_data["status"] != 200:
                    return Response(phone_data)
                print(request.data)
                self.create(request, *args, **kwargs)
                pwd = make_password(password)
                self.queryset.filter(u_name=u_name).update(u_password=pwd)
            except Exception as e:
                print("错误提示:", e)
                return Response({"status": 901, "msg": "信息填写有误,请重新填写"})
            # 发送激活邮件
            try:
                user = User.objects.get(u_name=u_name)
                email_token = uuid.uuid4().hex
                cache.set(email_token, user.id, timeout=60 * 60 * 24)
                send_email_activate(u_name, u_email, email_token)
            except:
                return Response({"status": 901, "msg": "您的激活邮件发送失败,请重新注册"})
            return Response({"status": 200})

        elif action == "login":
            u_name = request.data.get('u_name')
            u_password = request.data.get('u_password')

            # 首先判断验证码
            code_data = check_code(request.POST.get("verify_code"),
                                   request.session.get("the_code"))
            if code_data["status"] != 200:
                code_data["status"] = 909
                print("验证码不通过")
                return Response(code_data)
            try:
                user = User.objects.get(u_name=u_name)
                print(u_name, "用户名验证通过")
                if not user.is_active:
                    data = {
                        'msg': '用户未激活',
                        'status': 908,
                    }
                    return Response(data)
                if check_password(u_password, user.u_password):
                    print(u_name, "密码验证通过")
                    token = uuid.uuid4().hex
                    cache.set(token, user.id)
                    data = {
                        'msg': '登录成功',
                        'status': 200,
                        'token': token,
                    }
                    return Response(data)
            except Exception as e:
                print("记得打开系统的reids-server")
                print("错误提示:", e)
            return Response({"status": 901, "msg": "用户名或密码错误"})
        elif action == "logout":
            token = request.POST.get("token")
            cache.delete(token)
            return Response({'status': 200})
        elif action == "send_email":
            u_name = request.data.get('u_name')
            try:
                user = User.objects.get(u_name=u_name)
                u_email = user.u_email
                email_token = uuid.uuid4().hex
                cache.set(email_token, user.id, timeout=60 * 60 * 24)
                send_email_activate(u_name, u_email, email_token)
            except:
                return Response({"status": 901, "msg": "您的激活邮件发送失败,请重新注册"})
            return Response({"status": 200, "msg": "邮件发送成功,请前往邮箱激活"})
        else:
            print("接收到的网址有问题")
            data = {
                'msg': '网址有误',
                'status': 901,
            }
            return Response(data)