def create(request): if request.POST and "username" in request.POST: username = request.POST["username"] if username in reserved: return redirect(index) sleeper, created = Sleeper.objects.get_or_create(username=username) if created: sleeper.hours = 0 sleeper.save() return redirect(show, username=username) return index(request)
def signup(request, signup_form=SignupForm, template_name='registration/signup_form.html', success_url=None, extra_context=None): if settings.BAPH_AUTH_WITHOUT_USERNAMES and (signup_form == SignupForm): signup_form = SignupFormOnlyEmail if request.method == 'POST': form = signup_form(request.POST, request.FILES) if form.is_valid(): user = form.save() if success_url: redirect_to = success_url else: redirect_to = reverse('baph_signup_complete') # A new signed user should logout the old one. if request.user.is_authenticated(): logout(request) if (settings.BAPH_SIGNIN_AFTER_SIGNUP and not settings.BAPH_ACTIVATION_REQUIRED): user = authenticate(identification=user.email, check_password=False) login(request, user) return redirect(redirect_to) else: form = signup_form() if not extra_context: extra_context = dict() extra_context['form'] = form return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def sign_out(request, redirect_field_name=REDIRECT_FIELD_NAME): """ Handle 'sign out' action and redirect to proper page if needed. """ logout(request) next = request.GET.get(redirect_field_name) or \ resolve_url('website-index') return redirect(next)
def archive(request, week_num): try: archive = Archive.objects.get(edition=week_num) return render(request, "archive.html", locals()) except Archive.DoesNotExist: pass return redirect("index")
def archive(request, week_num): try: archive = Archive.objects.get(edition=week_num) return render(request, "archive.html", locals()) except Archive.DoesNotExist: pass return redirect('index')
def activate_retry(request, activation_key, template_name='registration/activate_retry_success.html', extra_context=None): """ Reissue a new ``activation_key`` for the user with the expired ``activation_key``. If ``activation_key`` does not exists, or ``BAPH_ACTIVATION_RETRY`` is set to False and for any other error condition user is redirected to :func:`activate` for error message display. :param activation_key: String of a SHA1 string of 40 characters long. A SHA1 is always 160bit long, with 4 bits per character this makes it --160/4-- 40 characters long. :param template_name: String containing the template name that is used when new ``activation_key`` has been created. Defaults to ``userena/activate_retry_success.html``. :param extra_context: Dictionary containing variables which could be added to the template context. Default to an empty dictionary. """ if not settings.BAPH_ACTIVATION_RETRY: return redirect(reverse('baph_activate', args=(activation_key, ))) try: if SignupManager.check_expired_activation(activation_key): new_key = SignupManager.reissue_activation(activation_key) if new_key: if not extra_context: extra_context = dict() return render_to_response( template_name, extra_context, context_instance=RequestContext(request)) else: return redirect( reverse('baph_activate', args=(activation_key, ))) else: return redirect(reverse('baph_activate', args=(activation_key, ))) except NoResultFound: return redirect(reverse('baph_activate', args=(activation_key, )))
def getscore(request): try: if 'fbid' in request.GET: fb = FacebookProfile.objects.get(facebook_id=request.GET['fbid']) results = json.dumps({'fbid' : fb.get_facebook_profile()['id'], 'highscore' : fb.highscore, 'currentscore' : fb.currentscore }, ensure_ascii=False) return HttpResponse(results, mimetype='application/json') except FacebookProfile.DoesNotExist: pass return redirect('home')
def form_detail(request, slug, template="forms/form_detail.html"): """ Display a built form and handle submission. """ published = Form.objects.published(for_user=request.user) if USE_SITES: published = published.filter(sites=Site.objects.get_current()) form = get_object_or_404(published, slug=slug) if form.login_required and not request.user.is_authenticated(): return redirect("%s?%s=%s" % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path()))) args = (form, request.POST or None, request.FILES or None) form_for_form = FormForForm(*args) if request.method == "POST": if not form_for_form.is_valid(): form_invalid.send(sender=request, form=form_for_form) else: entry = form_for_form.save() fields = ["%s: %s" % (v.label, form_for_form.cleaned_data[k]) for (k, v) in form_for_form.fields.items()] subject = form.email_subject if not subject: subject = "%s - %s" % (form.title, entry.entry_time) body = "\n".join(fields) if form.email_message: body = "%s\n\n%s" % (form.email_message, body) email_from = form.email_from or settings.DEFAULT_FROM_EMAIL email_to = form_for_form.email_to() if email_to and form.send_email: msg = EmailMessage(subject, body, email_from, [email_to]) msg.send() email_from = email_to or email_from # Send from the email entered. email_copies = [e.strip() for e in form.email_copies.split(",") if e.strip()] if email_copies: msg = EmailMessage(subject, body, email_from, email_copies) for f in form_for_form.files.values(): f.seek(0) msg.attach(f.name, f.read()) msg.send() form_valid.send(sender=request, form=form_for_form, entry=entry) return redirect(reverse("form_sent", kwargs={"slug": form.slug})) context = {"form": form, "form_for_form": form_for_form, "page": get_page(form, request)} return render_to_response(template, context, RequestContext(request))
def dummydata(request): fb = request.user.get_profile() drives = Drive.objects.all() if len(drives) > 101: r = random.randint(0, len(drives)-100) drives = drives[r:r+100] for d in drives: d.fb.add(fb) d.save() return redirect('/dashboard')
def challenge(request): if request.POST: fb = request.user.get_profile() challengee = FacebookProfile.objects.get(facebook_id=request.POST['challengee']) bet = request.POST['bet'] c = Challenge(challenger=fb, challengee=challengee, bet=bet, complete=0) c.save() fb.coins = fb.coins - int(bet) fb.save() return redirect('/dashboard')
def activate_retry(request, activation_key, template_name='registration/activate_retry_success.html', extra_context=None): """ Reissue a new ``activation_key`` for the user with the expired ``activation_key``. If ``activation_key`` does not exists, or ``BAPH_ACTIVATION_RETRY`` is set to False and for any other error condition user is redirected to :func:`activate` for error message display. :param activation_key: String of a SHA1 string of 40 characters long. A SHA1 is always 160bit long, with 4 bits per character this makes it --160/4-- 40 characters long. :param template_name: String containing the template name that is used when new ``activation_key`` has been created. Defaults to ``userena/activate_retry_success.html``. :param extra_context: Dictionary containing variables which could be added to the template context. Default to an empty dictionary. """ if not settings.BAPH_ACTIVATION_RETRY: return redirect(reverse('baph_activate', args=(activation_key,))) try: if SignupManager.check_expired_activation(activation_key): new_key = SignupManager.reissue_activation(activation_key) if new_key: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request)) else: return redirect(reverse('baph_activate', args=(activation_key,))) else: return redirect(reverse('baph_activate', args=(activation_key,))) except NoResultFound: return redirect(reverse('baph_activate', args=(activation_key,)))
def facebook_login(request): if hasattr(request, 'orm'): session = request.orm.sessionmaker() else: from baph.db.orm import ORM session = ORM.get().sessionmaker() params = get_user_from_cookie(request.COOKIES, settings.FACEBOOK_APP_ID, settings.FACEBOOK_SECRET_KEY) if params: user = authenticate(uid=params['uid'], session=session) if user is not None: if user.is_active: login(request, user) return redirect(settings.LOGIN_REDIRECT_URL, {}, ()) else: # Disabled account, redirect and notify? return redirect('/', {}, ()) else: # Invalid user, redirect and notify? return redirect('/', {}, ()) elif request.user.is_authenticated(): return redirect(settings.LOGIN_REDIRECT_URL, {}, ()) else: return redirect('/account/register/', {}, ())
def email_confirm(request, confirmation_key, template_name='registration/email_confirm_fail.html', success_url=None, extra_context=None): """ Confirms an email address with a confirmation key. Confirms a new email address by running :func:`User.objects.confirm_email` method. If the method returns an :class:`User` the user will have his new e-mail address set and redirected to ``success_url``. If no ``User`` is returned the user will be represented with a fail message from ``template_name``. :param confirmation_key: String with a SHA1 representing the confirmation key used to verify a new email address. :param template_name: String containing the template name which should be rendered when confirmation fails. When confirmation is successful, no template is needed because the user will be redirected to ``success_url``. :param success_url: String containing the URL which is redirected to after a successful confirmation. Supplied argument must be able to be rendered by ``reverse`` function. :param extra_context: Dictionary of variables that are passed on to the template supplied by ``template_name``. """ user = SignupManager.confirm_email(confirmation_key) if user: messages.success(request, _('Your email address has been changed.'), fail_silently=True) if success_url: redirect_to = success_url else: redirect_to = reverse('baph_email_confirm_complete') return redirect(redirect_to) else: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def scores(request): try: if 'fbid' in request.GET: fb = FacebookProfile.objects.get(facebook_id=request.GET['fbid']) fbid = fb.get_facebook_profile()['id'] first_name = fb.get_facebook_profile()['name'].split()[0] highscore = fb.highscore #friends = [{ 'fbid' : user.get_facebook_profile()['id'], 'first_name' : user.get_facebook_profile()['name'].split()[0], 'highscore' : user.highscore } for user in FacebookProfile.objects.all() if user != fb] # friends = [1, 2, 3] friends = [{ 'fbid' : user.get_facebook_profile()['id'], 'first_name' : user.get_facebook_profile()['name'].split()[0], 'highscore' : user.highscore } for user in FacebookProfile.objects.all()] results = json.dumps({'friends' : friends }, ensure_ascii=False) #results = json.dumps({ 'fbid' : fbid, 'first_name' : first_name, 'highscore' : highscore, 'friends' : friends }, ensure_ascii=False) return HttpResponse(results, mimetype='application/json') except FacebookProfile.DoesNotExist: pass return redirect('home')
def complete_registration(request): if request.method == 'POST': return register(request, BACKEND) form = None if 'denied' in request.GET: template_name = 'twitter/auth/denied.html' elif 'oauth_token' in request.GET and 'oauth_verifier' in request.GET: form = TwitterRegistrationForm(initial={ 'oauth_token': request.GET['oauth_token'], 'oauth_verifier': request.GET['oauth_verifier'], }) template_name = 'twitter/auth/complete.html' else: return redirect('/', (), {}) return render_to_response(template_name, { 'form': form, }, context_instance=RequestContext(request))
def email(request): try: email = EmailAddress.objects.get(user=request.user) except EmailAddress.DoesNotExist: email = None if request.method == 'POST': form = EmailForm(request.user, request.POST) if form.is_valid(): form.save() return redirect('account_email') else: form = EmailForm(request.user) return render(request, 'account/email.html', {'email': email, 'form': form})
def activate(request, activation_key, template_name='registration/activate_fail.html', retry_template_name='registration/activate_retry.html', success_url=django_settings.LOGIN_REDIRECT_URL, extra_context=None): session = orm.sessionmaker() signup = session.query(UserRegistration) \ .filter_by(activation_key=activation_key) \ .first() if not signup: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request)) if (not signup.activation_key_expired() or not settings.BAPH_ACTIVATION_RETRY): user = SignupManager.activate_user(activation_key) if user: auth_user = authenticate(identification=user.email, check_password=False) login(request, auth_user) messages.success(request, _('Your account has been activated and ' 'you have been signed in.'), fail_silently=True) if success_url: redirect_to = success_url % {'username': user.username} else: redirect_to = reverse('userena_profile_detail', kwargs={'username': user.username}) #TODO this is broken return redirect(redirect_to) else: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request)) else: if not extra_context: extra_context = dict() extra_context['activation_key'] = activation_key return render_to_response(retry_template_name, extra_context, context_instance=RequestContext(request))
def password_reset(request, uidb64, token, form_class=SetPasswordForm, template_name='auth_custom/pages/password-reset.html', token_generator=default_token_generator): """ View that checks the hash in a password reset link and presents a form for entering a new password. """ assert uidb64 is not None and token is not None # checked by URLconf try: uid = urlsafe_base64_decode(uidb64) user = User.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, User.DoesNotExist): user = None valid_link = user is not None and token_generator.check_token(user, token) if valid_link: if request.method == 'POST': form = form_class(user, request.POST) if form.is_valid(): form.save() is_anonymous = request.user.is_anonymous() message = _("Your password was successfully updated.") if is_anonymous: message = message + " " + \ _("You can use it to sign in right now!") messages.success(request, message) next_name = 'auth-custom-sign-in' if is_anonymous else \ 'website-index' return redirect(resolve_url(next_name)) else: form = form_class(None) else: form = None context = { 'form': form, 'valid_link': valid_link, } return render(request, template_name, context)
def apply(request): if request.is_ajax() and request.method == "POST": application = ApplyForm(request.POST) if application.is_valid(): cd = application.cleaned_data app = Application(name=cd['name'], email=cd['email'], major=cd['major'], attendance=cd['attendance'], interest=cd['interest'], background=cd['background'], comments=cd['comments']) app.save() appreview = ApplicationReview(application=app) appreview.save() results = json.dumps({'status': 'success'}, ensure_ascii=False) return HttpResponse(results, mimetype='application/json') return render(request, "application.html", locals()) return redirect('index')
def complete_login(request): redirect_path = '/' if 'oauth_token' in request.GET and 'oauth_verifier' in request.GET: token = request.GET['oauth_token'] verifier = request.GET['oauth_verifier'] request_token = request.session.pop(SESSION_KEY, None) if request_token and request_token.key == token: twitter = Twitter(request_token) access_token = twitter.get_access_token(verifier) if access_token: if hasattr(request, 'orm'): session = request.orm.sessionmaker() else: session = None user = authenticate(oauth_token=access_token.key, uid=twitter.user.id, session=session) auth_login(request, user) redirect_path = settings.LOGIN_REDIRECT_URL return redirect(redirect_path, (), {})
def complete_registration(request): if request.method == 'POST': return register(request, BACKEND) form = None if 'denied' in request.GET: template_name = 'twitter/auth/denied.html' elif 'oauth_token' in request.GET and 'oauth_verifier' in request.GET: form = TwitterRegistrationForm( initial={ 'oauth_token': request.GET['oauth_token'], 'oauth_verifier': request.GET['oauth_verifier'], }) template_name = 'twitter/auth/complete.html' else: return redirect('/', (), {}) return render_to_response(template_name, { 'form': form, }, context_instance=RequestContext(request))
def submit_review(request): if request.is_ajax() and request.method == "POST": app_id = int(request.POST['application']) editor = request.POST['editor'] decision = int(request.POST['decision']) comments = request.POST['comments'] review = ApplicationReview.objects.get(id=app_id) if editor == 'charlie': review.charlie_decision = decision review.charlie_comments = comments elif editor == 'kevin': review.kevin_decision = decision review.kevin_comments = comments elif editor == 'kingston': review.kingston_decision = decision review.kingston_comments = comments review.save() results = json.dumps({ 'decision' : decision, 'total' : review.total }, ensure_ascii=False) return HttpResponse(results, mimetype='application/json') return redirect('review')
def apply(request): if request.is_ajax() and request.method == "POST": application = ApplyForm(request.POST) if application.is_valid(): cd = application.cleaned_data app = Application( name=cd['name'], email=cd['email'], major=cd['major'], attendance=cd['attendance'], interest=cd['interest'], background=cd['background'], comments=cd['comments']) app.save() appreview = ApplicationReview(application=app) appreview.save() results = json.dumps({ 'status' : 'success' }, ensure_ascii=False) return HttpResponse(results, mimetype='application/json') return render(request, "application.html", locals()) return redirect('index')
def submit_review(request): if request.is_ajax() and request.method == "POST": app_id = int(request.POST['application']) editor = request.POST['editor'] decision = int(request.POST['decision']) comments = request.POST['comments'] review = ApplicationReview.objects.get(id=app_id) if editor == 'charlie': review.charlie_decision = decision review.charlie_comments = comments elif editor == 'kevin': review.kevin_decision = decision review.kevin_comments = comments elif editor == 'kingston': review.kingston_decision = decision review.kingston_comments = comments review.save() results = json.dumps({ 'decision': decision, 'total': review.total }, ensure_ascii=False) return HttpResponse(results, mimetype='application/json') return redirect('review')
def activate(request, activation_key, template_name='registration/activate_fail.html', retry_template_name='registration/activate_retry.html', success_url=django_settings.LOGIN_REDIRECT_URL, extra_context=None): session = orm.sessionmaker() signup = session.query(UserRegistration) \ .filter_by(activation_key=activation_key) \ .first() if not signup: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request)) if (not signup.activation_key_expired() or not settings.BAPH_ACTIVATION_RETRY): user = SignupManager.activate_user(activation_key) if user: auth_user = authenticate(identification=user.email, check_password=False) login(request, auth_user) messages.success(request, _('Your account has been activated and ' 'you have been signed in.'), fail_silently=True) if success_url: redirect_to = success_url % {'username': user.username } else: redirect_to = reverse('userena_profile_detail', kwargs={'username': user.username}) #TODO this is broken return redirect(redirect_to) else: if not extra_context: extra_context = dict() return render_to_response(template_name, extra_context, context_instance=RequestContext(request)) else: if not extra_context: extra_context = dict() extra_context['activation_key'] = activation_key return render_to_response(retry_template_name, extra_context, context_instance=RequestContext(request))
def admin_glossary(request): return redirect("admin-glossary-es")
def student(request, student_id): try: student = Student.objects.get(id=student_id) except Student.DoesNotExist: return redirect('students') return render(request, "student.html", locals())
def review(request): if not request.user.is_superuser: return redirect('index') apps = sorted(ApplicationReview.objects.all(), key=operator.attrgetter('application.created_at')) return render(request, "review.html", locals())
def signin(request, auth_form=AuthenticationForm, template_name='registration/signin_form.html', redirect_field_name=REDIRECT_FIELD_NAME, redirect_signin_function=signin_redirect, extra_context=None): """ Signin using email or username with password. Signs a user in by combining email/username with password. If the combination is correct and the user :func:`is_active` the :func:`redirect_signin_function` is called with the arguments ``REDIRECT_FIELD_NAME`` and an instance of the :class:`User` who is is trying the login. The returned value of the function will be the URL that is redirected to. A user can also select to be remembered for ``USERENA_REMEMBER_DAYS``. :param auth_form: Form to use for signing the user in. Defaults to the :class:`AuthenticationForm` supplied by userena. :param template_name: String defining the name of the template to use. Defaults to ``userena/signin_form.html``. :param redirect_field_name: Form field name which contains the value for a redirect to the succeeding page. Defaults to ``next`` and is set in ``REDIRECT_FIELD_NAME`` setting. :param redirect_signin_function: Function which handles the redirect. This functions gets the value of ``REDIRECT_FIELD_NAME`` and the :class:`User` who has logged in. It must return a string which specifies the URI to redirect to. :param extra_context: A dictionary containing extra variables that should be passed to the rendered template. The ``form`` key is always the ``auth_form``. **Context** ``form`` Form used for authentication supplied by ``auth_form``. """ form = auth_form() if request.method == 'POST': form = auth_form(request.POST, request.FILES) if form.is_valid(): identification, password, remember_me = (form.cleaned_data['identification'], form.cleaned_data['password'], form.cleaned_data['remember_me']) user = authenticate(identification=identification, password=password) if user.is_active: login(request, user) if remember_me: request.session.set_expiry(settings.BAPH_REMEMBER_ME_DAYS[1] * 86400) else: request.session.set_expiry(0) messages.success(request, _('You have been signed in.'), fail_silently=True) # Whereto now? redirect_to = redirect_signin_function( request.REQUEST.get(redirect_field_name), user) return HttpResponseRedirect(redirect_to) else: return redirect(reverse('baph_disabled')) if not extra_context: extra_context = dict() extra_context.update({ 'form': form, 'next': request.REQUEST.get(redirect_field_name), }) return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def email_change(request, email_form=ChangeEmailForm, template_name='registration/email_form.html', success_url=None, extra_context=None): """ Change email address :param username: String of the username which specifies the current account. :param email_form: Form that will be used to change the email address. Defaults to :class:`ChangeEmailForm` supplied by userena. :param template_name: String containing the template to be used to display the email form. Defaults to ``userena/email_form.html``. :param success_url: Named URL where the user will get redirected to when successfully changing their email address. When not supplied will redirect to ``userena_email_complete`` URL. :param extra_context: Dictionary containing extra variables that can be used to render the template. The ``form`` key is always the form supplied by the keyword argument ``form`` and the ``user`` key by the user whose email address is being changed. **Context** ``form`` Form that is used to change the email address supplied by ``form``. ``account`` Instance of the ``Account`` whose email address is about to be changed. **Todo** Need to have per-object permissions, which enables users with the correct permissions to alter the email address of others. """ user = request.user if not user.is_authenticated(): return HttpResponseForbidden() form = email_form(user) if request.method == 'POST': form = email_form(user, request.POST, request.FILES) if form.is_valid(): email_result = form.save() if success_url: redirect_to = success_url else: redirect_to = reverse('baph_email_change_complete') return redirect(redirect_to) if not extra_context: extra_context = dict() extra_context['form'] = form return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def password_change(request, template_name='registration/password_form.html', pass_form=PasswordChangeForm, success_url=None, extra_context=None): """ Change password of user. This view is almost a mirror of the view supplied in :func:`contrib.auth.views.password_change`, with the minor change that in this view we also use the username to change the password. This was needed to keep our URLs logical (and REST) across the entire application. And that in a later stadium administrators can also change the users password through the web application itself. :param username: String supplying the username of the user who's password is about to be changed. :param template_name: String of the name of the template that is used to display the password change form. Defaults to ``userena/password_form.html``. :param pass_form: Form used to change password. Default is the form supplied by Django itself named ``PasswordChangeForm``. :param success_url: Named URL that is passed onto a :func:`reverse` function with ``username`` of the active user. Defaults to the ``userena_password_complete`` URL. :param extra_context: Dictionary of extra variables that are passed on to the template. The ``form`` key is always used by the form supplied by ``pass_form``. **Context** ``form`` Form used to change the password. """ user = request.user form = pass_form(user=user) if request.method == "POST": form = pass_form(user=user, data=request.POST) if form.is_valid(): form.save() # Send a signal that the password has changed # TODO: implement signals #userena_signals.password_complete.send(sender=None, # user=user) if success_url: redirect_to = success_url else: redirect_to = reverse('baph_password_change_complete') return redirect(redirect_to) if not extra_context: extra_context = dict() extra_context['form'] = form return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def smartlogin(request, **kwargs): if request.user.is_authenticated() and "next" not in request.GET: return redirect("index") return login(request, **kwargs)
def admin(request): return redirect("admin-execution")
def show(request, username): try: sleeper = Sleeper.objects.get(username=username) return render(request, "show.html", locals()) except Sleeper.DoesNotExist: return redirect(index)
def smartlogin(request, **kwargs): if request.user.is_authenticated(): return redirect('index') else: return login(request, **kwargs)
def signin(request, auth_form=AuthenticationForm, template_name='registration/signin_form.html', redirect_field_name=REDIRECT_FIELD_NAME, redirect_signin_function=signin_redirect, extra_context=None): """ Signin using email or username with password. Signs a user in by combining email/username with password. If the combination is correct and the user :func:`is_active` the :func:`redirect_signin_function` is called with the arguments ``REDIRECT_FIELD_NAME`` and an instance of the :class:`User` who is is trying the login. The returned value of the function will be the URL that is redirected to. A user can also select to be remembered for ``USERENA_REMEMBER_DAYS``. :param auth_form: Form to use for signing the user in. Defaults to the :class:`AuthenticationForm` supplied by userena. :param template_name: String defining the name of the template to use. Defaults to ``userena/signin_form.html``. :param redirect_field_name: Form field name which contains the value for a redirect to the succeeding page. Defaults to ``next`` and is set in ``REDIRECT_FIELD_NAME`` setting. :param redirect_signin_function: Function which handles the redirect. This functions gets the value of ``REDIRECT_FIELD_NAME`` and the :class:`User` who has logged in. It must return a string which specifies the URI to redirect to. :param extra_context: A dictionary containing extra variables that should be passed to the rendered template. The ``form`` key is always the ``auth_form``. **Context** ``form`` Form used for authentication supplied by ``auth_form``. """ form = auth_form() if request.method == 'POST': form = auth_form(request.POST, request.FILES) if form.is_valid(): identification, password, remember_me = ( form.cleaned_data['identification'], form.cleaned_data['password'], form.cleaned_data['remember_me']) user = authenticate(identification=identification, password=password) if user.is_active: login(request, user) if remember_me: request.session.set_expiry( settings.BAPH_REMEMBER_ME_DAYS[1] * 86400) else: request.session.set_expiry(0) messages.success(request, _('You have been signed in.'), fail_silently=True) # Whereto now? redirect_to = redirect_signin_function( request.REQUEST.get(redirect_field_name), user) return HttpResponseRedirect(redirect_to) else: return redirect(reverse('baph_disabled')) if not extra_context: extra_context = dict() extra_context.update({ 'form': form, 'next': request.REQUEST.get(redirect_field_name), }) return render_to_response(template_name, extra_context, context_instance=RequestContext(request))
def smartlogin(request, **kwargs): if request.user.is_authenticated() and 'next' not in request.GET: return redirect('index') return login(request, **kwargs)