Files
fdn2/app/public/mobile/registrationMobile.php
2022-08-29 23:20:16 +02:00

115 lines
3.8 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");
// ANTICIPATI PER NON PERDERLI IN CASO DI ERRORE
$email = trim(PostHandler::get("email"));
$obj->email = $email;
$username = trim(PostHandler::get("username"));
$obj->username = $username;
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("UserModel",array("email",$email)) > 0 ){
throw new GUIException("L'email inserita è già in uso ($email)");
}
// 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");
}
$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){
?>
<div class="modalBody">
<p>La tua registrazione è quasi completa!</p>
<p>A breve riceverai un'email all'indirizzo <br/><span style="font-weight:bold;"><?php echo $user->email;?></span><br/> per completare la registrazione</p>
</div>
<?php
}
else {
?>
<div class="modalBody">
<form id="regForm">
<div class="title">Inserisci i tuoi dati per registrarti al sito.</div>
<div style="color:red; text-align:center;font-size:12pt;"><?php echo $msg;?></div>
<input type="hidden" name="action" value=""/>
<div><input placeholder="NOME" type="text" name="nome" value="<?php echo $obj->nome;?>" /></div>
<div><input placeholder="COGNOME" type="text" name="cognome" value="<?php echo $obj->cognome;?>" /></div>
<div><input placeholder="EMAIL" type="text" name="email" value="<?php echo $obj->email;?>" /></div>
<div><input placeholder="USERNAME" type="text" name="username" value="<?php echo $obj->username;?>"/></div>
<div><input placeholder="PASSWORD" type="password" name="password" value="" /></div>
<div><input placeholder="CONFERMA PASSWORD" type="password" name="password_confirm" value="" /></div>
<div style="font-size:12pt;">Vuoi iscriverti alla newsletter? <input type="checkbox" name="newsletter" value="true" checked /></div>
<div class="btn" ><a class="btn" 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:'registrationMobile.php',
data:$("#regForm").serialize(),
success: function(data){
$(".loginData").html(data);
}
});
});
$('#regForm input[name=password_confirm]').keypress(function(event) {
if (event.which==13){
$("#regMe").click();
return false;
}
});
});
</script>
<?php
}
?>