コード例 #1
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
def reset_pwd(request):
    if not request.user.is_authenticated():
        return JsonResponse({'error':u'用户没有登录'})

    reset = utils.load_json(request)
    old_pass = reset['old_pass'].strip()
    new_pass = reset['new_pass'].strip()
    new_pass_cfm = reset['new_pass_cfm'].strip()

    if old_pass is None or new_pass is None or new_pass_cfm is None:
        return JsonResponse({'error':u'密码不可为空'})

    if new_pass != new_pass_cfm:
        return JsonResponse({'error':u'新密码不一致'})
    if len(new_pass) < 8:
        return JsonResponse({'error':u'新密码长度不可少于8位'})

    # if 1 == User.objects.filter(username=request.user.username).update(password=new_pass):
    #     return JsonResponse({'info':'success'})

    user = User.objects.get(username=request.user.username)
    user.set_password(new_pass)
    user.save()

    return JsonResponse({'info':'success'})
コード例 #2
0
def reset_pwd(request):
    if not request.user.is_authenticated():
        return JsonResponse({'error': u'用户没有登录'})

    reset = utils.load_json(request)
    old_pass = reset['old_pass'].strip()
    new_pass = reset['new_pass'].strip()
    new_pass_cfm = reset['new_pass_cfm'].strip()

    if old_pass is None or new_pass is None or new_pass_cfm is None:
        return JsonResponse({'error': u'密码不可为空'})

    if new_pass != new_pass_cfm:
        return JsonResponse({'error': u'新密码不一致'})
    if len(new_pass) < 8:
        return JsonResponse({'error': u'新密码长度不可少于8位'})

    # if 1 == User.objects.filter(username=request.user.username).update(password=new_pass):
    #     return JsonResponse({'info':'success'})

    user = User.objects.get(username=request.user.username)
    user.set_password(new_pass)
    user.save()

    return JsonResponse({'info': 'success'})
コード例 #3
0
def sign_up(request):

    try:
        signup = utils.load_json(request)
    except:
        return JsonResponse({'error': u'参数格式有误'})

    username = signup['username'].strip()
    password = signup['password'].strip()
    password_confirmed = signup['password_confirmed'].strip()
    email = signup['email'].strip()

    username_regex = re.compile(r'[\dA-Za-z]+[\dA-Za-z_]*')
    email_regex = re.compile(
        r"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b", re.IGNORECASE)

    #validate form data
    if username is None:
        return JsonResponse({'error': u'用户名不可为空'})
    if len(username) < 6:
        return JsonResponse({'error': u'用户名长度不可少于6位'})
    user_reg_m = username_regex.match(username)
    if user_reg_m is None or user_reg_m.group() != username:
        return JsonResponse({'error': u'用户名只能包含字母、数字及下划线,且必须字母或数字开头'})
    try:
        user = User.objects.get(username=username)
        if user is not None:
            return JsonResponse({'error': u'此用户名已被注册'})
    except Exception as e:
        pass
    if password is None or password_confirmed is None:
        return JsonResponse({'error': u'密码不可为空'})
    if password_confirmed != password:
        return JsonResponse({'error': u'密码不一致'})
    if len(password) < 8:
        return JsonResponse({'error': u'密码长度不可少于8位'})
    if email is None:
        return JsonResponse({'error': u'邮箱地址不可为空'})
    email_reg_m = email_regex.match(email)
    if email_reg_m is None or email_reg_m.group() != email:
        return JsonResponse({'error': u'邮箱地址格式不正确'})
    try:
        user = User.objects.get(email=email)
        if user is not None:
            return JsonResponse({'error': u'此邮箱已被注册'})
    except Exception as e:
        pass
    new_user = User.objects.create_user(username,
                                        email=email,
                                        password=password)
    # new_user.is_active = False
    new_user.save()

    #launch potential partner approval process
    RegistryApprovalFlow.start.run(created_by=new_user)

    return JsonResponse({'info': 'success', 'id': new_user.id})
