~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to repro/php/userhome.php

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
require('reprofunctions.php');
 
4
dbgSquirt("============= userhome ===============");
 
5
 
 
6
// TODO
 
7
/* There is a bug here ... if a user has authenticated successfully (and hence
 
8
        the cookies for username and passwordMD5 are set) and then they use BACK
 
9
        to go back to the login page, enter some values for username and 
 
10
        password, and click login, then what they just typed will be ignored, 
 
11
        and they will remain logged in under their original credentials. */
 
12
 
 
13
// this variable controls whether the user is forced back to the main page to
 
14
// login.  For safety, the default value is to force you back.
 
15
$forceLogin = TRUE;
 
16
$error = "";
 
17
$time = time();
 
18
 
 
19
if (!checkCookies($forceLogin,$error,TRUE)) {
 
20
  // we got an error back that occurred while checkCookies was being run
 
21
  dbgSquirt('Error from checkCookies');
 
22
  header("Location: http://" . $_SERVER['HTTP_HOST'] . 
 
23
         dirname($_SERVER['PHP_SELF']) . "/index.php?error=$error");
 
24
  exit;
 
25
 }
 
26
 
 
27
// if the cookie's didn't pass authentication, or if the cookie's passed BUT
 
28
// we've received new values for POST that don't match on username (they did
 
29
// a BACK to the login page w/o a logout and then did a new login), then
 
30
// try to authenticate via the POSTED values been supplied.
 
31
if (isset($_POST['username']) && ($_POST['username'] != $_COOKIE['user']))
 
32
  $forceLogin = TRUE;
 
33
 
 
34
if ($forceLogin) {
 
35
  dbgSquirt('forceLogin is still true... checking post variables');
 
36
  if (isset($_POST['username']) || isset($_POST['password'])) {
 
37
    // we have one or more post variables
 
38
    dbgSquirt('Post variables are set');
 
39
    if (empty($_POST['username']) || empty($_POST['password'])) {
 
40
      // can't have empty values for username or password
 
41
      dbgSquirt('...but one is empty');
 
42
      $error = "Authentication error -- you must enter a username and password.";
 
43
    } else {
 
44
      // we have non-empty values for username and password from POST so
 
45
      // lets validate them
 
46
      dbgSquirt('...both are non-empty [good]');
 
47
      $username = $_POST['username'];
 
48
      $password = $_POST['password'];
 
49
      $encryptedPassword = createPassword($username,$password);
 
50
 
 
51
      $state = validateUser($username,$encryptedPassword);
 
52
      if ("N" == $state) {
 
53
        dbgSquirt('Not a valid user');
 
54
        $error = "Authentication error -- Invalid username/password combination.";
 
55
      } else if ("A" == $state) {
 
56
        // active account and username/password match
 
57
        dbgSquirt('Active account matched.');
 
58
 
 
59
        // if we haven't already looked up the salt, do so now
 
60
        $result = TRUE;
 
61
        if (empty($salt)) {
 
62
          dbgSquirt('Getting salt');
 
63
          $result = getSalt($salt); }
 
64
 
 
65
        if (FALSE == $result) {
 
66
          // uh-oh ... we got an error getting the salt
 
67
          dbgSquirt('Error in getSalt');
 
68
          $error = "Internal error -- failure while processing login. Please contact an administrator.";
 
69
        } else {
 
70
          dbgSquirt('Extending cookies');
 
71
          dbgSquirt("Time -- $time");
 
72
          dbgSquirt("Time + Duration -- ". ($time+$sessionDuration));
 
73
          $result = setcookie("user",$username,$time+$sessionDuration);
 
74
          $result1 = setcookie("authentication",sha1($username . $salt),
 
75
                               $time+$sessionDuration);
 
76
 
 
77
          if ((TRUE == $result) && (TRUE == $result1)) {
 
78
            // everything worked
 
79
            dbgSquirt('Everything worked.');
 
80
            $forceLogin = FALSE;
 
81
          } else {
 
82
            dbgSquirt('Error while creating cookies');
 
83
            $error = "Internal error -- problem while creating cookies.  Please contact an administrator.";
 
84
          }
 
85
        }
 
86
      } else if ("U" == $state) {
 
87
        // unverified account
 
88
        dbgSquirt('Unverified Account');
 
89
        $error="This account has not been verified. Please check for the verification email you were sent as part of the signup process.";
 
90
      } else if ("D" == $state) {
 
91
        // disabled account
 
92
        dbgSquirt('Disabled Account');
 
93
        $error = "This account has been disabled.";
 
94
      } else {
 
95
        // should not happen ... checked return value from validateUser
 
96
        dbgSquirt('Unknown return code from validateUser');
 
97
        $error = "Internal Error -- error validating username/password.  Please try again.  This this error reoccurs, please contact an administrator.";
 
98
          }
 
99
    }
 
100
  } else {
 
101
    // no post variables supplied
 
102
    dbgSquirt('No post variables');
 
103
    $error = "Authentication error -- you must enter a username and password.";
 
104
  }
 
105
 } else {
 
106
  // forceLogin was FALSE ... that means the cookie's were valid
 
107
  // so get username from the cookie
 
108
  $username = $_COOKIE['user'];
 
109
 }
 
