-
Notifications
You must be signed in to change notification settings - Fork 0
/
slouchin.php
52 lines (47 loc) · 1.36 KB
/
slouchin.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
44
45
46
47
48
49
50
51
52
<?php
if (count($_POST) == 0) {
if (is_array($_SESSION['slouchin'])) {
header('Location: private.php');
exit;
}
header('Location: index.html');
exit;
}
require_once 'Sag/Sag.php';
/*$username="admin"; // Mysql username
$password="password"; // Mysql password
print_r($_POST);*/
// Define $myusername and $mypassword
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$s = new Sag();
/* cookie auth */
try {
$res = $s->login($myusername, $mypassword, Sag::$AUTH_COOKIE);
//$me = $s->get('org.couchdb.user:'.$_POST['username'])->body;
if ($res->body->ok) {
session_name('SlouchIn');
session_id($res->cookies->AuthSession);
session_start();
$_SESSION['slouchin'] = array('name'=>$myusername);
header("Location: private.php");
exit;
}
} catch (SagCouchException $e) {
echo 'Wrong Username or Password. <a href="index.html">Try Again?</a>';
}
/* HTTP Basic Auth code
Don't use this unless you can *safely* store the user's username and password
somewhere safe safely without risk in a safe place. Got it! :)
$s->login($_POST['username'], $_POST['password']);
try {
$s->setDatabase('_users');
$me = $s->get('org.couchdb.user:'.$_POST['username'])->body;
if ($me->_id) {
$_SESSION['slouchin'] = array('username'=>$myusername);
header("Location: private.php");
exit;
}
} catch (SagCouchException $e) {
echo "Wrong Username or Password";
}*/