Beispiel #1
0
def updateEmail():
    data = json.loads(request.data)
    newEmail = data["email"]
    password = data["password"]

    if not UserModel.checkPassword(getCurrentUid(), password):
        return json.dumps({
            "result": "fail",
            "msg": "Password is not correct!"
        })

    if not isValidEmail(newEmail):
        return json.dumps({
            "result": "fail",
            "msg": "Please enter a valid email!"
        })

    if getCurrentUser()["email"] == newEmail:
        return json.dumps({
            "result": "fail",
            "msg": "This is your current email!"
        })

    UserModel.updateEmail(getCurrentUid(), newEmail)
    return json.dumps({
        "result":
        "success",
        "msg":
        "Email updated! You should activate your new email clicking the activation link we've sent you."
    })
Beispiel #2
0
def updatePassword():
    data = json.loads(request.data)

    currentPassword = data["currentPassword"]
    newPassword = data["newPassword"]
    confirmNewPassword = data["confirmNewPassword"]

    if not UserModel.checkPassword(getCurrentUid(), currentPassword):
        return json.dumps({
            "result": "fail",
            "msg": "Current password is not correct!"
        })

    if newPassword != confirmNewPassword:
        return json.dumps({"result": "fail", "msg": "Passwords don't match!"})

    if not isValidPassword(newPassword):
        return json.dumps({
            "result":
            "fail",
            "msg":
            "Password is not valid! It must be at least 6 characters."
        })

    UserModel.updatePassword(getCurrentUid(), newPassword)
    return json.dumps({
        "result": "success",
        "msg": "Password has updated successfully!"
    })
Beispiel #3
0
def updateUsername():
    data = json.loads(request.data)
    newUsername = data["username"]
    password = data["password"]

    if not UserModel.checkPassword(getCurrentUid(), password):
        return json.dumps({
            "result": "fail",
            "msg": "Password is not correct!"
        })

    if not isValidUsername(newUsername):
        return json.dumps({
            "result":
            "fail",
            "msg":
            "Username is not valid! It should be at least 1 character alpha-numeric and can contain '-', '_'"
        })

    if newUsername != None and newUsername != "":
        UserModel.updateUsername(getCurrentUid(), newUsername)
        return json.dumps({
            "result": "success",
            "msg": "Username successfully updated!"
        })
    else:
        return json.dumps({
            "result": "fail",
            "msg": "You have to enter username to update it."
        })