From dea73fb2a6bcc675773e91a0ec7033b4375df8c1 Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Tue, 18 Jul 2023 09:51:43 +0700
Subject: [PATCH] Add email in registration form

---
 system/controllers/register.php | 12 +++++++++++-
 ui/ui/register-otp.tpl          |  5 +++++
 ui/ui/register-rotp.tpl         |  6 +++---
 ui/ui/register.tpl              | 32 ++++++++++++++++++++------------
 4 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/system/controllers/register.php b/system/controllers/register.php
index f554be4d..5f41f97f 100644
--- a/system/controllers/register.php
+++ b/system/controllers/register.php
@@ -20,12 +20,15 @@ switch ($do) {
     case 'post':
         $otp_code = _post('otp_code');
         $username = alphanumeric(_post('username'),"+_.");
+        $email = _post('email');
         $fullname = _post('fullname');
         $password = _post('password');
         $cpassword = _post('cpassword');
         $address = _post('address');
         if(!empty($config['sms_url'])){
             $phonenumber = $username;
+        }else if(strlen($username)<21){
+            $phonenumber = $username;
         }
         $msg = '';
         if (Validator::Length($username, 35, 2) == false) {
@@ -37,6 +40,9 @@ switch ($do) {
         if (!Validator::Length($password, 35, 2)) {
             $msg .= 'Password should be between 3 to 35 characters' . '<br>';
         }
+        if (!Validator::Email($email)) {
+            $msg .= 'Email is not Valid<br>';
+        }
         if ($password != $cpassword) {
             $msg .= $_L['PasswordsNotMatch'] . '<br>';
         }
@@ -53,6 +59,7 @@ switch ($do) {
                     $ui->assign('username', $username);
                     $ui->assign('fullname', $fullname);
                     $ui->assign('address', $address);
+                    $ui->assign('email', $email);
                     $ui->assign('phonenumber', $phonenumber);
                     $ui->assign('notify', '<div class="alert alert-success">
                     <button type="button" class="close" data-dismiss="alert">
@@ -79,7 +86,7 @@ switch ($do) {
             $d->password = $password;
             $d->fullname = $fullname;
             $d->address = $address;
-            $d->email = '';
+            $d->email = $email;
             $d->phonenumber = $phonenumber;
             if ($d->save()) {
                 $user = $d->id();
@@ -88,6 +95,7 @@ switch ($do) {
                 $ui->assign('username', $username);
                 $ui->assign('fullname', $fullname);
                 $ui->assign('address', $address);
+                $ui->assign('email', $email);
                 $ui->assign('phonenumber', $phonenumber);
                 $ui->assign('notify', '<div class="alert alert-danger">
                 <button type="button" class="close" data-dismiss="alert">
@@ -101,6 +109,7 @@ switch ($do) {
             $ui->assign('username', $username);
             $ui->assign('fullname', $fullname);
             $ui->assign('address', $address);
+            $ui->assign('email', $email);
             $ui->assign('phonenumber', $phonenumber);
             $ui->assign('notify', '<div class="alert alert-danger">
             <button type="button" class="close" data-dismiss="alert">
@@ -152,6 +161,7 @@ switch ($do) {
             $ui->assign('username', "");
             $ui->assign('fullname', "");
             $ui->assign('address', "");
+            $ui->assign('email', "");
             $ui->assign('otp', false);
             run_hook('view_register'); #HOOK
             $ui->display('register.tpl');
diff --git a/ui/ui/register-otp.tpl b/ui/ui/register-otp.tpl
index 917f1023..49896d18 100644
--- a/ui/ui/register-otp.tpl
+++ b/ui/ui/register-otp.tpl
@@ -58,6 +58,11 @@
                                     <input type="text" required class="form-control" id="fullname" value="{$fullname}"
                                         name="fullname">
                                 </div>
+                                <div class="form-group">
+                                    <label>{$_L['Email']}</label>
+                                    <input type="text" required class="form-control" placeholder="xxxxxx@xxx.xx" id="email" value="{$email}"
+                                        name="email">
+                                </div>
                                 <div class="form-group">
                                 <label>{$_L['Address']}</label>
                                     <input type="text" name="address" id="address" value="{$address}" class="form-control">
diff --git a/ui/ui/register-rotp.tpl b/ui/ui/register-rotp.tpl
index d01cca02..a9a99e6c 100644
--- a/ui/ui/register-rotp.tpl
+++ b/ui/ui/register-rotp.tpl
@@ -63,11 +63,11 @@
                             </div>
                             <div class="btn-group btn-group-justified mb15">
                                 <div class="btn-group">
-                                    <button class="btn btn-primary waves-effect waves-light"
-                                        type="submit">{Lang::T('Request OTP')}</button>
+                                    <a href="{$_url}login" class="btn btn-warning">{$_L['Cancel']}</a>
                                 </div>
                                 <div class="btn-group">
-                                    <a href="{$_url}login" class="btn btn-success">{$_L['Cancel']}</a>
+                                    <button class="btn btn-success waves-effect waves-light"
+                                        type="submit">{Lang::T('Request OTP')}</button>
                                 </div>
                             </div>
                         </div>
diff --git a/ui/ui/register.tpl b/ui/ui/register.tpl
index 8e88d9d1..849c1c01 100644
--- a/ui/ui/register.tpl
+++ b/ui/ui/register.tpl
@@ -43,19 +43,25 @@
                         <div class="panel-heading">1. {$_L['Register_Member']}</div>
                         <div class="panel-body">
                             <div class="form-container">
-                                <div class="md-input-container md-float-label">
-                                    <input type="text" required class="md-input" id="username" value="{$username}"
-                                        placeholder="{$_L['Phone_Number']}" name="username">
+                                <div class="md-input-container">
                                     <label>{$_L['Phone_Number']}</label>
+                                    <input type="text" required class="form-control" id="username" value="{$username}"
+                                        placeholder="{$_L['Phone_Number']}" name="username">
                                 </div>
                                 <div class="md-input-container md-float-label">
-                                    <input type="text" required class="md-input" id="fullname" value="{$fullname}"
-                                        name="fullname">
                                     <label>{$_L['Full_Name']}</label>
+                                    <input type="text" required class="form-control" id="fullname" value="{$fullname}"
+                                        name="fullname">
+                                </div>
+                                <div class="md-input-container md-float-label">
+                                    <label>{$_L['Email']}</label>
+                                    <input type="text" required class="form-control" id="email"
+                                        placeholder="xxxxxxx@xxxx.xx" value="{$email}" name="email">
                                 </div>
                                 <div class="md-input-container md-float-label">
-                                    <input type="text" name="address" id="address" value="{$address}" class="md-input">
                                     <label>{$_L['Address']}</label>
+                                    <input type="text" name="address" id="address" value="{$address}"
+                                        class="form-control">
                                 </div>
                             </div>
                         </div>
@@ -67,21 +73,23 @@
                         <div class="panel-body">
                             <div class="form-container">
                                 <div class="md-input-container md-float-label">
-                                    <input type="password" required class="md-input" id="password" name="password">
                                     <label>{$_L['Password']}</label>
+                                    <input type="password" required class="form-control" id="password" name="password">
                                 </div>
                                 <div class="md-input-container md-float-label">
-                                    <input type="password" required class="md-input" id="cpassword" name="cpassword">
                                     <label>{$_L['Confirm_Password']}</label>
+                                    <input type="password" required class="form-control" id="cpassword"
+                                        name="cpassword">
                                 </div>
+                                <br>
                                 <div class="btn-group btn-group-justified mb15">
+                                <div class="btn-group">
+                                    <a href="{$_url}login" class="btn btn-warning">{$_L['Cancel']}</a>
+                                </div>
                                     <div class="btn-group">
-                                        <button class="btn btn-primary waves-effect waves-light"
+                                        <button class="btn btn-success waves-effect waves-light"
                                             type="submit">{$_L['Register']}</button>
                                     </div>
-                                    <div class="btn-group">
-                                        <a href="{$_url}login" class="btn btn-success">{$_L['Cancel']}</a>
-                                    </div>
                                 </div>
                             </div>
                         </div>