/extremedating/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/extremedating/trunk

« back to all changes in this revision

Viewing changes to adduser.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-15 22:24:25 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130415222425-lez45gq9v06tqfid
* Opitimised add user code
* images are no longer stored as base64 encoded strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<!DOCTYPE html>
2
2
<html>
 
3
<!--
 
4
    ExtremeDating - a Hackathon 2013 project.
 
5
    Copyright (C) 2013 Gustav Hartvigsson <gustav.hartvigsson@gmail.com>
 
6
    Copyright (C) 2013 Daniel Johansson <maila@danieljohansson.nu>
 
7
 
 
8
 
 
9
    This program is free software: you can redistribute it and/or modify
 
10
    it under the terms of the GNU Affero General Public License as
 
11
    published by the Free Software Foundation, either version 3 of the
 
12
    License, or (at your option) any later version.
 
13
 
 
14
    This program is distributed in the hope that it will be useful,
 
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
    GNU Affero General Public License for more details.
 
18
 
 
19
    You should have received a copy of the GNU Affero General Public License
 
20
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
-->
3
22
<head>
4
23
        <title>Extreme Dating - Create User</title>
5
24
        <link rel="stylesheet" type="text/css" href="css/main.css"/>
6
25
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
7
 
<head>
 
26
</head>
8
27
<?php
 
28
set_time_limit(0);
9
29
include "php/db.php";
 
30
include "php/salt.php";
 
31
include "php/stupid_image.php";
 
32
set_time_limit(60);
 
33
ini_set("post_max_size","16M");
 
34
ini_set("upload_max_filesize","16M");
 
35
ini_set("memory_limit","64M");
 
36
 
10
37
if(isset($_POST['hiddenStuff']) && $_POST['hiddenStuff'] == "Something Strange") {
11
 
  $password = sha1($_POST['passwd']."salt");
 
38
  $password = sha1($_POST['passwd'].$pwd_salt);
12
39
  //If there is a $_POST that indicates that the add userscript should be run.
13
40
  $query = "";
14
 
  $handle = @fopen($_FILES["image"]["tmp_name"]);
15
 
  $output = "NULL";
16
 
  if ($handle) {
17
 
      while (($buffer = fgets($handle, 4096)) !== false) {
18
 
        $buffer = str_replace("&", "&amp;", $buffer);
19
 
        $buffer = str_replace("<", "&lt;", $buffer);
20
 
        $buffer = str_replace(">", "&gt;", $buffer);
21
 
      $output .= $buffer;
22
 
     }
23
 
      if (!feof($handle)) {
24
 
      $output .= "Error: unexpected fgets() fail\n";
25
 
        }
26
 
    fclose($handle);
 
41
  $output = "";
 
42
  if(isset($_FILES["image"]["tmp_name"]) && $_FILES['image']['size'] != 0 ){
 
43
    $tmpFile = $_FILES["image"]["tmp_name"];
 
44
    $handle = fopen($tmpFile,"r");
 
45
    $fileSize = $_FILES['image']['size'];
 
46
    $output = fread($handle, filesize($tmpFile));
 
47
    $image = new Imagick();
 
48
    $image->readImageBlob($output);
 
49
    $image = stupid_convert_and_rescale($image, 280, 280, 'png');
 
50
    $output = $image;
27
51
  }
28
 
 
29
 
  if (isset($_SESSION['userType']) && $_POST['isSuperUser'] == true && $_SESSION['userType'] == 1) {
30
 
    $query = "INSERT INTO Users (
 
52
  $query = "INSERT INTO Users (
31
53
    loginName,
32
54
    shadow,
33
55
    firstName,
45
67
    '{$_POST['surName']}',
46
68
    '{$_POST['eMail']}',
47
69
    '{$_POST['city']}',
48
 
    '{$output}',
49
 
    '1'
 
70
    ? ,
 
71
    ?
50
72
    );";
 
73
  $q = null;
 
74
  try{
 
75
    $q = $db->prepare($query);
 
76
  } catch (PDOException $err) {
 
77
    echo "<pre>";
 
78
    var_dump($err);
 
79
    echo "</pre>";
 
80
    
 
81
  }
 
82
  if (isset($_SESSION['userType']) && $_POST['isSuperUser'] == true && $_SESSION['userType'] == 1) {
 
83
    $q->bindValue(2, '1');
51
84
  } else {
52
 
    $query = "INSERT INTO Users (
53
 
    loginName,
54
 
    shadow,
55
 
    firstName,
56
 
    surName,
57
 
    eMail,
58
 
    city,
59
 
    profileImage
60
 
    )
61
 
    
62
 
    VALUES(
63
 
    '{$_POST['name']}',
64
 
    '{$password}',
65
 
    '{$_POST['firstName']}',
66
 
    '{$_POST['surName']}',
67
 
    '{$_POST['eMail']}',
68
 
    '{$_POST['city']}',
69
 
    '{$output}'
70
 
    );";
71
 
  }
72
 
  $db->exec($query);
73
 
  echo "<body> <h1> New user added! </h1> </body>";
74
 
  sleep(.5);
75
 
  header("Location:./index.php");
 
85
    $q->bindValue(2, '0');
 
86
  }
 
87
  $success = NULL;
 
88
  try {
 
89
    $q->bindValue(1,$output, PDO::PARAM_LOB);
 
90
    $q->execute();
 
91
    $success = true;
 
92
  } catch (PDOException $err) {
 
93
    echo "<pre>";
 
94
    var_dump($err);
 
95
    var_dump($query);
 
96
    var_dump($q);
 
97
    echo "</pre>";
 
98
    $success = false;
 
99
  } if ($success) {
 
100
    /*echo "<pre>";
 
101
    var_dump($query);
 
102
    var_dump($q);
 
103
    echo "</pre>";
 
104
    */
 
105
    echo "<body> <h1> New user added! </h1>";
 
106
    sleep(1);
 
107
    header("Location:./index.php");
 
108
  }
76
109
} else {
77
110
 
78
111
?>
81
114
        <div id="frame">
82
115
    <h1> Create a new user </h1>
83
116
    <hr />
84
 
        <form action="./adduser.php" method="POST">
 
117
        <form action="./adduser.php" method="POST" enctype="multipart/form-data">
85
118
          <table border="0">
86
119
            <?php
87
120
              if(isset($_SESSION['userType']) && $_SESSION['userType'] == 1 ) {
120
153
              <td> <input type="input" name="city" id="city" /> </td>
121
154
            </tr>
122
155
            <tr>
123
 
              <td> <label for="file"> City </label> </td>
 
156
              <td> <label for="file"> Profile Image </label> </td>
124
157
              <td> <input type="file" name="image" id="image" /> </td>
125
158
            </tr>
126
159
                              <tr>
129
162
            </tr>
130
163
          </table>
131
164
        </form>
132
 
      <?php
 
165
            </div>
 
166
    </div>
 
167
    <?php
133
168
}
134
 
      ?>
135
 
          </div>
136
 
    </div>
 
169
    ?>
 
170
 
137
171
  </body>
138
172
</html>