pages/register.php

72 lines
2.4 KiB
PHP

<?php
include("./includes/header.php");
if($_SERVER['REQUEST_METHOD']=="POST"){
if($_POST['name']){
$username = filter_var($_POST['name'],FILTER_UNSAFE_RAW);
$username_reg = '/^[a-z_][a-z0-9_]{0,30}$/';
if(preg_match('/'.$username.':/',file_get_contents('/etc/passwd'))){
$err = "Username already exists!";
}
else if(!preg_match($username_reg,$username)){
$err = "Make sure you enter a valid username!";
}
else{
$success= true;
$success_msg= "Your registration request is submitted successfully! Please wait for an approval E-mail.";
}
}
if($success){
$file = fopen("/var/varsh/registrations/".$_POST['name'],"w");
$txt = $_POST['name'].','.$_POST['email'].','.$_POST['ssh'].','.$_POST['reason']."\n";
fwrite($file,$txt);
fclose($file);
}
}
?>
<main>
<p>So you want to be a part of tildevarsh?
<br>Go ahead, register.</p>
<p>The only thing that we ask for is <b>participation</b>.<br> As seen on the homepage, tildevarsh is more about the community and less about services. Please try to be active in the community. Unlike other tildes, your account will be deleted if you seem inactive for a long period of time. We plan to make this a vibrant community of like-minded people.</p>
<h3>Register</h3>
<form method="POST" action="">
<div class="container">
<div class="row">
<div class="col-6">Username: </div>
<div class="col-6"><input type="text" name="name" required/><br></div>
</div>
<br>
<div class="row">
<div class="col-6">Your email (Need one so we can contact you):</div>
<div class="col-6"> <input type="email" name="email" required/></div>
</div>
<br>
<div class="row">
<div class="col-6">Your <b>Public</b> SSH key(Need one so can login to the server):</div>
<div class="col-6"> <textarea name="ssh" rows="5" style="height:max-content; width:80%;" required></textarea></div>
</div>
<div class="row">
<div class="col-6">Why would you like to join tildevarsh? (Please try to write more than just one word):</div>
<div class="col-6"> <textarea name="reason" rows="5" style="height:max-content; width:80%;" required></textarea></div>
</div>
<br>
<div class="row">
<div class="col-6">
<input type="submit" value="Sign up"/>
</div>
<?php
if($err){?>
<div class="col-6 error"><?php echo $err ?></div>
<?php
}?>
<?php
if($success){?>
<div class="col-6 success"><?php echo $success_msg?></div>
<?php
}?>
</div>
</div>
</form>
<?php include("./includes/footer.php")?>