Blame view
apps/homepage/views.py
1.93 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 |
f96567709 modify page |
15 |
from decrators import weapp_login_required, weapp_logout |
c51fd49af first add |
16 |
|
f96567709 modify page |
17 |
@weapp_login_required |
c51fd49af first add |
18 |
def homepage(request): |
f96567709 modify page |
19 20 21 |
c = csrf(request) username = request.COOKIES.get('username', '') return render_to_response('homepage/index.html', c, context_instance=RequestContext(request)) |
c51fd49af first add |
22 23 24 25 26 27 28 29 30 31 32 33 34 |
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 |
35 36 37 38 39 |
post_params = { 'comefrom': 2, 'user_name': username, 'password': password, } |
1a597f51f add login token |
40 |
resp = requests.post(settings.AUTH_DOMAIN, data=post_params, verify=False) |
e11f60ade m |
41 42 43 44 45 |
if resp.status_code == 200: rst = resp.json() if rst.get('status') == 1: data = rst.get('data') token = data.get('token') |
f96567709 modify page |
46 47 |
suid = data.get('suid') t = HttpResponseRedirect('/') |
1a597f51f add login token |
48 49 50 51 |
t.set_cookie('pu', token, 864000) t.set_cookie('pt', suid, 864000) t.set_cookie('username', username, 86400) return t |
f96567709 modify page |
52 53 |
t = HttpResponseRedirect('/') return t |
c51fd49af first add |
54 |
|
f96567709 modify page |
55 56 |
@weapp_login_required() @weapp_logout() |
c51fd49af first add |
57 |
def mylogout(request): |
f96567709 modify page |
58 |
|
c51fd49af first add |
59 |
return HttpResponseRedirect("/login/") |