Beispiel #1
0
def change_name(request):
    if request.method == 'GET':
        return render_to_response('change_name.html', context_instance=RequestContext(request))
    if request.method == 'POST':
        phone = request.POST.get('phone')
        password = request.POST.get('password')
        new_name = request.POST.get('new_name')
        merchant_phone = request.session['username']
        if phone and password and new_name:
            if not phone == merchant_phone:
                return render_to_response('change_name.html', {'fault1': 'T',
                                                               'phone': phone,
                                                               'new_name': new_name}, context_instance=RequestContext(request))
            merchant = Merchant.objects.get(alin_account=phone)
            req = merchant.check_password(password)
            if not req:
                return render_to_response('change_name.html', {'fault1': 'T',
                                                               'phone': phone,
                                                               'new_name': new_name}, context_instance=RequestContext(request))
            merchant.name = new_name
            merchant.save()
            newlog = AccountLog()
            newlog.atype = '商家'
            newlog.content = '商家更改名称'
            newlog.ltype = 15
            newlog.note = '改名'
            newlog.account = str(phone)
            newlog.save()
            return render_to_response('change_name.html', {'success': 'T', 'new_user_name': new_name}, context_instance=RequestContext(request))
        else:
            return render_to_response('change_name.html', {'phone': phone, 'new_name': new_name}, context_instance=RequestContext(request))
Beispiel #2
0
def login_in(request):
    if 'user_name' in request.POST and request.POST['user_name'] and 'password' in request.POST and request.POST['password']:
        user_name = request.POST['user_name']
        password = request.POST['password']
        try:
            user = Merchant.objects.get(alin_account=user_name)
            if user.check_password(password):
                if user.verify is False:
                    return render_to_response('login_page.html', {'flag': 2}, context_instance=RequestContext(request))
                request.session['username'] = user_name
                merchant = Merchant.objects.get(alin_account=user_name)
                merchant.update_time = datetime.datetime.now()
                merchant.is_online = True
                merchant.save()
                newlog = AccountLog()
                newlog.atype = '商家'
                newlog.content = '商家登陆'
                newlog.ltype = 11
                newlog.note = '登陆'
                newlog.account = str(user_name)
                newlog.save()
                return HttpResponseRedirect("/merchant/operate_new")
            else:
                return render_to_response('login_page.html', {'flag': 1}, context_instance=RequestContext(request))
        except Merchant.DoesNotExist:
            return render_to_response('login_page.html', {'flag': 1}, context_instance=RequestContext(request))
    else:
        return render_to_response('login_page.html', context_instance=RequestContext(request))
Beispiel #3
0
def forgetpasswd(req):
    body = {}
    if req.method == 'POST':
        reqdata = simplejson.loads(req.body)
        phone = reqdata['phone']
        currentuserset = Sender.objects.filter(phone = phone)
        if currentuserset.count() > 0:
            currentuser = currentuserset[0]
            res = createverifycode(currentuser.phone)
            jres = simplejson.loads(res)
            if jres['success'] is False:
                return HttpResponse(encodejson(2, body))
            currentuser.is_verify = True
            currentuser.verify_code = str(jres['verify_code'])
            currentuser.save()
            newlog = AccountLog()
            newlog.account = str(currentuser.phone)
            newlog.atype = '物流'
            newlog.ltype = 4
            newlog.note = '忘密'
            newlog.content = '外卖人员忘记密码'
            newlog.save()
            return HttpResponse(encodejson(1, body), content_type="application/json")
        else:
            return HttpResponse(encodejson(7, body), content_type="application/json")
    else:
        raise Http404
