コード例 #1
0
def password_req(request):
    mcid = normalize_mcid(request.REQUEST['mcid'])

    mcuser = get_object_or_404(User, mcid=mcid)

    decoded_skey = mcuser.enc_skey and mcuser.enc_skey.decode('base64')

    ts = datetime.fromtimestamp(mcuser.ccrlogupdatetime)

    skey_form = None

    if 'skey' in request.POST:
        skey_form = SKeyForm(request.POST)

        if skey_form.is_valid():
            curr = skey.get(skey_form.clean_data['skey'])
            next = skey.step(curr)

            if next == decoded_skey:
                mcuser.email = skey_form.clean_data['email']
                mcuser.set_password(skey_form.clean_data['newpw'])
                mcuser.enc_skey = curr.encode('base64').strip()

                mcuser.save()

                properties = get_properties()
                properties['user'] = mcuser
                properties['newpw'] = skey_form.clean_data['newpw']

                email_user_template(
                    request, mcuser,
                    'Your {{ ApplianceName }} email and password has been reset',
                    'email/new_email.txt', properties)

                return HttpResponseRedirect('user?mcid=' + mcid)

            skey_form.errors.setdefault('skey', []).append('S/Key mismatch')

        pw_form = PasswordForm(initial=dict(newpw=request.POST['newpw']))
    elif 'newpw' in request.POST:
        pw_form = PasswordForm(request.POST)

        if pw_form.is_valid():
            mcuser.set_password(pw_form.clean_data['newpw'])
            mcuser.save()

            properties = get_properties()
            properties['user'] = mcuser
            properties['newpw'] = pw_form.clean_data['newpw']

            email_user_template(
                request, mcuser,
                'Your {{ ApplianceName }} password has been reset',
                'email/new_password.txt', properties)

            return HttpResponseRedirect('user?mcid=' + mcid)

        if decoded_skey:
            skey_form = SKeyForm(
                initial=dict(email=mcuser.email, newpw=request.POST['newpw']))
    else:
        newpw = random_password()
        initial = dict(newpw=newpw, email=mcuser.email)
        pw_form = PasswordForm(initial=initial)

        if decoded_skey:
            skey_form = SKeyForm(initial=initial)

    return render_to_response(
        'users/password.html',
        default_context(request,
                        mcuser=mcuser,
                        ccrlogupdatetime=ts,
                        pw_form=pw_form,
                        skey_form=skey_form))
コード例 #2
0
ファイル: views.py プロジェクト: billdonner/medcommonsPhp
def password_req(request):
    mcid = normalize_mcid(request.REQUEST["mcid"])

    mcuser = get_object_or_404(User, mcid=mcid)

    decoded_skey = mcuser.enc_skey and mcuser.enc_skey.decode("base64")

    ts = datetime.fromtimestamp(mcuser.ccrlogupdatetime)

    skey_form = None

    if "skey" in request.POST:
        skey_form = SKeyForm(request.POST)

        if skey_form.is_valid():
            curr = skey.get(skey_form.clean_data["skey"])
            next = skey.step(curr)

            if next == decoded_skey:
                mcuser.email = skey_form.clean_data["email"]
                mcuser.set_password(skey_form.clean_data["newpw"])
                mcuser.enc_skey = curr.encode("base64").strip()

                mcuser.save()

                properties = get_properties()
                properties["user"] = mcuser
                properties["newpw"] = skey_form.clean_data["newpw"]

                email_user_template(
                    request,
                    mcuser,
                    "Your {{ ApplianceName }} email and password has been reset",
                    "email/new_email.txt",
                    properties,
                )

                return HttpResponseRedirect("user?mcid=" + mcid)

            skey_form.errors.setdefault("skey", []).append("S/Key mismatch")

        pw_form = PasswordForm(initial=dict(newpw=request.POST["newpw"]))
    elif "newpw" in request.POST:
        pw_form = PasswordForm(request.POST)

        if pw_form.is_valid():
            mcuser.set_password(pw_form.clean_data["newpw"])
            mcuser.save()

            properties = get_properties()
            properties["user"] = mcuser
            properties["newpw"] = pw_form.clean_data["newpw"]

            email_user_template(
                request,
                mcuser,
                "Your {{ ApplianceName }} password has been reset",
                "email/new_password.txt",
                properties,
            )

            return HttpResponseRedirect("user?mcid=" + mcid)

        if decoded_skey:
            skey_form = SKeyForm(initial=dict(email=mcuser.email, newpw=request.POST["newpw"]))
    else:
        newpw = random_password()
        initial = dict(newpw=newpw, email=mcuser.email)
        pw_form = PasswordForm(initial=initial)

        if decoded_skey:
            skey_form = SKeyForm(initial=initial)

    return render_to_response(
        "users/password.html",
        default_context(request, mcuser=mcuser, ccrlogupdatetime=ts, pw_form=pw_form, skey_form=skey_form),
    )
コード例 #3
0
 def clean_skey(self):
     s = self.data['skey']
     try:
         return skey.put(skey.get(s))
     except KeyError:
         raise forms.ValidationError('Invalid S/Key data')
コード例 #4
0
ファイル: views.py プロジェクト: billdonner/medcommonsPhp
 def clean_skey(self):
     s = self.data["skey"]
     try:
         return skey.put(skey.get(s))
     except KeyError:
         raise forms.ValidationError("Invalid S/Key data")