110
 
 
111
// after checking cookies and post variables, if a login is still needed, then
 
112
// redirect
 
113
dbgSquirt("After post check -- forceLogin = $forceLogin");
 
114
if ($forceLogin) {
 
115
  header("Location: http://" . $_SERVER['HTTP_HOST'] . 
 
116
            dirname($_SERVER['PHP_SELF']) . 
 
117
            "/index.php?error=$error");
 
118
  exit;
 
119
 }
 
120
?>
 
121
 
 
122
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
123
 
 
124
<!--
 
125
System:  Repro
 
126
File:    userhome.php
 
127
Purpose: User Home Page.  This displays the users personal information and
 
128
         allows changes to be made.
 
129
Author:  S. Chanin
 
130
-->
 
131
 
 
132
<html>
 
133
<head>
 
134
<link rel="stylesheet" type="text/css" href="repro_style.css" />
 
135
<title></title>
 
136
</head>
 
137
 
 
138
<body>
 
139
<h1 class="title">Repro</h1>
 
140
 
 
141
<h1>User Home Page</h1>
 
142
<hr />
 
143
 
 
144
<?php
 
145
// if we've looped back due to an error, show the message
 
146
if (isset($_GET["error"]) && !empty($_GET['error'])) {
 
147
    echo '<p class="error">' . $_GET["error"] . "</p>\n";
 
148
}
 
149
if (!lookupUserInformation($username,$id,$fullname,$domain,$email)) {
 
150
        echo "<h2>Error -- Error while accessing account information</h2>\n";
 
151
        echo "<p>Please contact your administrator for assistance.</p>\n";
 
152
} else {
 
153
?>
 
154
<!-- show basic user information with the user -->
 
155
<table border="0" cellpadding="5">
 
156
<tr>
 
157
<td>Username</td>
 
158
<td><h2><?php echo $username ?></h2></td>
 
159
</tr>
 
160
 
 
161
<tr>
 
162
<td>Fullname</td>
 
163
<td><?php echo $fullname ?></td>
 
164
<td><a href="changefullname.php">Change Fullname</a></td>
 
165
</tr>
 
166
 
 
167
<tr>
 
168
<td>Password</td>
 
169
<td>********</td>
 
170
<td><a href="changepassword.php">Change Password</a></td>
 
171
</tr>
 
172
 
 
173
<tr>
 
174
<td>Email</td>
 
175
<td><?php echo $email ?></td>
 
176
<td><a href="changeemail.php">Change Email</a></td>
 
177
</tr>
 
178
 
 
179
<tr>
 
180
<td>Domain</td>
 
181
<td><?php echo $domain ?></td>
 
182
</tr>
 
183
</table>
 
184
 
 
185
<!-- now show the resources associated with the user -->
 
186
<br />
 
187
<table border="1">
 
188
<th class="header">Address</th><th class="header">Forward</th>
 
189
<th class="header">Voicemail</th><th class="header">Edit</th><th class="header">Delete</th>
 
190
 
 
191
<?php
 
192
$result = getResourcesByUsername($username,$resources);
 
193
// print "<br />Final Result --";
 
194
// print_r($resources);
 
195
foreach ($resources as $r) {
 
196
  // print "Row -- ";
 
197
  // print_r($r);
 
198
  // print "<br />";
 
199
        
 
200
  $id = $r[0];
 
201
  $aor = $r[1];
 
202
  $forwardType = $r[2];
 
203
  $forward = $r[3];
 
204
  $voicemail = $r[4];
 
205
 
 
206
  echo "<tr>";
 
207
  echo '<form method="post" action="modifyresource.php">'."\n";
 
208
  echo "<td>$aor</td>\n";
 
209
  if ("Y" == $forwardType)
 
210
    echo "<td>$forward</td>\n";
 
211
  else
 
212
    echo "<td>&nbsp</td>\n";
 
213
  echo "<td>$voicemail</td>\n";
 
214
 
 
215
  echo '<td><input type="submit" name="edit" id="edit" value="Edit"/></td>'."\n";
 
216
  echo '<td><input type="submit" name="delete" id="delete" value="Delete"/></td>'."\n";
 
217
  echo '<input type="hidden" name="resourceId" id="resourceId" value="' . $id .'" />'."\n";
 
218
  echo '<input type="hidden" name="aor" id="aor" value="' . $aor .'" />'."\n";
 
219
  echo '<input type="hidden" name="forwardType" id="forwardType" value="' . $forwardType .'" />'."\n";
 
220
  echo '<input type="hidden" name="forward" id="forward" value="' . $forward .'" />'."\n";
 
221
  echo '<input type="hidden" name="voicemail" id="voicemail" value="' . $voicemail .'" />'."\n";
 
222
  echo "</form>\n";
 
223
  echo "</tr>\n";
 
224
}
 
225
?>
 
226
</table>
 
227
<form method="post" action="addresource.php">
 
228
<input type="submit" name="addResource" id="addResource" value="Add Resource" />
 
229
</form>
 
230
 
 
231
<?php
 
232
} ?>
 
233
<br /><hr /><a href="logout.php">Logout</a>
 
234
 
 
235
</body>
 
236
</html>