<s> from django . http import HttpResponseRedirect <EOL> from django . shortcuts import render_to_response <EOL> from django . template import RequestContext <EOL> from django . contrib import auth <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . auth . models import User <EOL> from oauth2app . models import Client , AccessRange <EOL> from . forms import SignupForm , LoginForm , CreateClientForm , ClientRemoveForm <EOL> @ login_required <EOL> def clients ( request ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = CreateClientForm ( request . POST ) <EOL> remove_form = ClientRemoveForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> Client . objects . create ( <EOL> name = form . cleaned_data [ "<STR_LIT:name>" ] , <EOL> user = request . user ) <EOL> elif remove_form . is_valid ( ) : <EOL> Client . objects . filter ( <EOL> id = remove_form . cleaned_data [ "<STR_LIT>" ] ) . delete ( ) <EOL> form = CreateClientForm ( ) <EOL> else : <EOL> form = CreateClientForm ( ) <EOL> template = { <EOL> "<STR_LIT>" : form , <EOL> "<STR_LIT>" : Client . objects . filter ( user = request . user ) } <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> template , <EOL> RequestContext ( request ) ) <EOL> def login ( request ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = LoginForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> user = auth . authenticate ( <EOL> username = form . cleaned_data [ "<STR_LIT:username>" ] , <EOL> password = form . cleaned_data [ "<STR_LIT:password>" ] ) <EOL> auth . login ( request , user ) <EOL> return HttpResponseRedirect ( "<STR_LIT:/>" ) <EOL> else : <EOL> form = LoginForm ( ) <EOL> template = { "<STR_LIT>" : form } <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> template , <EOL> RequestContext ( request ) ) <EOL> @ login_required <EOL> def logout ( request ) : <EOL> auth . logout ( request ) <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> { } , <EOL> RequestContext ( request ) ) <EOL> def signup ( request ) : <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = SignupForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> user = User . objects . create_user ( <EOL> form . cleaned_data [ "<STR_LIT:username>" ] , <EOL> form . cleaned_data [ "<STR_LIT:email>" ] , <EOL> form . cleaned_data [ "<STR_LIT>" ] , ) <EOL> user = auth . authenticate ( <EOL> username = form . cleaned_data [ "<STR_LIT:username>" ] , <EOL> password = form . cleaned_data [ "<STR_LIT>" ] ) <EOL> auth . login ( request , user ) <EOL> return HttpResponseRedirect ( "<STR_LIT:/>" ) <EOL> else : <EOL> form = SignupForm ( ) <EOL> template = { "<STR_LIT>" : form } <EOL> return render_to_response ( <EOL> '<STR_LIT>' , <EOL> template , <EOL> RequestContext ( request ) ) </s>
