Add rider username and password to forms and database #119
This commit is contained in:
parent
6d38522125
commit
9e6ff4ee15
3 changed files with 107 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ use App\Ramcar\DayOfWeek;
|
||||||
use App\Entity\Rider;
|
use App\Entity\Rider;
|
||||||
use App\Entity\RiderSchedule;
|
use App\Entity\RiderSchedule;
|
||||||
use App\Entity\Hub;
|
use App\Entity\Hub;
|
||||||
|
use App\Entity\User;
|
||||||
use App\Service\FileUploader;
|
use App\Service\FileUploader;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
|
|
@ -14,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
|
|
@ -154,7 +156,8 @@ class RiderController extends BaseController
|
||||||
->setContactNumber($req->request->get('contact_no'))
|
->setContactNumber($req->request->get('contact_no'))
|
||||||
->setPlateNumber($req->request->get('plate_number'))
|
->setPlateNumber($req->request->get('plate_number'))
|
||||||
->setImageFile($req->request->get('image_file'))
|
->setImageFile($req->request->get('image_file'))
|
||||||
->setActive($req->request->get('flag_active') ? true : false);
|
->setActive($req->request->get('flag_active') ? true : false)
|
||||||
|
->setUsername($req->request->get('username'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator)
|
||||||
|
|
@ -176,6 +179,24 @@ class RiderController extends BaseController
|
||||||
// initialize error list
|
// initialize error list
|
||||||
$error_array = [];
|
$error_array = [];
|
||||||
|
|
||||||
|
// get password inputs
|
||||||
|
$password = $req->request->get('password');
|
||||||
|
$confirm_password = $req->request->get('confirm_password');
|
||||||
|
|
||||||
|
// custom validation for password fields
|
||||||
|
if (!$password) {
|
||||||
|
$error_array['password'] = 'This value should not be blank.';
|
||||||
|
} else if ($password != $confirm_password) {
|
||||||
|
$error_array['confirm_password'] = 'Passwords do not match.';
|
||||||
|
} else {
|
||||||
|
// encode password
|
||||||
|
$enc = $ef->getEncoder(new User());
|
||||||
|
$encoded_password = $enc->encodePassword($req->request->get('password'), '');
|
||||||
|
|
||||||
|
// set password
|
||||||
|
$obj->setPassword($encoded_password);
|
||||||
|
}
|
||||||
|
|
||||||
// custom validation for associations
|
// custom validation for associations
|
||||||
$hub_id = $req->request->get('hub');
|
$hub_id = $req->request->get('hub');
|
||||||
|
|
||||||
|
|
@ -303,6 +324,24 @@ class RiderController extends BaseController
|
||||||
// initialize error list
|
// initialize error list
|
||||||
$error_array = [];
|
$error_array = [];
|
||||||
|
|
||||||
|
// get password inputs
|
||||||
|
$password = $req->request->get('password');
|
||||||
|
$confirm_password = $req->request->get('confirm_password');
|
||||||
|
|
||||||
|
// custom validation for password fields
|
||||||
|
if ($password || $confirm_password) {
|
||||||
|
if ($password != $confirm_password) {
|
||||||
|
$error_array['confirm_password'] = 'Passwords do not match.';
|
||||||
|
} else {
|
||||||
|
// encode password
|
||||||
|
$enc = $ef->getEncoder(new User());
|
||||||
|
$encoded_password = $enc->encodePassword($req->request->get('password'), '');
|
||||||
|
|
||||||
|
// set password
|
||||||
|
$obj->setPassword($encoded_password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// custom validation for associations
|
// custom validation for associations
|
||||||
$hub_id = $req->request->get('hub');
|
$hub_id = $req->request->get('hub');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,18 @@ class Rider
|
||||||
*/
|
*/
|
||||||
protected $flag_active;
|
protected $flag_active;
|
||||||
|
|
||||||
|
// username for rider api
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=80, unique=true, nullable=true)
|
||||||
|
*/
|
||||||
|
protected $username;
|
||||||
|
|
||||||
|
// password for rider api
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=64)
|
||||||
|
*/
|
||||||
|
protected $password;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->job_orders = new ArrayCollection();
|
$this->job_orders = new ArrayCollection();
|
||||||
|
|
@ -99,6 +111,8 @@ class Rider
|
||||||
$this->curr_rating = 0;
|
$this->curr_rating = 0;
|
||||||
$this->flag_available = true;
|
$this->flag_available = true;
|
||||||
$this->flag_active = true;
|
$this->flag_active = true;
|
||||||
|
$this->username = null;
|
||||||
|
$this->password = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getID()
|
public function getID()
|
||||||
|
|
@ -253,4 +267,27 @@ class Rider
|
||||||
{
|
{
|
||||||
return $this->flag_active;
|
return $this->flag_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setUsername($username)
|
||||||
|
{
|
||||||
|
$this->username = $username;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsername()
|
||||||
|
{
|
||||||
|
return $this->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPassword($pass)
|
||||||
|
{
|
||||||
|
// they have to pass the encoded password
|
||||||
|
$this->password = $pass;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPassword()
|
||||||
|
{
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,36 @@
|
||||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('rider_update_submit', {'id': obj.getId()}) : url('rider_create_submit') }}">
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('rider_update_submit', {'id': obj.getId()}) : url('rider_create_submit') }}">
|
||||||
<div class="m-portlet__body">
|
<div class="m-portlet__body">
|
||||||
<div class="m-form__section m-form__section--first">
|
<div class="m-form__section m-form__section--first">
|
||||||
|
|
||||||
|
<div class="m-form__heading">
|
||||||
|
<h3 class="m-form__heading-title">
|
||||||
|
Rider App User
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="username">Username</label>
|
||||||
|
<input type="text" name="username" class="form-control m-input" value="{{ obj.getUsername() }}">
|
||||||
|
<div class="form-control-feedback hide" data-field="username"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="password">Password</label>
|
||||||
|
<input type="password" name="password" class="form-control m-input">
|
||||||
|
<div class="form-control-feedback hide" data-field="password"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group m-form__group row">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="confirm_password">Confirm Password</label>
|
||||||
|
<input type="password" name="confirm_password" class="form-control m-input">
|
||||||
|
<div class="form-control-feedback hide" data-field="confirm_password"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
||||||
|
<div class="m-form__section m-form__section">
|
||||||
<div class="m-form__heading">
|
<div class="m-form__heading">
|
||||||
<h3 class="m-form__heading-title">
|
<h3 class="m-form__heading-title">
|
||||||
Rider Details
|
Rider Details
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue