ba1cec254fe382717a810ab81b297d5603017268
[smail.git/.git] / mailbox / new_user.php
1 <?php include '../i18n.class.php'; $i18n = new i18n('../lang/lang_{LANGUAGE}.ini'); $i18n->init();?>
2 <?php
3
4 include '../api/server_info.php';
5
6 if (isset($_POST['mail']) and isset($_POST['password'])){
7     $conn=mysqli_connect($db_link,$db_user,$db_password,$db_name);
8     $selfUrl=$_SERVER['HTTP_HOST'].preg_replace('/mailbox\/new_user.php/','',$_SERVER['PHP_SELF']);
9     $query=mysqli_query($conn,'SELECT mail_user FROM mail WHERE mail_user="'.$_POST['mail'].'@'.$selfUrl.'"');
10     print_r($query);
11     if (mysqli_connect_error()){
12         http_response_code(500);
13     }
14     elseif (mysqli_num_rows($query)==0){
15         mkdir($_POST['mail']);
16         mkdir($_POST['mail'].'/mails');
17         mkdir($_POST['mail'].'/readed');
18         $query=mysqli_query($conn,'INSERT INTO mail(mail_user,mail_password) VALUES("'.$_POST['mail']."@".$selfUrl.'","'.password_hash($_POST['password'],PASSWORD_DEFAULT).'")');
19         header('Location: ../login.php?info=<text>'.L::new_user.' '.$_POST['mail'].'@'.$selfUrl.'</text>');
20     }
21     else{
22         header('Location: ../new_user.php?info=<text>'.L::new_already.' '.$_POST['mail'].'@'.$selfUrl.'</text>');
23     }
24 }
25 else{
26     header('Location: ../index.php');
27 }
28 ?>