summaryrefslogtreecommitdiff
path: root/appli_3_alpha_old/auth_dialog.php
blob: b55e0f029611caff2bd8353c14f97e1b58de5180 (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
<?php
	// R�cup�ration des param�tres
	if ( isset($_GET['retour']) && $_GET['retour']!='' )
		{ $retour=addslashes( $_GET['retour'] ); } else { $retour='index.php'; }

	// Si le formulaire � �t� envoy�, on le traite ici
	if ( isset($_POST['envoi']) && $_POST['envoi'] === '1' )
	{
		if ( ! ( isset($_POST['loginP']) && isset($_POST['pass']) )  )
		{
			$errmsg = 'Param�tres incorrects';
		}
		else
		{
			$loginP=addslashes( $_POST['loginP'] );
			
			
			include 'include/ludo/auth.inc.php';
			
			// Code v�rifiant que la personne qui tente de se connecter est bien r�f�renc�e dans notre base
			include 'include/ludo/fonctions.inc.php';
			// Connexion � la base et s�lection de la database
			include 'include/connect.inc.php';
			include 'include/ludo/config.inc.php';

			// Requete SQL
			$query = "SELECT idP, loginP, nomP, prenomP, methodeAuth FROM Personne WHERE loginP='$loginP';";
			if ( ! $result = @mysql_query($query) )
			{
				// Cas d'erreur
				$errmsg =mysql_generate_errmsg();
			}
			else
			{
				// Initialisation par d�faut
				$methodeAuth='';
				// Chargement des pr�f�rences d'authentification de l'utilisateur
				if ( mysql_num_rows($result) === 1)
				{
					list($idP, $loginP, $nomP, $prenomP, $methodeAuth) = mysql_fetch_row($result);
				}
				// Si le script est lanc� en local, on saute l'authentification
				if ( ($CONFIG['AUTH']['bypass_if_local'] === true ) 
					&& ( ($_SERVER['REMOTE_ADDR'] == 'localhost') || ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') ) )
				{
					$methodeAuth='bypass';
				}
				
				$auth_is_ok=false;
				switch (  $methodeAuth )
				{
					case 'webetud':
						// TODO
					break;
					// Vous pouvez ajouter d'autres mode d'authentification ici !
					case 'bypass':
						$auth_is_ok=true;
					break;
					default:
						// Tentative d'authentification POP
						if ( ($errno = pop3_auth_simple($loginP, addslashes($_POST['pass']) ) ) != 0 )
						{
							// Authentification �chou�e
							$errmsg=pop3_generate_errmsg($errno);
						}
						else
						{
							$auth_is_ok=true;
						}
					break;
				}
				if ( $auth_is_ok === true )
				{
					// Authentification r�ussie
					session_start();
					$_SESSION['loginP']=$loginP;
					if ( isset($nomP) ) $_SESSION['nomP']=$nomP;
					if ( isset($prenomP) ) $_SESSION['prenomP']=$prenomP;
					$_SESSION['idP']=$idP;
					require('include/ludo/redir.inc.php');
					html_redir($retour);
				}
			}
		}
	}
require_once('include/ludo/html_elements.inc.php');
generate_html_doctype_and_head("Identification");
?>
<body onload="javascript:document.forms['auth'].elements['loginP'].focus()">
	<h1>Application Web d'Organisation de R�union</h1>
	<h2>Veuillez vous identifier</h2>
	<?php echo '<form id="auth" method="post" action="' . $_SERVER['PHP_SELF'] . '">' . "\n"; ?>
		<input type="hidden" name="envoi" value="1" />
		<?php echo '<input type="hidden" name="retour" value="' .  $retour . '" />' . "\n" ; ?>
		<div class="aligned">
			<div>
				<span class="label">Votre identifiant :</span>
				<span class="field"><input name="loginP" type="text" size="20" tabindex="1" /></span>
			</div>
			<div>
				<span class="label">Votre mot de passe :</span>
				<span class="field"><input name="pass" type="password" size="20" tabindex="2" /></span>
			</div>
			<div>
				<span class="label"><input type="reset" value="Vider" /></span>
				<span class="field"><input type="submit" value="Valider" /></span>
			</div>
		</div>
<?php if ( isset ($debug) ) { echo '			<input type="hidden" name="debug" value="true" />' . "\n"; } ?>
	</form>
<?php if ( isset ($errmsg) ) { generate_html_div_errmsg($errmsg); } ?>
</body>
</html>