Daniel Camargo 1f5b36ee15 Driver onboarding #2969
1) When creating an account as a driver, it should automatically add notifications using their phone number (assume they have a smart phone) and email
2) It should text them their username
3) I never received an email to nickhunter1991@gmail.com
4) When I accessed order 16844, I couldn't see the customer price total or subtotal
2014-05-27 18:59:11 -03:00

68 lines
1.9 KiB
PHP

<?php
class Controller_api_driver_setup extends Crunchbutton_Controller_Rest {
public function init() {
if( $this->method() == 'post' ) {
$id_admin = $this->request()[ 'id_admin' ];
$admin = Crunchbutton_Admin::o( $id_admin );
if( $admin->id_admin ){
$email = $this->request()[ 'email' ];
if( $email && trim( $email ) != '' ){
$admin->email = $email;
}
$admin->active = 1;
$admin->pass = $admin->makePass( $this->request()[ 'password' ] );
$admin->save();
$log = new Cockpit_Driver_Log();
$log->id_admin = $admin->id_admin;
$log->action = Cockpit_Driver_Log::ACTION_ACCOUNT_SETUP;
$log->info = $admin->login;
$log->datetime = date('Y-m-d H:i:s');
$log->save();
Log::debug( [ 'action' => 'driver setup finished', 'driver' => $admin->id_admin, 'type' => 'drivers-onboarding'] );
// Notify
Cockpit_Driver_Notify::send( $admin->id_admin, Cockpit_Driver_Notify::TYPE_SETUP );
echo json_encode( [ 'success' => $admin->exports() ] );
} else {
$this->_error();
}
} else {
$phone = c::getPagePiece( 3 );
if( $phone ){
$phone = preg_replace( '/[^0-9]/i', '', $phone );
$admin = Crunchbutton_Admin::getByPhoneSetup( $phone );
if( $admin->id_admin ){
Log::debug( [ 'action' => 'driver setup started', 'driver' => $admin->id_admin, 'phone' => $phone, 'type' => 'drivers-onboarding'] );
echo json_encode( [ 'success' => [ 'id_admin' => $admin->id_admin, 'hasEmail' => ( $admin->email && $admin->email != '' ) ? true : false ] ] );
} else {
Log::debug( [ 'action' => 'driver setup error', 'invalid phone' => $phone, 'type' => 'drivers-onboarding'] );
$this->_error( 'Invalid phone number' );
}
} else {
$this->_error();
}
}
}
private function _error( $error = 'invalid request' ){
echo json_encode( [ 'error' => $error ] );
exit();
}
}