def login(request): info = '' if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] if email == '*****@*****.**': if password == 'password': request.session['is_admin'] = True request.session['uid'] = '-1' request.session['user'] = '******' info = '登陆成功' else : info = '密码错误!' elif not Customer.contain_email(email): info = 'EMAIL不存在!' elif not Customer.is_auth(email, password): info = '密码错误!' else: customer = Customer.objects.get(email = email) request.session['is_admin'] = False request.session['uid'] = customer.customer_id request.session['user'] = email info = '登录成功' form = LoginForm() return render(request, 'login.html', {'form' : form, 'info' : info})
def login(request): if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] if not Customer.contain_email(email): return render(request, 'login.html', {'form' : form , 'non_exist_email' : True}) elif not Customer.is_auth(email, password): return render(request, 'login.html', {'form' : form , 'wrong_password' : True}) else: print "login successfully" form = LoginForm() return render(request, 'login.html', {'form' : form})
def login_api(request): info = '' status_code = -1 customer = None if request.method == "GET": form = request.GET email = form['email'] password = form['password'] if not Customer.contain_email(email): status_code = 1 elif not Customer.is_auth(email, password): status_code = 2 else: customer = Customer.objects.get(email = email) status_code = 0 return render(request, 'auth.json', {'status_code' : status_code, 'customer' : customer})