コード例 #4
0
def _query(request, is_active, is_formal):
    if request.method == 'POST':
        pd = utils.load_json(request)

        form = PotentialSearchForm(request.POST)
        # if form.is_valid():
        #     pd = form.cleaned_data
        # query
        kwargs = {}
        if pd['zh_name'] is not None and '' != pd['zh_name']:
            kwargs['zh_name__icontains'] = pd['zh_name']

        if pd['en_name'] is not None and '' != pd['en_name']:
            kwargs['en_name__icontains'] = pd['en_name']

        if pd['licence'] is not None and '' != pd['licence']:
            kwargs['licence__icontains'] = pd['licence']

        if pd['contact'] is not None and '' != pd['contact']:
            kwargs['contact__icontains'] = pd['contact']

        if pd['tax'] is not None and '' != pd['tax']:
            kwargs['tax__icontains'] = pd['tax']

        if pd['orgCode'] is not None and '' != pd['orgCode']:
            kwargs['orgCode__icontains'] = pd['orgCode']

        kwargs['is_active'] = is_active
        kwargs['is_formal'] = is_formal

        # pagination
        potential_list = Potential.objects.filter(**kwargs)
        paginator = Paginator(potential_list, 6)  # 6 records / per page

        page = request.GET.get('page')  # pageNo

        try:
            potentials = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            potentials = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            potentials = paginator.page(paginator.num_pages)

        list = []
        for potential in potentials:
            list.append(potential.tojson())

        response_data = {}
        response_data['potentials'] = list
        response_data['paginator.num_pages'] = potentials.paginator.num_pages
        response_data['number'] = potentials.number

        return response_data
コード例 #5
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
def _query(request, is_active, is_formal):
    if request.method == 'POST':
        pd = utils.load_json(request)

        form = PotentialSearchForm(request.POST)
        # if form.is_valid():
        #     pd = form.cleaned_data
            # query
        kwargs = {}
        if pd['zh_name'] is not None and '' != pd['zh_name']:
            kwargs['zh_name__icontains'] = pd['zh_name']

        if pd['en_name'] is not None and '' != pd['en_name']:
            kwargs['en_name__icontains'] = pd['en_name']

        if pd['licence'] is not None and '' != pd['licence']:
            kwargs['licence__icontains'] = pd['licence']

        if pd['contact'] is not None and '' != pd['contact']:
            kwargs['contact__icontains'] = pd['contact']

        if pd['tax'] is not None and '' != pd['tax']:
            kwargs['tax__icontains'] = pd['tax']

        if pd['orgCode'] is not None and '' != pd['orgCode']:
            kwargs['orgCode__icontains'] = pd['orgCode']

        kwargs['is_active'] = is_active
        kwargs['is_formal'] = is_formal

        # pagination
        potential_list = Potential.objects.filter(**kwargs)
        paginator = Paginator(potential_list, 6) # 6 records / per page

        page = request.GET.get('page') # pageNo

        try:
            potentials = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            potentials = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            potentials = paginator.page(paginator.num_pages)

        list = []
        for potential in potentials:
            list.append(potential.tojson())

        response_data = {}
        response_data['potentials'] = list
        response_data['paginator.num_pages'] = potentials.paginator.num_pages
        response_data['number'] = potentials.number

        return response_data
コード例 #6
0
    def get_object(self):
        input = utils.load_json(self.request)
        contact = input['contact']
        potential = input['potential']
        user = self.request.user

        self.activation.process.potential = \
            self._save_potential(user=user, contact=contact, potential=potential)
        self.activation.process.save()

        return self.activation.process.potential
