Menu

[r1]: / sampleCode / login.php  Maximize  Restore  History

Download this file

63 lines (49 with data), 1.4 kB

 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
<?php
/*
********************************************************
Name: login.php
Author: Rob Hunter
Date 1/19/11
Description: Sample code to test loginTools. This page allows users to login
********************************************************
*/
require_once('../lib/initHunterDB.php');
$user = getUser();
$email = $_POST['email'];
$password = $_POST['password'];
$action = $_POST['action'];
if ($action == 'login'){
if ( !empty($email) && !empty($password) ){
try {
$user = loginUser($email, $password);
//echo "Logged in<br>";
}
catch (Exception $e){
$error = $e->getMessage();
}
}
}
elseif($action=='logout'){
logoutUser();
unset($user);
}
if (!empty($user)){
echo "Welcome, ".$user->my->email."<br>";
?>
<form name="log_out" method="POST">
<input type="hidden" name="action" value="logout">
<input type="submit" value="Logout">
</form>
<?php
}else{
?>
<form name="sign_up" method="POST">
<?php if (!empty($error)){echo $error.'<br>';}?>
<input type="hidden" name="action" value="login">
Email: <input type="text" name="email"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
<?php
} // end if empty ($user)
?>
MongoDB Logo MongoDB