Automad
 All Classes Functions Variables Pages
add_user.php
1 <?php
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  * AUTOMAD
29  *
30  * Copyright (c) 2014 by Marc Anton Dahmen
31  * http://marcdahmen.de
32  *
33  * Licensed under the MIT license.
34  * http://automad.org/license
35  */
36 
37 
38 defined('AUTOMAD') or die('Direct access not permitted!');
39 
40 
41 /*
42  * Add an user.
43  */
44 
45 
46 $output = array();
47 
48 
49 if (isset($_POST['username']) && $_POST['username'] && isset($_POST['password1']) && $_POST['password1'] && isset($_POST['password2']) && $_POST['password2']) {
50 
51  // Check if password1 equals password2.
52  if ($_POST['password1'] == $_POST['password2']) {
53 
54  // Get all accounts from file.
55  $accounts = $this->accountsGetArray();
56 
57  // Check, if user exists already.
58  if (!isset($accounts[$_POST['username']])) {
59 
60  // Add user to accounts array.
61  $accounts[$_POST['username']] = $this->passwordHash($_POST['password1']);
62  ksort($accounts);
63 
64  // Write array with all accounts back to file.
65  if ($this->accountsSaveArray($accounts)) {
66 
67  $output['success'] = $this->tb['success_added'] . ' <strong>' . $_POST['username'] . '</strong>';
68 
69  } else {
70 
71  $output['error'] = $this->tb['error_permission'] . '<p>' . AM_FILE_ACCOUNTS . '</p>';
72 
73  }
74 
75  } else {
76 
77  $output['error'] = '<strong>' . $_POST['username'] . '</strong> ' . $this->tb['error_existing'];
78 
79  }
80 
81  } else {
82 
83  $output['error'] = $this->tb['error_form'];
84 
85  }
86 
87 } else {
88 
89  $output['error'] = $this->tb['error_form'];
90 
91 }
92 
93 
94 echo json_encode($output);
95 
96 
97 ?>