root / nephthys_profile.php

View | Annotate | Download (6.6 KB)

1
<?php
2
3
/***************************************************************************
4
 *
5
 * Nephthys - file sharing management
6
 * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
7
 *
8
 *  This file is part of Nephthys.
9
 *
10
 *  Nephthys is free software: you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation, either version 3 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  Nephthys is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with Nephthys. If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 ***************************************************************************/
24
25
class NEPHTHYS_PROFILE {
26
27
   private $db;
28
   private $parent;
29
   private $tmpl;
30
31
   /**
32
    * NEPHTHYS_PROFILE constructor
33
    *
34
    * Initialize the NEPHTHYS_PROFILE class
35
    */
36
   public function __construct()
37
   {
38
      global $nephthys;
39
      $this->parent =& $nephthys;
40
      $this->db =& $nephthys->db;
41
      $this->tmpl =& $nephthys->tmpl;
42
43
   } // __construct()
44
  
45
   /* interface output */
46
   public function show()
47
   {
48
      if(!$this->parent->is_logged_in()) {
49
         $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##"));
50
         return 0;
51
      }
52
53
      if(!isset($_GET['mode'])) 
54
         $_GET['mode'] = "show";
55
56
      switch($_GET['mode']) {
57
         default:
58
         case 'edit':
59
            return $this->showEdit();
60
            break;
61
      }
62
63
   } // show()
64
65
   /**
66
    * display interface to edit profile settings
67
    */
68
   private function showEdit()
69
   {
70
      /* If authentication is enabled, check permissions */
71
      if(!$this->parent->is_logged_in()) {
72
         $this->parent->_error($this->parent->_("##MANAGE_USERS##") ." - ". $this->parent->_("##NOT_ALLOWED##"));
73
         return 0;
74
      }
75
76
      $user = $this->db->db_fetchSingleRow("
77
         SELECT *
78
         FROM nephthys_users
79
         WHERE
80
            user_idx='". $_SESSION['login_idx'] ."'
81
      ");
82
83
      $this->tmpl->assign('user_idx', $_SESSION['login_idx']);
84
      $this->tmpl->assign('user_name', $this->parent->unescape($user->user_name));
85
      $this->tmpl->assign('user_full_name', $this->parent->unescape($user->user_full_name));
86
      $this->tmpl->assign('user_email', $this->parent->unescape($user->user_email));
87
      $this->tmpl->assign('user_default_expire', $user->user_default_expire);
88
      $this->tmpl->assign('user_auto_created', $user->user_auto_created);
89
      $this->tmpl->assign('user_deny_chpwd', $user->user_deny_chpwd);
90
      $this->tmpl->assign('user_language', $user->user_language);
91
92
      return $this->tmpl->fetch("profile.tpl");
93
94
   } // showEdit()
95
     
96
   /** 
97
    * store user values
98
    */
99
   public function store()
100
   {
101
      if($this->parent->check_privileges('user') && isset($_POST['user_name'])) {
102
         return $this->parent->_("##FAILURE_CHANGE_LOGIN##");
103
      }
104
      if($this->parent->check_privileges('user') &&
105
         !$this->parent->is_auto_created($_SESSION['login_idx'])
106
         && isset($_POST['user_email'])) {
107
         return $this->parent->_("##FAILURE_CHANGE_EMAIL##");
108
      }
109
110
      if(!$this->parent->check_privileges('user') && (!isset($_POST['user_name']) ||
111
         empty($_POST['user_name']))) {
112
         return $this->parent->_("##FAILURE_ENTER_USERNAME##");
113
      }
114
      if(!$this->parent->is_deny_chpwd($_SESSION['login_idx']) && empty($_POST['user_pass1'])) {
115
         return $this->parent->_("##FAILURE_EMPTY_PASSWORD##");
116
      }
117
      /* it's not a must that the password needs to be available, as
118
         the user may not have the right to change its Nephthys password.
119
      */
120
      if(isset($_POST['user_pass1']) && isset($_POST['user_pass2']) &&
121
         $_POST['user_pass1'] != $_POST['user_pass2']) {
122
         return $this->parent->_("##FAILURE_PASSWORD_NOT_MATCH##");
123
      }
124
125
      /* user-privileged are not allowed to change their user-names */
126
      if(!$this->parent->check_privileges('user')) {
127
128
         $sth = $this->db->db_prepare("
129
            UPDATE nephthys_users
130
            SET
131
               user_name=?
132
            WHERE
133
               user_idx=?
134
         ");
135
136
         $this->db->db_execute($sth, array(
137
            $_POST['user_name'],
138
            $_POST['user_idx'],
139
         ));
140
      }
141
142
      /* handling email-address update. only privileged- or auto-created users
143
         are allowed to change their email address. Manually created users are
144
         not permitted to change their email address.
145
      */
146
      if(!$this->parent->check_privileges('user') ||
147
         $this->parent->is_auto_created($_SESSION['login_idx'])) {
148
149
         if(!isset($_POST['user_email']) || empty($_POST['user_email'])) {
150
            return $this->parent->_("##FAILURE_ENTER_EMAIL##");
151
         }
152
         if(!$this->parent->validate_email($_POST['user_email'])) {
153
            return $this->parent->_("##FAILURE_ENTER_VALID_EMAIL##");
154
         }
155
156
         $sth = $this->db->db_prepare("
157
            UPDATE nephthys_users
158
            SET
159
               user_email=?
160
            WHERE
161
               user_idx=?
162
         ");
163
164
         $this->db->db_execute($sth, array(
165
            $_POST['user_email'],
166
            $_POST['user_idx'],
167
         ));
168
      }
169
170
      /* update user's full name, default-expiry and langugage time */
171
      $sth = $this->db->db_prepare("
172
         UPDATE nephthys_users
173
         SET
174
            user_full_name=?,
175
            user_default_expire=?,
176
            user_language=?
177
         WHERE
178
            user_idx=?
179
      ");
180
181
      $this->db->db_execute($sth, array(
182
         $_POST['user_full_name'],
183
         $_POST['user_default_expire'],
184
         $_POST['user_language'],
185
         $_POST['user_idx'],
186
      ));
187
188
      if(isset($_POST['user_pass1'])) {
189
190
         /* if a password change was requested, change it here. */
191
         if($_POST['user_pass1'] != " nochangeMS " &&
192
            !$this->parent->is_deny_chpwd($_SESSION['login_idx'])) {
193
194
            $sth = $this->db->db_prepare("
195
               UPDATE nephthys_users
196
               SET
197
                  user_pass=?
198
               WHERE
199
                  user_idx=?
200
            ");
201
202
            $this->db->db_execute($sth, array(
203
               sha1($_POST['user_pass1']),
204
               $_POST['user_idx'],
205
            ));
206
         }
207
      }
208
                  
209
      return "ok";
210
211
   } // store()
212
213
} // class NEPHTHYS_PROFILE
214
215
// vim: set filetype=php expandtab softtabstop=3 tabstop=3 shiftwidth=3 autoindent smartindent:
216
?>
217