Blame view
homepage/views.py
1.84 KB
c51fd49af first add |
1 2 3 4 |
import json import logging |
1a597f51f add login token |
5 |
import requests |
c51fd49af first add |
6 7 8 9 10 11 12 13 |
from django.contrib import auth from django.contrib.auth import logout from django.contrib.auth.decorators import login_required from django.http import HttpResponseRedirect from django.contrib.auth import get_user_model from django.shortcuts import render_to_response from django.template import RequestContext from django.template.context_processors import csrf |
e11f60ade m |
14 |
from django.conf import settings |
c51fd49af first add |
15 16 17 18 19 |
@login_required def homepage(request): username = request.user.username |
1a597f51f add login token |
20 |
import pdb; pdb.set_trace() |
c51fd49af first add |
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
t = HttpResponseRedirect('/admin/') t.set_cookie('username', username, 864000) return t def mylogin(request): alert_msg= 0 if request.method =='GET': cookies_username = request.COOKIES.get('username','') c = csrf(request) c.update({'alert_msg':alert_msg,'cookies_username:':cookies_username}) return render_to_response('login.html', c) else: postdata = request.POST username = postdata.get('username','') password = postdata.get('password','') |
e11f60ade m |
37 38 39 40 41 |
post_params = { 'comefrom': 2, 'user_name': username, 'password': password, } |
1a597f51f add login token |
42 |
resp = requests.post(settings.AUTH_DOMAIN, data=post_params, verify=False) |
e11f60ade m |
43 44 45 46 47 48 49 |
if resp.status_code == 200: rst = resp.json() if rst.get('status') == 1: data = rst.get('data') token = data.get('token') suid = data.get('1000') t = HttpResponseRedirect('/admin/') |
1a597f51f add login token |
50 51 52 53 54 55 |
t.set_cookie('pu', token, 864000) t.set_cookie('pt', suid, 864000) t.set_cookie('username', username, 86400) return t t = HttpResponseRedirect('/login/') |
c51fd49af first add |
56 57 58 59 60 |
def mylogout(request): logout(request) return HttpResponseRedirect("/login/") |