public static function update($request, $match)
    {
        // Check access
        if(isset($match['userId'])){
            $user = Pluf_Shortcuts_GetObjectOr404('User_Account', $match['userId']);
        }else{
            $user = $request->user;
        }
        $profile = null;
        if (array_key_exists('profileId', $match)) {
            $profile = Pluf_Shortcuts_GetObjectOr404('User_Profile', $match['profileId']);
            if($profile->account_id !== $user->id){
                throw new Pluf_HTTP_Error404('You are not allowed to change this profile.');
            }
            $form = Pluf_Shortcuts_GetFormForUpdateModel($profile, $request->REQUEST, array());
            $profile = $form->save();
        }else{
            $profile = self::getProfileOfUser($user);
            if ($profile === null) {
                $profile = new User_Profile();
                $profile->account_id = $user;
                $form = Pluf_Shortcuts_GetFormForModel($profile, $request->REQUEST, array());
                $profile = $form->save();
            } else {
                $form = Pluf_Shortcuts_GetFormForUpdateModel($profile, $request->REQUEST, array());
                $profile = $form->save();
            }
        }
        return $profile;
    }