Blame view
apps/account/views.py
1.96 KB
831eac332 add file |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import json import logging 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 from service.account.account_service import AccountService my_user_model = get_user_model() 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('account/login.html', c) else: postdata = request.POST username = postdata.get('username','') password = postdata.get('password','') account_service = AccountService(my_user_model, request) next_url = account_service.get_login_next_url() if not (username and password): alert_msg = 1 c = csrf(request) c.update({'alert_msg':alert_msg}) return render_to_response('account/login.html', c, context_instance=RequestContext(request)) else: user = account_service.user_auth_local(username, password) if user is not None and user.is_active: auth.login(request,user) t = HttpResponseRedirect(next_url) t.set_cookie('username', username, 864000) return t else: alert_msg = 2 c = csrf(request) c.update({'alert_msg':alert_msg}) t= render_to_response('account/login.html',c,context_instance=RequestContext(request) ) t.set_cookie('username', username) return t def mylogout(request): logout(request) return HttpResponseRedirect("/account/login") |