summaryrefslogtreecommitdiff
path: root/Simple-UM-Login-Admin.php
blob: 4ca94dde5437c10650092fd62f59d56e3d8ce44a (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<html>
<head>
<style>
div.simpleum_style {
	padding: 5px;
	background: #EBEBEB;
	margin: 10px;
	font-family: Calibri,Helvetica,Arial,sans-serif;
	float: left;
}
div.simpleum_style_test {
	padding: 5px;
	margin: 0px 10px 10px 10px;
	background: #EBEBEB;
	font-family: Calibri,Helvetica,Arial,sans-serif;
	float: left;
}
h1.banner {
	padding 5px;
	margin-left: 10px;
	margin-top: 15px;
	font-family: Calibri,Helvetica,Arial,sans-serif;
}
h2, h3, h4 {
	margin: 0;
}
p {
	margin-bottom: 0;
}
</style>
</head>
<?php
//Debug
$debug = false;

//Where are we?
$this_page = $_SERVER['PHP_SELF'].'?page='.$_GET['page'];

//If this is a test, we will use this variable
$bool_test = 0;

//If admin options updated (uses hidden field)
if ($_POST['stage'] == 'process') {
	// Store settings
	update_option('simpleum_url', $_POST['um_url']);

	// Version 1.3
	update_option('simpleum_login_mode',$_POST['mode']);
	update_option('simpleum_group',$_POST['group_name']);
	update_option('simpleum_account_type',$_POST['create_type']);

	// Version 1.3.0.2
	update_option('simpleum_security_mode',$_POST['security_mode']);
}
// Test credentials
if ($_POST['stage'] == 'test') {
	//Temporarily change security mode for test. Store old setting.
	$temp_holder = get_option("simpleum_security_mode");
	update_option("simpleum_security_mode", "security_high");

	$test_user = wp_authenticate($_POST['test_username'],$_POST['test_password']);

	// Restore security mode setting.
	update_option("simpleum_security_mode", $temp_holder);

	if ($test_user->ID > 0) {
		$bool_test = 1;
	} else {
		$bool_test = 2;
	}
}
// Load settings, etc
$simpleum_url = get_option("simpleum_url");

// Version 1.3
$simpleum_login_mode   = get_option("simpleum_login_mode");
$simpleum_group        = get_option("simpleum_group");
$simpleum_account_type = get_option("simpleum_account_type");

// Version 1.3.0.2
$simpleum_security_mode = get_option("simpleum_security_mode");

?>
<body>
  <div class="container">
    <div class="banner"><h1 class="banner">Simple UM Login 1.4.0.5.1</h1></div>
    <form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>&updated=true">
      <div class="simpleum_style">
	<h2>Settings</h2>
	<h3>These are rather important.</h3>
	<label for="um_url">URL of UM installation:</label>
	<input name="um_url" id="um_url" type="text" value="<?php echo $simpleum_url; ?>" />
	<br />
	<h2>Advanced</h2>
	<h3>For the intrepid and daring among you.</h3>
	<h4>Login mode:</h4>
	<ul>
	  <li>
	    <input name="mode" type="radio" value="mode_normal" <?php if($simpleum_login_mode=="mode_normal"){echo "checked";}?> />
	    <label for="mode_normal">Authenticate Wordpress users against UM. I will create the accounts in wordpress myself. (default)</label>
	  </li>
	  <li>
	    <input name="mode" type="radio" value="mode_create_all" <?php if($simpleum_login_mode=="mode_create_all"){echo "checked";}?> />
	    <label for="mode_create_all">Create Wordpress account for anyone who successfully authenticates against UM.</label>
	  </li>
	  <li>
	    <input name="mode" type="radio" value="mode_create_group" <?php if($simpleul_login_mode=="mode_create_group"){echo "checked";}?> />
	    <label for="mode_create_group">Create Wordpress account for users in specified UM group:</label>
	    <input name="group_name" type="text" value="<?php  echo $simpleum_group; ?>" />
	  </li>
	</ul>
	<h4>For latter two options, create account as:</h4>
	<select name="create_type">
	  <option value="Administrator" <?php if($simpleum_account_type=="Administrator"){echo 'selected="selected"';}?> >Administrator</option>
	  <option value="Editor"        <?php if($simpleum_account_type=="Editor"){echo 'selected="selected"';}?> >Editor</option>
	  <option value="Author"        <?php if($simpleum_account_type=="Author"){echo 'selected="selected"';}?> >Author</option>
	  <option value="Contributor"   <?php if($simpleum_account_type=="Contributor"){echo 'selected="selected"';}?> >Contributor</option>
	  <option value="Subscriber"    <?php if($simpleum_account_type=="Subscriber"){echo 'selected="selected"';}?> >Subscriber</option>
	</select>
	<h4>Security mode:</h4>
	<ul>
	  <li>
	    <input name="security_mode" type="radio" id="security_low" value="security_low" <?php if($simpleum_security_mode=="security_low"){echo "checked";}?> />
	    <label for="security_low"><strong>Low.</strong> Default mode. First attempts to login with UM password, failing that, it attempts to login using the local wordpress password. If you intend to use a mixture of local and UM accounts, leave this mode enabled.</label>
	  </li>
	  <li>
	    <input name="security_mode" type="radio" id="security_high" value="security_high" <?php if($simpleum_security_mode=="security_high"){echo "checked";}?> />
	    <label for="security_high"><strong>High.</strong>Restrict login to only UM passwords. If a wordpress username fails to authenticate against UM, login will fail. More secure.</label>
	  </li>
	</ul>
	<input type="hidden" name="stage" value="process" />
	<input type="submit" name="button_submit" value="<?php _e('Update Options', 'simple-um-login') ?> &raquo;" />
      </div>
    </form>
    <div class="simpleum_style_test">
      <h2>Test Settings</h2>
      <h3>Use this form as a limited test for those settings you saved.* This <em>will</em> test user creation and group membership. If settings don't work, use another browser to try actually logging in. (unless you'd rather get locked out)</h3>
      <h4>*You did save them, right?</h4>
      <form method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
	<ul>
	  <li>
	    <label for="test_username">Username:</label>
	    <input name="test_username" id="test_username"type="text" />
	  </li>
	  <li>
	    <label for="test_password">Password:</label>
	    <input name="test_password" id="test_password" type="password" />
	  </li>
	</ul>
	<input type="hidden" name="stage" value="test" />
	<input type="submit" name="button_submit" value="<?php _e('Test Settings', 'simple-um-login') ?> &raquo;" />
      </form>
      <div>
	<h4>Test Results:</h4>
	<p><?php
if ($bool_test == 0) {
	echo "Nothing to report yet, Mr. Fahrenheit.";
} if ($bool_test == 1) {
	echo "Congratulations! The test succeeded. This account is able to login.";
} elseif ($bool_test == 2) {
	echo "Failure. Your settings do not seem to work yet or the credentials are either wrong or have insufficient group membership.";
	if (is_a($test_user, 'WP_Error')) {
		echo '</p><p>'.$test_user->get_error_message();
	}
}
?></p>
      </div>
    </div>
  </div>
<?php
//Echo settings
if($debug) { ?>
  <div>
    <h4>Debug Info:</h4>
    <ul>
      <li>simpleum_login_mode:
	<?php echo get_option("simpleum_login_mode")."/".$_POST['mode']; ?>
      </li>
      <li>simpleum_group:
	<?php echo get_option("simpleum_group")."/".$_POST['group_name']; ?>
      </li>
      <li>simpleum_account_type:
	<?php echo get_option("simpleum_account_type")."/".$_POST['create_type']; ?>
      </li>
    </ul>
  </div>
<?php }
?>
</body>
</html>