示例#1
0
def userSave(id):
    try:
        user = User().getObjectsByKey("_id", id)[0]
    except Exception as e:
        return abort(404)

    data = dict(request.form)

    oldPassword = urllib2.unquote(
        data.get("old-password", [""])[0].decode("utf-8"))
    newPassword = urllib2.unquote(
        data.get("new-password", [""])[0].decode("utf-8"))
    newPasswordAgain = urllib2.unquote(
        data.get("new-password-again", [""])[0].decode("utf-8"))

    if len(newPassword) > 0:
        if not user.checkPassword(oldPassword):
            return redirect(
                request.args.get("back", "/users/%s/edit" % id) +
                "?error=password-incorrect")

        if newPassword != newPasswordAgain:
            return redirect(
                request.args.get("back", "/users/%s/edit" % id) +
                "?error=password-nomatch")

        if len(newPassword) < 8:
            return redirect(
                request.args.get("back", "/users/%s/edit" % id) +
                "?error=password-tooshort")

        if newPassword in User.getMostCommonPasswords():
            return redirect(
                request.args.get("back", "/users/%s/edit" % id) +
                "?error=password-toocommon")

        user.setPassword(newPassword)

    user.username = data["username"][0]
    user.firstname = data["firstname"][0]
    user.lastname = data["lastname"][0]
    user.email = data["email"][0]
    user.save()

    return redirect(
        request.args.get("back", "/users/%s/edit" % id) + "?success=true")
示例#2
0
def installYurasFinal():
    data = dict(request.form)

    user = User()

    username = unicode(data.get("name")[0].lower())
    password = unicode(data.get("password")[0].lower())
    email = unicode(data.get("email")[0].lower())

    user.setPassword(password)
    user.username = username
    user.email = email
    user.firstname = username

    user.save()

    return render_template("install/final.html",
                           name="You are done installing Yuras!")