Skip to content

Instantly share code, notes, and snippets.

@Bonveio
Last active November 2, 2020 01:51
Show Gist options
  • Select an option

  • Save Bonveio/b1c83ef9349dda8a801956de52a55a67 to your computer and use it in GitHub Desktop.

Select an option

Save Bonveio/b1c83ef9349dda8a801956de52a55a67 to your computer and use it in GitHub Desktop.
OCS Panel guest user registration
# Copyright (c) BonvScripts
# Author: Bonveio Abitona
RouteConf='/home/panel/html/config/route.php'
RegisterPHP='/home/panel/html/controller/register.php'
RegisterHTML='/home/panel/html/view/register.html'
if [[ "$(grep -c 'register' ${RouteConf})" -gt 1 ]]; then
sed -i "/^.*\/register.*$/d" "${RouteConf}"
fi
sed -i "/\[routes\]/aGET \/register=Register-\>In\nPOST \/register=Register-\>Post" "${RouteConf}";
cat <<'EOF' > "${RegisterHTML}"
<style type="text/css">
a:link { text-decoration: none; }
</style>
<div id="content" class="content">
<h1 class="page-header"> Registration </h1>
<check if="{{ @message }}">
<div class="alert alert-{{ @message['type'] }}"> {{ @message['data'] }} </div>
</check>
<div class="row">
<div class="col-lg-12">
<div class="panel blue-gradient">
<div class="panel-heading">
<h4 class="panel-title text-white"> Register </h4>
</div>
<div class="panel-body bg-white text-black">
<form role="form" action="{{ @URI }}" method="POST">
<div class="form-group">
<label>First name</label>
<input class="form-control" placeholder="First name" name="firstname" type="text" required>
</div>
<div class="form-group">
<label>Last name</label>
<input class="form-control" placeholder="Last name" name="lastname" type="text" required>
</div>
<div class="form-group">
<label>Username</label>
<input class="form-control" placeholder="Username" name="username" type="text" required>
</div>
<div class="form-group">
<label>Password</label>
<input class="form-control" placeholder="New Password" name="password" type="password" required>
</div>
<div class="form-group">
<label>Email</label>
<input class="form-control" placeholder="Email" name="email" type="text" required>
</div>
<div align="right">
<button type="submit" class="btn btn-primary text-white">Create</button>
<a href="/home" class="btn btn-default text-white">Back</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
EOF
cat <<'EOF' > "${RegisterPHP}"
<?php
class Register extends Controller {
function In($f3) {
if ($f3->exists('SESSION.id')) {
$f3->reroute('/home');
}
$f3->set('content','register.html');
}
function Post($f3) {
$f3 = \Base::instance();
$user = new \User;
$user->load(array('username=?',$f3->get('POST.username')));
if ( ! $user->dry()) {
$this->flash('User Already registered');
$f3->reroute('/register');
}
$user->copyFrom('POST');
$user->id = $f3->get('PARAMS.id');
$user->saldo = 0;
$user->type = 2;
$user->save();
$this->flash('You are now registered, go back to login page now','success');
$f3->reroute('/register');
$f3->clear('SESSION');
}
}
EOF
### then make registration form appearable into login page
## if you're using OceanVPN ocs source:
## just edit /home/panel/html/view/login.html
## then find:
# <!-- end login-content -->
## Below at it, insert these html code
# <div align="center"><p><small class="text-black">No account? <a href="register">Create here</a></small></p></div>
## then save
##
## Re-read register.php on your controller folder
## if you want some value/data modifications (like edit default registration balance[0] and usertype; 1 is for admin, 2 is for seller/user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment