summaryrefslogtreecommitdiff
path: root/final/app/auth_dialog.php
blob: fce5948db070fc9506f5e5f098237c4cbc3798b2 (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
<?php
include 'include/ludo/auth.inc.php';
// Code v&eacute;rifiant que la personne qui tente de se connecter est bien r&eacute;f&eacute;renc&eacute;e dans notre base
include 'include/ludo/fonctions.inc.php';
// Connexion &agrave; la base et s&eacute;lection de la database
include 'include/connect.inc.php';

//Fonction d'authentification 
function authentification($loginP,$pass,$verifAuth="")
{
	//~ echo "function authentification($loginP,$pass,$verifAuth='')\n";
	include 'include/ludo/config.inc.php';
	
	// Requete SQL
	$query = "SELECT idP, loginP, nomP, prenomP, methodeAuth FROM AWOR_Personne WHERE loginP='$loginP';";
	if ( ! $result = @mysql_query($query) )
	{
		// Cas d'erreur
		$errmsg =mysql_generate_errmsg();
	}
	else
	{
		// Initialisation par d&eacute;faut
		$methodeAuth='';
		$existLogin=mysql_num_rows($result);
		// Chargement des pr&eacute;f&eacute;rences d'authentification de l'utilisateur
		if ($existLogin  === 1)
		{
			list($idP, $loginP, $nomP, $prenomP, $methodeAuth) = mysql_fetch_row($result);
		}
		
		
		// Si le script est lanc&eacute; en local, on saute l'authentification
		//~ $a = $CONFIG['AUTH']['bypass_if_local'];
		//~ $b = $_SERVER['REMOTE_ADDR'];
		
		//~ echo "if ( ($a === true ) && ( ($b == 'localhost') || ( $b == '127.0.0.1') ) )\n";
		if ( ($CONFIG['AUTH']['bypass_if_local'] === true ) 
			&& ( ($_SERVER['REMOTE_ADDR'] == 'localhost') || ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') ) )
		{
			//~ echo "VRAI";
			$methodeAuth='bypass';
		}
		//~ else echo "FAUX";

		//~ echo "DEBUG1 : \$methodeAuth==$methodeAuth\n";

		$auth_is_ok=false;
		if ($verifAuth != "") {$methodeAuth = $verifAuth;} // Pour la v�rification d'authentification (monProfil)
		
		//~ echo "DEBUG2 : \$methodeAuth==$methodeAuth\n";
		switch (  $methodeAuth )
		{
			case 'webetud':
				// include...
				$auth_is_ok=VerifOuvertureSession("quelconque");
				if ( ! $auth_is_ok ) { $errmsg="Authentification WebEtud refus&eacute;e !"; }
			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, $pass) ) != 0 )
				{
					// Authentification &eacute;chou&eacute;e
					$errmsg=pop3_generate_errmsg($errno);
					//~ echo "DEBUG : \$errmsg == $errmsg\n";
				}
				else
				{
					$auth_is_ok=true;
				}
			break;
		}
		if ( $auth_is_ok === true )
		{
			// Authentification r&eacute;ussie
			/*Inscription de la personne si elle �tait inconnue de la base de donn�e :*/
			if ($existLogin === 0 && $verifAuth == "")
			{	
				$idP_new =  new_pers ($loginP);
				$query = "SELECT idP, loginP, nomP, prenomP, methodeAuth FROM AWOR_Personne WHERE idP='$idP_new';";
				if ( ! $result = @mysql_query($query) )
				{
					// Cas d'erreur
					$errmsg =mysql_generate_errmsg();
				}
				// Chargement des pr&eacute;f&eacute;rences d'authentification de l'utilisateur
				if (mysql_num_rows($result)  === 1)
				{
					list($idP, $loginP, $nomP, $prenomP, $methodeAuth) = mysql_fetch_row($result);
				}
			}
			
			
			
			session_start();
			$_SESSION['session_loginP']=$loginP;
			$_SESSION['session_nomP']=$nomP;
			$_SESSION['session_prenomP']=$prenomP;
			$_SESSION['session_idP']=$idP;
		}
		return ($auth_is_ok?true:$errmsg);
	}

}

if ( (! isset($_POST['action']) ) || ( $_POST['action'] != "maj_profil") )
{

	// R&eacute;cup&eacute;ration des param&egrave;tres
	if ( isset($_GET['retour']) && $_GET['retour']!='' )
		{ $retour=addslashes( $_GET['retour'] ); } else { $retour='index.php'; }

	// Si le formulaire &agrave; &eacute;t&eacute; envoy&eacute;, on le traite ici
	if ( isset($_POST['envoi']) && $_POST['envoi'] === '1' )
	{
		if ( ! ( isset($_POST['loginP']) && isset($_POST['pass']) )  )
		{
			$errmsg = 'Param&egrave;tres incorrects';
		}
		else
		{
			require ('include/tools.inc.php');
			$ret=authentification(addslashes_if_needed($_POST['loginP']),addslashes_if_needed($_POST['pass']));

			//~ echo "DEBUG : \$ret==$ret\n";

			if ( $ret === true )
			{
				//Authentification r�ussie
				require('include/ludo/redir.inc.php');
				//~ echo "DEBUG : html_redir($retour);\n";
				html_redir($retour);
			}
			else
			{
				$errmsg = $ret;
			}
		}
	}
require_once('include/ludo/html_elements.inc.php');
generate_html_doctype_and_head("Identification");
?>
<body onload="javascript:document.forms['auth'].elements['loginP'].focus()">
<div id="titre"><h2>AWOR</h2></div>

<?php
generate_html_div_help();
?>
<div id="page_accueil">
	<h1>Application Web d'Organisation de R&eacute;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>
</div>
<?php if ( isset ($errmsg) ) { generate_html_div_errmsg($errmsg); }
generate_html_div_footer(); ?>
</body>
</html>
<?php
}
?>