コード例 #7
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
def sign_up(request):

    try:
        signup = utils.load_json(request)
    except:
        return JsonResponse({'error':u'参数格式有误'})

    username = signup['username'].strip()
    password = signup['password'].strip()
    password_confirmed = signup['password_confirmed'].strip()
    email = signup['email'].strip()

    username_regex = re.compile(r'[\dA-Za-z]+[\dA-Za-z_]*')
    email_regex = re.compile(r"\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b", re.IGNORECASE)

    #validate form data
    if username is None:
        return JsonResponse({'error':u'用户名不可为空'})
    if len(username) < 6:
        return JsonResponse({'error':u'用户名长度不可少于6位'})
    user_reg_m = username_regex.match(username)
    if user_reg_m is None or user_reg_m.group() != username:
        return JsonResponse({'error':u'用户名只能包含字母、数字及下划线,且必须字母或数字开头'})
    try:
        user = User.objects.get(username=username)
        if user is not None:
            return JsonResponse({'error':u'此用户名已被注册'})
    except Exception as e:
        pass
    if password is None or password_confirmed is None:
        return JsonResponse({'error':u'密码不可为空'})
    if password_confirmed != password:
        return JsonResponse({'error':u'密码不一致'})
    if len(password) < 8:
        return JsonResponse({'error':u'密码长度不可少于8位'})
    if email is None:
        return JsonResponse({'error':u'邮箱地址不可为空'})
    email_reg_m = email_regex.match(email)
    if email_reg_m is None or email_reg_m.group() != email:
        return JsonResponse({'error':u'邮箱地址格式不正确'})
    try:
        user = User.objects.get(email=email)
        if user is not None:
            return JsonResponse({'error':u'此邮箱已被注册'})
    except Exception as e:
        pass
    new_user = User.objects.create_user(username, email=email, password=password)
    # new_user.is_active = False
    new_user.save()

    #launch potential partner approval process
    RegistryApprovalFlow.start.run(created_by=new_user)

    return JsonResponse({'info':'success', 'id':new_user.id})
コード例 #8
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
    def post(self, request, *args, **kwargs):
        input = utils.load_json(self.request)
        task_id = input['task_id']
        assign_to = User.objects.get(id=input['assign_to'])

        if '_assign' or '_continue' in request.POST:
            self.assign(assign_to)
            # task_message_user(
            #     request, self.task,
            #     'assigned to {}'.format(request.user.get_full_name() or request.user.username))
            # return JsonResponse(r'{"info":"assigned to %(owner)s"}' % {'owner':assign_to.username})
            return JsonResponse({"info":"assigned to %s" % assign_to.username})
        else:
            return self.get(request, *args, **kwargs)
コード例 #9
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
    def activation_done(self, *args, **kwargs):
        input = utils.load_json(self.request)
        potential_id = input['potential_id']
        try:
            potential = Potential.objects.get(id=potential_id)
        except Potential.DoesNotExist:
            potential = None

        if potential is None:
            return JsonResponse({'error':'指定的合作伙伴不存在'})

        self.process.created_by = self.request.user
        self.process.potential = potential
        self.done()
コード例 #10
0
    def activation_done(self, *args, **kwargs):
        input = utils.load_json(self.request)
        potential_id = input['potential_id']
        try:
            potential = Potential.objects.get(id=potential_id)
        except Potential.DoesNotExist:
            potential = None

        if potential is None:
            return JsonResponse({'error': '指定的合作伙伴不存在'})

        self.process.created_by = self.request.user
        self.process.potential = potential
        self.done()
コード例 #11
0
    def post(self, request, *args, **kwargs):
        input = utils.load_json(self.request)
        task_id = input['task_id']
        assign_to = User.objects.get(id=input['assign_to'])

        if '_assign' or '_continue' in request.POST:
            self.assign(assign_to)
            # task_message_user(
            #     request, self.task,
            #     'assigned to {}'.format(request.user.get_full_name() or request.user.username))
            # return JsonResponse(r'{"info":"assigned to %(owner)s"}' % {'owner':assign_to.username})
            return JsonResponse({"info":"assigned to %s" % assign_to.username})
        else:
            return self.get(request, *args, **kwargs)
コード例 #12
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
    def _approve(self):
        input = utils.load_json(self.request)

        self.activation.process.comment = input['proc_comment'].strip()
        if 'True' == input['is_approved']:
            self.activation.process.is_approved = True
        else:
            self.activation.process.is_approved = False
        self.activation.process.approver = self.request.user
        self.activation.process.save()

        if self.activation.process.is_approved is True:
            self.activation.process.potential.is_formal = True
            self.activation.process.potential.save()

        return self.activation.process
コード例 #13
0
    def _approve(self):
        input = utils.load_json(self.request)

        self.activation.process.comment = input['proc_comment'].strip()
        if 'True' == input['is_approved']:
            self.activation.process.is_approved = True
        else:
            self.activation.process.is_approved = False
        self.activation.process.approver = self.request.user
        self.activation.process.save()

        if self.activation.process.is_approved is True:
            self.activation.process.potential.is_formal = True
            self.activation.process.potential.save()

        return self.activation.process
