/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 17:10:47 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130415171047-4oi51n3olx6cmn7v
woops..

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
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
-->
 
22
<head>
 
23
        <title>Extreme Dating - Create User</title>
 
24
        <link rel="stylesheet" type="text/css" href="css/main.css"/>
 
25
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 
26
<head>
 
27
<?php
 
28
set_time_limit(0);
 
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
 
 
37
if(isset($_POST['hiddenStuff']) && $_POST['hiddenStuff'] == "Something Strange") {
 
38
  $password = sha1($_POST['passwd'].$pwd_salt);
 
39
  //If there is a $_POST that indicates that the add userscript should be run.
 
40
  $query = "";
 
41
  $output = "";
 
42
  if(isset($_FILES["image"]["tmp_name"])){
 
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 = base64_encode ($image);
 
51
  }
 
52
  if (isset($_SESSION['userType']) && $_POST['isSuperUser'] == true && $_SESSION['userType'] == 1) {
 
53
    $query = "INSERT INTO Users (
 
54
    loginName,
 
55
    shadow,
 
56
    firstName,
 
57
    surName,
 
58
    eMail,
 
59
    city,
 
60
    profileImage,
 
61
    userType
 
62
    )
 
63
    
 
64
    VALUES(
 
65
    '{$_POST['name']}',
 
66
    '{$password}',
 
67
    '{$_POST['firstName']}',
 
68
    '{$_POST['surName']}',
 
69
    '{$_POST['eMail']}',
 
70
    '{$_POST['city']}',
 
71
    '{$output}',
 
72
    '1'
 
73
    );";
 
74
  } else {
 
75
    $query = "INSERT INTO Users (
 
76
    loginName,
 
77
    shadow,
 
78
    firstName,
 
79
    surName,
 
80
    eMail,
 
81
    city,
 
82
    profileImage
 
83
    )
 
84
    
 
85
    VALUES(
 
86
    '{$_POST['name']}',
 
87
    '{$password}',
 
88
    '{$_POST['firstName']}',
 
89
    '{$_POST['surName']}',
 
90
    '{$_POST['eMail']}',
 
91
    '{$_POST['city']}',
 
92
    '{$output}'
 
93
    );";
 
94
  }
 
95
  $success = NULL;
 
96
  try {
 
97
    $db->exec($query);
 
98
    $success = true;
 
99
  } catch (PDOException $err) {
 
100
    echo "<pre>";
 
101
    var_dump($err);
 
102
    var_dump($query);
 
103
    echo "</pre>";
 
104
    $db->rollBack();
 
105
    $success = false;
 
106
  } if ($success) {
 
107
    echo "<body> <h1> New user added! </h1> </body>";
 
108
    sleep(1);
 
109
    header("Location:./index.php");
 
110
  }
 
111
} else {
 
112
 
 
113
?>
 
114
  <body id="wrapper">
 
115
        <div id="profile">
 
116
        <div id="frame">
 
117
    <h1> Create a new user </h1>
 
118
    <hr />
 
119
        <form action="./adduser.php" method="POST" enctype="multipart/form-data">
 
120
          <table border="0">
 
121
            <?php
 
122
              if(isset($_SESSION['userType']) && $_SESSION['userType'] == 1 ) {
 
123
                //you are a superuser!
 
124
                //you can add other superusers.
 
125
            ?>
 
126
            <tr>
 
127
              <td> <label for="user"> Is the user a Super User? </label> </td>
 
128
              <td> <input type="checkbox" name="isSuperUser" id="super" /> </td>
 
129
            </tr>
 
130
            <?php
 
131
              }
 
132
            ?>
 
133
            <tr>
 
134
              <td> <label for="name"> User Name </label> </td>
 
135
              <td> <input type="input" name="name" id="name" /> </td>
 
136
            </tr>
 
137
            <tr>
 
138
              <td> <label for="passwd"> Password </label> </td>
 
139
              <td> <input type="password" name="passwd" id="passwd" /> </td>
 
140
            </tr>
 
141
            <tr>
 
142
              <td> <label for="firstname"> First Name </label> </td>
 
143
              <td> <input type="input" name="firstName" id="firstname" /> </td>
 
144
            </tr>
 
145
            <tr>
 
146
              <td> <label for="surname"> Sur Name </label> </td>
 
147
              <td> <input type="input" name="surName" id="surname" /> </td>
 
148
            </tr>
 
149
            <tr>
 
150
              <td> <label for="email"> E-mail </label> </td>
 
151
              <td> <input type="input" name="eMail" id="email" /> </td>
 
152
            </tr>
 
153
            <tr>
 
154
              <td> <label for="city"> City </label> </td>
 
155
              <td> <input type="input" name="city" id="city" /> </td>
 
156
            </tr>
 
157
            <tr>
 
158
              <td> <label for="file"> Profile Image </label> </td>
 
159
              <td> <input type="file" name="image" id="image" /> </td>
 
160
            </tr>
 
161
                              <tr>
 
162
              <td><input name="hiddenStuff" value="Something Strange" type="hidden"/></td>
 
163
              <td><input id="inputbutton1" type="submit" action="./adduser.php" value="Registera mig"/></td>
 
164
            </tr>
 
165
          </table>
 
166
        </form>
 
167
      <?php
 
168
}
 
169
      ?>
 
170
          </div>
 
171
    </div>
 
172
  </body>
 
173
</html>