Beispiel #1
0
def upload_password(request):
    '''个人中心里修改密码'''
    if request.method == "GET":
        # froget_form = forgetForm(request.POST)

        email = request.GET.get("email", '')
        status = send_email_register(email, "forget")
        if status:
            return ajax_ok_data(message="邮件发送成功,请注意查收")
        else:
            return ajax_fail_data(message="邮件发送成功,请注意查收")

    if request.method == "POST":
        repwd_form = resetpwdForm(request.POST)
        if repwd_form.is_valid():
            email = request.POST.get("email", '')
            code = request.POST.get("code", "")
            password1 = request.POST.get("password1", '')
            password2 = request.POST.get("password2", '')
            token = request.COOKIES.get("token")
            o = EmailVerifyRecord.objects.get(email=email,
                                              code=code,
                                              send_type="forget")
            if password1 == password2 and o:
                user = UserProfile.objects.get(token=token)
                user.password = make_password(password1)
                user.save()

                return ajax_ok_data(message="修改成功")
            else:
                return ajax_fail_data(message="兩次輸入的密碼不一致")
        data = repwd_form.errors
        return ajax_ok_data(data)
Beispiel #2
0
def reset(request):
    """找回密码发送验证码"""
    if request.method == "POST":
        email = request.POST.get("email", "")
        status = send_email_register(email, "forget")
        if status:
            return ajax_ok_data(message="邮件发送成功")
        else:
            return ajax_fail_data(message="邮件发送失败")
Beispiel #3
0
def sendemil_code(request):
    '''更换邮箱时发送邮箱验证码'''
    if request.method == "POST":

        email = request.GET.get("email", "")
        if UserProfile.objects.filter(email=email):

            return ajax_ok_data(message="此邮箱已经注册")
        status = send_email_register(email, "update_email")
        if status:
            return ajax_ok_data(message="邮件发送成功")
        else:
            return ajax_fail_data(message="邮件发送失败")
Beispiel #4
0
def active(request, active_code):
    """激活"""
    if request.method == "GET":
        emil_recode = EmailVerifyRecord.objects.filter(code=active_code)
        if emil_recode:
            for cord in emil_recode:
                email = cord.email
                user = UserProfile.objects.get(email=email)
                user.is_staff = True
                user.save()
            return ajax_ok_data()
        else:
            return ajax_fail_data()
Beispiel #5
0
def user_register(request):
    """注册"""
    if request.method == "POST":
        print("开始注册")
        register_form = RegisterForm(request.POST)
        if 1:

            email = request.POST.get("email", "")
            username = request.POST.get("username", "")
            password = request.POST.get("password", "")
            code = request.POST.get("code")
            try:
                user_profile = UserProfile.objects.get(
                    Q(username=username) | Q(email=email))

            except Exception as e:
                user_profile = None
            if user_profile:
                if user_profile.is_staff:
                    return ajax_fail_data(message="用戶已存在")
            code = EmailVerifyRecord.objects.get(code=code,
                                                 email=email,
                                                 send_type="register")
            if not code:
                return ajax_fail_data(message="请输入正确验证码")
            token = create_token(email)
            user_profile = UserProfile()
            user_profile.username = username
            user_profile.is_staff = True
            user_profile.email = email
            user_profile.password = make_password(password)
            user_profile.token = token
            user_profile.save()
            return ajax_ok_data()
        else:
            print("f**k")
            data = register_form
            return ajax_ok_data(data)
Beispiel #6
0
def upload_image(request):
    '''修改头像'''
    if request.method == "POST":
        uploadfrom = UpLoadImage(request.POST, request.FILES)
        token = request.COOKIES.get("token")
        user = UserProfile.objects.get(token=token)
        if uploadfrom.is_valid():
            image = uploadfrom.cleaned_data['image']
            user.image = image
            user.save()

            return ajax_ok_data()
        else:
            return ajax_fail_data()
Beispiel #7
0
def user_login(request):
    if request.method == "POST":

        login_form = loginform(request.POST)
        if login_form.is_valid():
            print(111)
            email = username = request.POST.get("email", "")
            password = request.POST.get("password", "")
            user = authenticate(username=username, password=password)
            if user:
                if user.is_staff:
                    # request.session["token"] = user.token
                    # response = render(request)
                    # response.set_cookie()
                    # login(request,user)
                    return ajax_ok(request)

                else:
                    return ajax_fail_data(message="用户未激活")
            else:
                return ajax_fail_data(message="用户名或者密碼錯誤")

        else:
            return ajax_fail_data(message="输入错误")
Beispiel #8
0
 def inner(reqeust, *args, **kwargs):
     v = reqeust.COOKIES.get("token")
     if not v:
         return ajax_fail_data(message="请重新登陆")
     return func(reqeust, *args, **kwargs)
Beispiel #9
0
def user_home(request):
    if request.method == "GET":
        email = request.GET.get("email", "")
        page = request.GET.get("p", "1")  #第几页
        page = int(page)
        search = request.GET.get("search", "")  #筛选条件
        print(search)
        page = int(page)
        if email:
            user = UserProfile.objects.get(Q(username=email) | Q(email=email))
        else:
            token = request.COOKIES.get("token")
            user = UserProfile.objects.get(token=token)

        page_nums = 9  #一页显示的数据数量
        user_data = user.get_data()
        if user.is_superuser:
            page_last = page * page_nums  #本页的最后一条数据
            page_first = page_last - page_nums  #本页第一条数据
            if search:
                print(88888)
                search_nums = UserProfile.objects.filter(
                    Q(username__icontains=search)
                    | Q(address__icontains=search)
                    | Q(mobile__icontains=search) | Q(gender__icontains=search)
                    | Q(email__icontains=search)).count()
                data = UserProfile.objects.filter(
                    Q(username__icontains=search)
                    | Q(address__icontains=search)
                    | Q(mobile__icontains=search) | Q(gender__icontains=search)
                    | Q(email__icontains=search))[page_first:page_last]
            else:
                data = UserProfile.objects.all()[page_first:page_last]

            users = []
            for i in data:
                i = i.get_data()
                users.append(i)
            # print (users)
            if not search:
                users.insert(0, user_data)
            if not search:
                nums = user.get_nums()  # 总的数据量
            else:
                nums = search_nums
                print(nums)
            yushu = nums % (page_nums + 1)
            pnums = nums / (page_nums + 1)  # 页数
            if yushu > 0:
                pnums += 1
            print(pnums)
            return ajax_ok_data(users, nums=pnums)
        data = user.get_data()
        print(type(user))
        # print(user_data)
        return ajax_ok_data(user_data)
    if request.method == "POST":
        print("success12")
        token = request.COOKIES.get("token")
        print(token)
        user = UserProfile.objects.get(token=token)
        print(token)
        user_info_update_form = UserInfoUpdate(request.POST, instance=user)
        if user_info_update_form.is_valid():
            user_info_update_form.save()
            print("success")
            return ajax_ok_data()
        else:
            data = user_info_update_form.errors
            print(data)
            return ajax_fail_data(data)