]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
call validate before saving objects
authorEvan Prodromou <evan@prodromou.name>
Tue, 20 May 2008 19:10:32 +0000 (15:10 -0400)
committerEvan Prodromou <evan@prodromou.name>
Tue, 20 May 2008 19:10:32 +0000 (15:10 -0400)
darcs-hash:20080520191032-84dde-64197121c93cd4cf3cbc614badff0bd44547f9f9.gz

actions/avatar.php
actions/newnotice.php
actions/password.php
actions/profilesettings.php
actions/register.php
actions/subscribe.php

index 17f56634b30d94037b83c060704a7749e9a7d6d9..43f02a88d593cfe42e87a17db1058d4d24b4f108 100644 (file)
@@ -128,6 +128,17 @@ class AvatarAction extends SettingsAction {
                $avatar->url = common_avatar_url($filename);
                $avatar->created = DB_DataObject_Cast::dateTime(); # current time
 
+               $val = $avatar->validate();
+               
+               if ($val !== TRUE) {
+                       $err = '';
+                       foreach ($val as $k=>$v) {
+                               $err .= _t('Something wrong with ') . $k;
+                               $this->show_form($err);
+                               return;
+                       }
+               }
+               
                foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
                        $scaled[] = $this->scale_avatar($user, $avatar, $size);
                }
@@ -139,7 +150,6 @@ class AvatarAction extends SettingsAction {
                        common_server_error(_t('Error deleting old avatars.'));
                        return;
                }
-
                if (!$avatar->insert()) {
                        @unlink($filepath);
                        common_server_error(_t('Error inserting avatar.'));
index fed3278a47f1b0b5489a253f3b27c5b47a78cd77..5bbc9153158d5cbff6b121ca7c3bacffb04f71f0 100644 (file)
@@ -49,7 +49,14 @@ class NewnoticeAction extends Action {
                $notice->profile_id = $user->id; # user id *is* profile id
                $notice->created = DB_DataObject_Cast::dateTime();
                $notice->content = trim($this->arg('content'));
-               return $notice->insert();
+               
+               $val = $notice->validate();
+               if ($val === TRUE) {
+                       return $notice->insert();
+               } else {
+                       // XXX: display some info
+                       return NULL;
+               }
        }
        
        function show_form() {
index 6eba136cebaaf60ca642e25a41bfc6c16e8fa026..3a89c99d333a5f90ffd9223b1bf394767c45a7bf 100644 (file)
@@ -64,6 +64,12 @@ class PasswordAction extends SettingsAction {
 
                $user->password = common_munge_password($newpassword, $user->id);
 
+               $val = $user->validate();
+               if ($val !== TRUE) {
+                       $this->show_form(_t('Error saving user; invalid.'));
+                       return;
+               }
+               
                if (!$user->update($original)) {
                        common_server_error(_t('Can\'t save new password.'));
                        return;
index ab8175901aa805c76689031376c91ee94ab1a85f..a0c9527a20e7b0392df0c2980c7d180a001c6266 100644 (file)
@@ -70,6 +70,13 @@ class ProfilesettingsAction extends SettingsAction {
                $user->nickname = $this->arg('nickname');
                $user->email = $this->arg('email');
 
+               $val = $user->validate();
+               if ($val !== TRUE) {
+                       # XXX: better validation
+                       $this->show_form(_t('Error saving user; invalid.'));
+                       return;
+               }
+               
                if (!$user->update($original)) {
                        common_server_error(_t('Couldnt update user.'));
                        return;
@@ -86,6 +93,13 @@ class ProfilesettingsAction extends SettingsAction {
                $profile->location = $this->arg('location');
                $profile->profileurl = common_profile_url($nickname);
 
+               $val = $profile->validate();
+               if ($val !== TRUE) {
+                       # XXX: some feedback here, please!
+                       $this->show_form(_t('Error saving profile; invalid.'));
+                       return;
+               }
+               
                if (!$profile->update($orig_profile)) {
                        common_server_error(_t('Couldnt save profile.'));
                        return;
index f9402b98f4f251dc60889d72b316d1afc68b51f4..2fa66338902a73baf9dd0f51beb3f70c7c63ecf9 100644 (file)
@@ -83,6 +83,12 @@ class RegisterAction extends Action {
                $profile->nickname = $nickname;
                $profile->profileurl = common_profile_url($nickname);
                $profile->created = DB_DataObject_Cast::dateTime(); # current time
+               
+               $val = $profile->validate();
+               if ($val !== TRUE) {
+                       # XXX: some feedback here, please!
+                       return FALSE;
+               }
                $id = $profile->insert();
                if (!$id) {
                        return FALSE;
@@ -93,6 +99,15 @@ class RegisterAction extends Action {
                $user->password = common_munge_password($password, $id);
                $user->email = $email;
                $user->created =  DB_DataObject_Cast::dateTime(); # current time
+               
+               $val = $user->validate();
+               if ($val !== TRUE) {
+                       # XXX: some feedback here, please!
+                       # Try to clean up...
+                       $profile->delete();
+                       return FALSE;
+               }
+               
                $result = $user->insert();
                if (!$result) {
                        # Try to clean up...
index 4edf3e714ea5207ac0111078d573a1379df74ed8..ea3038236c45303dab990a62166c7013ea42607a 100644 (file)
@@ -49,6 +49,14 @@ class SubscribeAction extends Action {
                $sub->subscribed = $other->id;
                
                $sub->created = DB_DataObject_Cast::dateTime(); # current time
+
+               $val = $sub->validate();
+               
+               if ($val !== TRUE) {
+                       # XXX: give some error notice
+                       common_server_error(_t('Subscription did not validate.'));
+                       return;
+               }
                
                if (!$sub->insert()) {
                        common_server_error(_t('Couldn\'t create subscription.'));