Exemplo n.º 1
0
def emailconfirm(request, bwuid):
    h = None
    if 'h' in request.GET:
        h = request.GET['h']
    else:
        return debug_or_404(
            request,
            message=
            "The proper parameters were not found.  Expecting 'h' parameter")
    manager = EmailChangeManager()
    if manager.token_exists(h, bwuid).issuccess():
        if request.user.is_authenticated():
            #then we can assume the user is legit
            new_email = manager.finalize_change(request.user.beatwrituser)

            bwuser = request.user.beatwrituser
            if 'settings' in request.GET:
                settings = request.GET['settings']
                emailform, passform, optionsform = default_settings_forms(
                    bwuser)
                emsg = "Email successfully changed"
                return render_to_response(
                    'settings.html', {
                        'optionsform': optionsform,
                        'emailform': emailform,
                        'passform': passform,
                        'email_success_msg': emsg
                    },
                    context_instance=RequestContext(request))
            else:
                pdb.set_trace()
                header = "Email was successfully set to %s" % new_email
                msg = "<p>You can change you the settings for receiving email by visiting the <a href='/%s/settings'>accounts settings</a> page.</p><p>Would you like to visit your <a href='%s'>beatwrits page</a>, or perhaps <a href='/joinbrowse'>browse the joinable writs</a>?</p>" % (
                    bwuser.id, bwuser.get_absolute_url())
                return message(request, message=msg, header=header)

        else:
            #ask the user to give password first to confirm that this person is truly the user.
            #ie. take the user to another page where they enter their pass and POST back to the same page.
            return message(request, message="Need to enter pass")
    return oops(request)