Files
fdn2/public/registration.php
T
Riccardo Di Dato 2761b9e69a Completato sistema di registrazione e di login (Senza grafica);
Completato sistema di banner e rotazioni
Inserito sistema per ricerca full text
2016-03-11 20:15:14 +01:00

102 lines
3.2 KiB
PHP

<?php
require_once(dirname(__FILE__)."/load.php");
try {
$msg = "";
$saved = false;
$action = PostHandler::get("action");
if (!is_null($action) && strcmp($action, "save")==0){
$obj = new stdClass();
$obj->nome = PostHandler::get("nome");
$obj->cognome = PostHandler::get("cognome");
$email = trim(PostHandler::get("email"));
if (is_null($email) || !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/",$email)){
throw new GUIException("L'email inserita non è in un formato valido ($email)");
}
if (GlobalVariables::get("dao")->count("AdminModel",array("email",$email)) > 0 ){
throw new GUIException("L'email inserita è già in uso ($email)");
}
$obj->email = $email;
$username = trim(PostHandler::get("username"));
// Validate Username
if (is_null($username) || strcmp($username,"")==0){
throw new GUIException("Inserire un nome utente valido");
}
if (GlobalVariables::get("dao")->count("UserModel",array("username"=>$username ) ) > 0 ){
throw new GUIException("Il nome utente '".$username."' è già in uso");
}
$obj->username = $username;
$pass = trim(PostHandler::get("password"));
$passConf = trim(PostHandler::get("password_confirm"));
if (is_null($pass) || strcmp($pass,"")==0){
throw new GUIException("Inserire una password");
}
if (strcmp($pass,$passConf)!=0){
throw new GUIException("Le password inserite non coincidono");
}
$obj->password = sha1($pass);
$obj->newsletter = false;
$news = PostHandler::get("newsletter");
if (!is_null($news) && strcasecmp("true", $news)){
$obj->newsletter = true;
}
$user = new UserModel($obj);
GlobalVariables::get("dao")->save($user);
$saved = true;
}
}catch(GUIException $ex){
$msg = $ex->getMessage();
$err = true;
}catch (Exception $exec){
$msg = LogModel::fromException($exec);
GlobalVariables::get("dao")->save($msg);
}
if ($saved){
echo "Registrazione avvenuta con successo";
}
else {
?>
<div class="topReg"><span></span><div><a class="close" href="javascript:void(0);" onClick="$('#floating').hide();">x</a></div></div>
<div style="color:red;"><?php echo $msg;?></div>
<div class="modalBody">
<form id="regForm">
<input type="hidden" name="action" value=""/>
<div>Nome: <input type="text" name="nome" value="" /></div>
<div>Cognome: <input type="text" name="cognome" value="" /></div>
<div>Email: <input type="text" name="email" value="" /></div>
<div>Username: <input type="text" name="username" value=""/></div>
<div>Password: <input type="password" name="password" value="" /></div>
<div>Conferma password: <input type="password" name="password_confirm" value="" /></div>
<div>Vuoi iscriverti alla newsletter? <input type="checkbox" name="newsletter" value="true" checked /></div>
<div ><a id="regMe" href="javascript:void(0);">Registrami</a></div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#regMe").click(function () {
$("#regForm input[name=action]").val("save");
$.ajax({
method:"POST",
url:'registration.php',
data:$("#regForm").serialize(),
success: function(data){
$("#floating").html(data);
}
});
});
});
</script>
<?php
}
?>