コード例 #14
0
def sign_in(request):
    signin = utils.load_json(request)
    username = signin['username'].strip()
    password = signin['password'].strip()

    if username is None or password is None:
        return JsonResponse({'error': u'缺少用户名或密码'})

    user = authenticate(username=username, password=password)
    if user is None:
        return JsonResponse({'error': u'用户名或密码错误'})
    elif user.is_active:
        login(request, user)
    else:
        return JsonResponse({'error': u'该用户已被冻结'})

    # return HttpResponseRedirect('')
    return JsonResponse({'info': 'success'})
コード例 #15
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
def sign_in(request):
    signin = utils.load_json(request)
    username = signin['username'].strip()
    password = signin['password'].strip()

    if username is None or password is None:
        return JsonResponse({'error':u'缺少用户名或密码'})

    user = authenticate(username=username, password=password)
    if user is None:
        return JsonResponse({'error':u'用户名或密码错误'})
    elif user.is_active:
        login(request, user)
    else:
        return JsonResponse({'error':u'该用户已被冻结'})

    # return HttpResponseRedirect('')
    return JsonResponse({'info':'success'})
コード例 #16
0
ファイル: views.py プロジェクト: dakeiskind/partner_sys
def del_formals(request):
    ids = utils.load_json(request)['ids']
    for o in ids:
        Potential.objects.get(id=o['id']).delete()

    return JsonResponse({'info':'success'})
コード例 #17
0
def del_formals(request):
    ids = utils.load_json(request)['ids']
    for o in ids:
        Potential.objects.get(id=o['id']).delete()

    return JsonResponse({'info': 'success'})
コード例 #18
0
def fill_in(request):
    input = utils.load_json(request)
    # contact = input['contact']
    # potential = input['potential']
    user_id = input['user_id']
    process_id = input['process_id']

    user = User.objects.get(id=user_id)
    if user is None:
        return JsonResponse({'error':r'尚未进行用户注册'})

    # process = PotentialApprovalProcess.objects.get(id=process_id)

    if False:
        c = Contact()
        c.name = 'contact_01'
        c.title = 'no title'
        c.tel = '110'
        c.mobile = '13800138000'
        c.idCard = 'mei you'
        c.email = '*****@*****.**'
        c.idCopy = 'ye mei you'
        # c.name = contact.name
        # c.title = contact.title
        # c.tel = contact.tel
        # c.mobile = contact.mobile
        # c.idCard = contact.idCard
        # c.email = contact.email
        # c.idCopy = contact.idCopy
        # print(utils.to_json(c))
        print(c.__dict__)
        # c.save()


        p = Potential()
        p.zh_name = u'供应商_01'
        p.en_name = 'partner_01'
        p.ceo = 'Whoever'
        p.scope = 'what?'
        p.founding = datetime.datetime.today()
        p.capital = 100000000000
        p.licence = '0101010101010'
        p.licenceCopy = 'mei you'
        p.tax = 'mei you'
        p.taxCopy = 'ye mei you'
        p.orgCode = '250'
        p.orgCodeCopy = 'mei you'
        p.employees = 3
        p.address = r'beijing'
        p.homepage = r'www.bjhjyd.gov.cn'
        p.tel = '62620202'
        p.fax = '66668888'
        p.post = u'北京市630信箱'
        p.summary = 'blahblahblah....'
        # p.zh_name = potential.zh_name
        # p.en_name = potential.en_name
        # p.ceo = potential.ceo
        # p.scope = potential.scope
        # p.founding = potential.founding
        # p.capital = potential.capital
        # p.licence = potential.license
        # p.licenceCopy = potential.licenceCopy
        # p.tax = potential.tax
        # p.taxCopy = potential.taxCopy
        # p.orgCode = potential.orgCode
        # p.orgCodeCopy = potential.orgCodeCopy
        # p.employees = potential.employees
        # p.address = potential.address
        # p.homepage = potential.homepage
        # p.tel = potential.tel
        # p.fax = potential.fax
        # p.post = potential.post
        # p.summary = potential.summary
        # p.contact = c
        p.user = user
        # print(utils.to_json(p))
        print(p.__dict__)
        # p.save()

        # RegistryApprovalFlow.fill_in.run()
        return JsonResponse({'contact':c.id, 'potential':p.id})