forked from eckama11/air_quality
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoAdd.php
43 lines (34 loc) · 1.21 KB
/
doAdd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
require_once("common.php");
// If the form was posted, verify the old password
// and update the password if the 2 new passwords match and are acceptable
// check that username is not taken
$username = @$_POST['username'];
$email = @$_POST['email'];
$device = @$_POST['device'];
$password1 = @$_POST['password1'];
$password2 = @$_POST['password2'];
$rv = (Object)[];
try {
// Verify the username is unique
if ($db->isUsernameInUse($username))
throw new Exception("The username '$username' is already assigned to another user");
// Verify the password is valid
if ($password1 != $password2)
throw new Exception("The password and verify password do not match");
// Verify password is > 8 length
if (strlen($password1) < 8)
throw new Exception("The new password must be at least 8 characters long");
// id = 0 means no id given yet
//will be used in DBInterface to make new id
$id = 0;
// Create/update the user record
$user1 = new User(
$id, $username, $password1, $email, $device
);
$user = $db->writeUser($user1);
$rv->success = true;
} catch (Exception $ex) {
$rv->error = $ex->getMessage();
} // try/catch
echo json_encode($rv);