]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/profilesettings.php
fix check for POST
[quix0rs-gnu-social.git] / actions / profilesettings.php
1 <?php
2 /* 
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  * 
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  * 
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class ProfilesettingsAction extends SettingsAction {
23         
24         function show_form($msg=NULL, $success=false) {
25                 common_show_header(_t('Profile settings'));
26                 $this->settings_menu();
27                 $this->message($msg, $success);
28                 common_element_start('form', array('method' => 'POST',
29                                                                                    'id' => 'profilesettings',
30                                                                                    'action' => 
31                                                                                    common_local_url('profilesettings')));
32                 common_input('nickname', _t('Nickname'));
33                 common_input('fullname', _t('Full name'));
34                 common_input('email', _t('Email address'));             
35                 common_input('homepage', _t('Homepage'));                               
36                 common_input('bio', _t('Bio'));
37                 common_input('location', _t('Location'));
38                 common_element('input', array('name' => 'submit',
39                                                                           'type' => 'submit',
40                                                                           'id' => 'submit'),
41                                            _t('Login'));
42                 common_element('input', array('name' => 'cancel',
43                                                                           'type' => 'button',
44                                                                           'id' => 'cancel'),
45                                            _t('Cancel'));
46                 common_element_end('form');
47                 common_show_footer();
48         }
49         
50         function handle_post() {
51                 $nickname = $this->arg('nickname');
52                 $fullname = $this->arg('fullname');
53                 $email = $this->arg('email');
54                 $homepage = $this->arg('homepage');
55                 $bio = $this->arg('bio');
56                 $location = $this->arg('location');
57
58                 $user = common_current_user();
59                 assert(!is_null($user)); # should already be checked
60                 
61                 # FIXME: scrub input
62                 # FIXME: transaction!
63                 
64                 $user->nickname = $this->arg('nickname');
65                 $user->email = $this->arg('email');
66                 
67                 if (!$user->update()) {
68                         common_server_error(_t('Couldnt update user.'));
69                         return;
70                 }
71
72                 $profile = $user->getProfile();
73
74                 $profile->nickname = $user->nickname;
75                 $profile->fullname = $this->arg('fullname');
76                 $profile->homepage = $this->arg('homepage');
77                 $profile->bio = $this->arg('bio');
78                 $profile->location = $this->arg('location');
79
80                 if (!$profile->update()) {
81                         common_server_error(_t('Couldnt save profile.'));
82                         return;
83                 }
84                 
85                 $this->show_form(_t('Settings saved.'), TRUE);
86         }
87 }