Beispiel #4
0
def change_password(request):
    if request.method == 'GET':
        if request.session.get('username'):
            return render_to_response('change_password.html', context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect('login_in')
    if request.method == 'POST':
        phone = request.POST.get('phone')
        old_password = request.POST.get('old_password')
        new_password = request.POST.get('new_password')
        new_password_again = request.POST.get('new_password_again')
        if phone and old_password and new_password and new_password_again:
            if not new_password == new_password_again:
                return render_to_response('change_password.html', {'fault2': 'T', 'phone': phone}, context_instance=RequestContext(request))
            if new_password == old_password:
                return render_to_response('change_password.html', {'fault4': 'T', 'phone': phone}, context_instance=RequestContext(request))
            if not phone == request.session.get('username'):
                return render_to_response('change_password.html', {'fault3': 'T', 'phone': phone}, context_instance=RequestContext(request))
            merchant = Merchant.objects.get(alin_account=phone)
            if not merchant.check_password(old_password):
                return render_to_response('change_password.html', {'fault1': 'T', 'phone': phone}, context_instance=RequestContext(request))
            password = hashlib.md5(new_password).hexdigest()
            merchant.password = password
            merchant.save()
            newlog = AccountLog()
            newlog.atype = '商家'
            newlog.content = '商家更改密码'
            newlog.ltype = 16
            newlog.note = '改密'
            newlog.account = str(phone)
            newlog.save()
            return render_to_response('change_password.html', {'success': 'T'}, context_instance=RequestContext(request))
        else:
            return render_to_response('change_password.html', context_instance=RequestContext(request))
Beispiel #5
0
def login(req):
    body = {}
    if req.method == 'POST':
        reqdata = simplejson.loads(req.body)
        username = reqdata['username']
        passwd = reqdata['password']
        sender_list = Sender.objects.filter(phone = str(username))
        if sender_list.count() > 0:
            sender = sender_list[0]
            if sender.check_password(passwd):
                mytoken = createtoken()
                sender.private_token = mytoken
                sender.active_time = datetime.datetime.now()
                sender.save()
                body["private_token"] = mytoken
                body['nick'] = str(sender.nick)
                newlog = AccountLog()
                newlog.account = str(username)
                newlog.atype = '物流'
                newlog.ltype = 1
                newlog.note = '登陆'
                newlog.content = '外卖人员登陆'
                newlog.save()
                return HttpResponse(encodejson(1, body), content_type="application/json")
            else:
                return HttpResponse(encodejson(4, body), content_type="application/json")
        else:
            return HttpResponse(encodejson(7, body), content_type="application/json")
    else:
        raise Http404
Beispiel #6
0
def changepasswd(req):
    if req.method == 'POST':
        body = {}
        reqdata = simplejson.loads(req.body)
        privatetoken = reqdata['private_token']
        passwd = reqdata['password']
        new_passwd = reqdata['new_password']
        currentuserset = Sender.objects.filter(private_token = privatetoken)
        if currentuserset.count() > 0:
            currentuser = currentuserset[0]
            lasttime = currentuser.active_time.replace(tzinfo = None)
            if not isactive(lasttime):
                return HttpResponse(encodejson(5, body), content_type="application/json")
            if currentuser.check_password(passwd):
                currentuser.password = hashlib.md5(new_passwd).hexdigest()
                currentuser.save()
                newlog = AccountLog()
                newlog.account = str(currentuser.phone)
                newlog.atype = '物流'
                newlog.ltype = 3
                newlog.note = '改密'
                newlog.content = '外卖人员更改密码'
                newlog.save()
                return HttpResponse(encodejson(1, body), content_type="application/json")
            else:
                return HttpResponse(encodejson(4, body), content_type="application/json")
        else:
            return HttpResponse(encodejson(7, body), content_type="application/json")
    else:
        raise Http404
Beispiel #7
0
def forgetpasswd(req):
    body = {}
    if req.method == 'POST':
        reqdata = simplejson.loads(req.body)
        phone = reqdata['phone']
        currentuserset = Sender.objects.filter(phone=phone)
        if currentuserset.count() > 0:
            currentuser = currentuserset[0]
            res = createverifycode(currentuser.phone)
            jres = simplejson.loads(res)
            if jres['success'] is False:
                return HttpResponse(encodejson(2, body))
            currentuser.is_verify = True
            currentuser.verify_code = str(jres['verify_code'])
            currentuser.save()
            newlog = AccountLog()
            newlog.account = str(currentuser.phone)
            newlog.atype = '物流'
            newlog.ltype = 4
            newlog.note = '忘密'
            newlog.content = '外卖人员忘记密码'
            newlog.save()
            return HttpResponse(encodejson(1, body),
                                content_type="application/json")
        else:
            return HttpResponse(encodejson(7, body),
                                content_type="application/json")
    else:
        raise Http404
Beispiel #8
0
def changepasswd(req):
    if req.method == 'POST':
        body = {}
        reqdata = simplejson.loads(req.body)
        privatetoken = reqdata['private_token']
        passwd = reqdata['password']
        new_passwd = reqdata['new_password']
        currentuserset = Sender.objects.filter(private_token=privatetoken)
        if currentuserset.count() > 0:
            currentuser = currentuserset[0]
            lasttime = currentuser.active_time.replace(tzinfo=None)
            if not isactive(lasttime):
                return HttpResponse(encodejson(5, body),
                                    content_type="application/json")
            if currentuser.check_password(passwd):
                currentuser.password = hashlib.md5(new_passwd).hexdigest()
                currentuser.save()
                newlog = AccountLog()
                newlog.account = str(currentuser.phone)
                newlog.atype = '物流'
                newlog.ltype = 3
                newlog.note = '改密'
                newlog.content = '外卖人员更改密码'
                newlog.save()
                return HttpResponse(encodejson(1, body),
                                    content_type="application/json")
            else:
                return HttpResponse(encodejson(4, body),
                                    content_type="application/json")
        else:
            return HttpResponse(encodejson(7, body),
                                content_type="application/json")
    else:
        raise Http404
Beispiel #9
0
def login(req):
    body = {}
    if req.method == 'POST':
        reqdata = simplejson.loads(req.body)
        username = reqdata['username']
        passwd = reqdata['password']
        sender_list = Sender.objects.filter(phone=str(username))
        if sender_list.count() > 0:
            sender = sender_list[0]
            if sender.check_password(passwd):
                mytoken = createtoken()
                sender.private_token = mytoken
                sender.active_time = datetime.datetime.now()
                sender.save()
                body["private_token"] = mytoken
                body['nick'] = str(sender.nick)
                newlog = AccountLog()
                newlog.account = str(username)
                newlog.atype = '物流'
                newlog.ltype = 1
                newlog.note = '登陆'
                newlog.content = '外卖人员登陆'
                newlog.save()
                return HttpResponse(encodejson(1, body),
                                    content_type="application/json")
            else:
                return HttpResponse(encodejson(4, body),
                                    content_type="application/json")
        else:
            return HttpResponse(encodejson(7, body),
                                content_type="application/json")
    else:
        raise Http404
Beispiel #10
0
def login_out(request):
    user_name = request.session.get('username')
    merchant = Merchant.objects.get(alin_account=user_name)
    merchant.is_online = False
    merchant.save()
    newlog = AccountLog()
    newlog.atype = '商家'
    newlog.content = '商家登出'
    newlog.ltype = 12
    newlog.note = '登出'
    newlog.account = str(user_name)
    newlog.save()
    del request.session['username']
    return HttpResponseRedirect("login_in")
Beispiel #11
0
def register(request):
    if request.method == 'POST':
        password = request.POST.get('password')
        merchant_name = request.POST.get('merchant_name')
        phone = request.POST.get('phone')
        verify = request.POST.get('verify')
        if password and merchant_name and phone and verify and len(phone) == 11:
            user_test_list = Merchant.objects.filter(alin_account=phone)
            if user_test_list.count() > 0:
                return render_to_response('register.html', {'phone': phone, 'merchant_name': merchant_name,
                                                            'fault2': 'T'}, context_instance=RequestContext(request))
            phone_verify = PhoneVerify.objects.filter(phone=str(phone), verify_code=str(verify))
            if phone_verify.count() > 0:
                update_time = phone_verify[0].update_time
                if (update_time.replace(tzinfo=None) + datetime.timedelta(minutes=30)) < \
                        datetime.datetime.utcnow():
                    return render_to_response('register.html', {'phone': phone, 'merchant_name': merchant_name,
                                                                'fault1': 'T'}, context_instance=RequestContext(request))
                else:
                    newmerchant = Merchant()
                    newmerchant.alin_account = phone
                    password = hashlib.md5(password).hexdigest()
                    newmerchant.password = password
                    newmerchant.name = merchant_name
                    newmerchant.belongs = get_phone_belong(phone)
                    newmerchant.save()
                    request.session['username'] = phone
                    qr_bind = createqr(2, newmerchant.id)
                    request.session['qr_bind'] = qr_bind
                    phone_verify.delete()
                    newlog = AccountLog()
                    newlog.atype = '商家'
                    newlog.content = '商家注册'
                    newlog.ltype = 14
                    newlog.note = '注册'
                    newlog.account = str(phone)
                    newlog.save()
                    return render_to_response('login_page.html', {'flag': 2}, context_instance=RequestContext(request))
            else:
                return render_to_response('register.html', {'phone': phone, 'merchant_name': merchant_name,
                                                            'fault3': 'T'}, context_instance=RequestContext(request))
        else:
            return render_to_response('register.html', context_instance=RequestContext(request))
    else:
        return render_to_response('register.html', context_instance=RequestContext(request))
Beispiel #12
0
def register(req):
    body = {}
    if req.method == 'POST':
        reqdata = simplejson.loads(req.body)
        username = reqdata['username']
        nick = reqdata['nick']
        passwd = reqdata['password']
        code = reqdata['reg_code']
        ishave = Sender.objects.filter(phone=str(username))
        if ishave.count() == 0:
            is_send_list = PhoneVerify.objects.filter(phone=str(username))
            if is_send_list.count() == 0:
                return HttpResponse(encodejson(11, body),
                                    content_type="application/json")
            is_send = is_send_list[0]
            if str(is_send.verify_code) == str(code):
                mytoken = createtoken()
                newsender = Sender()
                newsender.phone = username
                newsender.password = hashlib.md5(passwd).hexdigest()
                newsender.active_time = datetime.datetime.now()
                newsender.nick = nick
                newsender.belongs = get_phone_belong(username)
                newsender.private_token = mytoken
                newsender.save()
                body["private_token"] = mytoken
                is_send.delete()
                newlog = AccountLog()
                newlog.account = str(username)
                newlog.atype = '物流'
                newlog.ltype = 2
                newlog.note = '注册'
                newlog.content = '外卖人员注册'
                newlog.save()
                return HttpResponse(encodejson(1, body),
                                    content_type="application/json")
            else:
                return HttpResponse(encodejson(12, body),
                                    content_type="application/json")
        else:
            return HttpResponse(encodejson(6, body),
                                content_type="application/json")
    else:
        raise Http404
Beispiel #13
0
def register(req):
    body = {}
    if req.method == 'POST':
        reqdata = simplejson.loads(req.body)
        username = reqdata['username']
        nick = reqdata['nick']
        passwd = reqdata['password']
        code = reqdata['reg_code']
        ishave = Sender.objects.filter(phone = str(username))
        if ishave.count() == 0:
            is_send_list = PhoneVerify.objects.filter(phone = str(username))
            if is_send_list.count() == 0:
                return HttpResponse(encodejson(11, body), content_type="application/json")
            is_send = is_send_list[0]
            if str(is_send.verify_code) == str(code):
                mytoken = createtoken()
                newsender = Sender()
                newsender.phone = username
                newsender.password = hashlib.md5(passwd).hexdigest()
                newsender.active_time = datetime.datetime.now()
                newsender.nick = nick
                newsender.belongs = get_phone_belong(username)
                newsender.private_token = mytoken
                newsender.save()
                body["private_token"] = mytoken
                is_send.delete()
                newlog = AccountLog()
                newlog.account = str(username)
                newlog.atype = '物流'
                newlog.ltype = 2
                newlog.note = '注册'
                newlog.content = '外卖人员注册'
                newlog.save()
                return HttpResponse(encodejson(1, body), content_type="application/json")
            else:
                return HttpResponse(encodejson(12, body), content_type="application/json")
        else:
            return HttpResponse(encodejson(6, body), content_type="application/json")
    else:
        raise Http404
Beispiel #14
0
def forget_password_verify(request):
    if request.method == 'POST':
        context = {}
        context.update(csrf(request))
        phone = request.POST.get('phone')
        merchant_have = Merchant.objects.filter(alin_account=phone)
        if merchant_have.count() > 0 :
            merchant = merchant_have[0]
            if merchant.verify is False:
                return HttpResponse(json.dumps("auth"), content_type='application/json')
            req = createverifycode(phone)
            print req
            newlog = AccountLog()
            newlog.atype = '商家'
            newlog.content = '商家忘记密码'
            newlog.ltype = 13
            newlog.note = '忘密'
            newlog.account = str(phone)
            newlog.save()
            return HttpResponse(json.dumps("OK"), content_type="application/json")
        else:
            return HttpResponse(json.dumps("False"), content_type="application/json")
    return HttpResponse(json.dumps("False"), content_type="application/json")