Advertisement
Guest User

ClientAuthController.php

a guest
Aug 11th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.21 KB | None | 0 0
  1. <?php namespace Modules\Clients\Http\Controllers;
  2.  
  3. use App\Client;
  4. use Illuminate\Http\Request;
  5. use Modules\Core\Http\Controllers\BasePublicController;
  6. use Illuminate\Support\Facades\Log;
  7. use Illuminate\Support\Facades\Redirect;
  8. use League\Flysystem\Exception;
  9. use Modules\Core\Contracts\Authentication;
  10. use Modules\Clients\Events\ClientHasBegunResetProcess;
  11. use Modules\Clients\Http\Requests\CreateClientRequest;
  12. use Modules\Clients\Http\Requests\UpdateClientRequest;
  13. use Illuminate\Support\Facades\Input;
  14. use Illuminate\Support\Facades\Auth;
  15. use Illuminate\Support\Facades\Validator;
  16.  
  17. class ClientAuthController extends BasePublicController
  18. {
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.  
  23.     }
  24.  
  25.     /**
  26.      * Create a client account from given form data.
  27.      *
  28.      * @param Request $request
  29.      * @return Response
  30.      */
  31.     public function register(Request $request)
  32.     {
  33.         Log::info('Entered Register Function');
  34.         $clientData = [
  35.             'title'             =>  Input::get('title'),
  36.             'forename'          =>  Input::get('forename'),
  37.             'surname'           =>  Input::get('surname'),
  38.             'email'             =>  Input::get('email'),
  39.             'telephone'         =>  Input::get('telephone'),
  40.             'mobile'            =>  Input::get('mobile'),
  41.             'company'           =>  Input::get('company'),
  42.             'department'        =>  Input::get('department'),
  43.             'position'          =>  Input::get('position'),
  44.             'company_address'   =>  Input::get('company_address'),
  45.             'company_postcode'  =>  Input::get('company_postcode'),
  46.             'invoice_address'   =>  Input::get('invoice_address'),
  47.             'invoice_postcode'  =>  Input::get('invoice_postcode'),
  48.             'budget_code'       =>  Input::get('budget_code'),
  49.             'password'          =>  Input::get('password')
  50.         ];
  51.  
  52.         $validator = Validator::make($clientData, [
  53.             'title'             =>  'required|max:255',
  54.             'forename'          =>  'required|max:255',
  55.             'surname'           =>  'required|max:255',
  56.             'email'             =>  'required|email|max:255|confirmed|unique:clients',
  57.             'telephone'         =>  'required|numeric|min:11|max:14',
  58.             'company'           =>  'required|max:255',
  59.             'company_address'   =>  'required',
  60.             'company_postcode'  =>  'required|max:10',
  61.             'invoice_address'   =>  'required',
  62.             'invoice_postcode'  =>  'required|max:10',
  63.             'password'          =>  'required|min:5|confirmed'
  64.         ]);
  65.  
  66.         if($validator->fails())
  67.         {
  68.             return Redirect::back()->withErrors($validator)->withInput();
  69.         }else{
  70.             try {
  71.                 $client = Client::create([
  72.                     'title'             =>  $clientData['title'],
  73.                     'forename'          =>  $clientData['forename'],
  74.                     'surname'           =>  $clientData['surname'],
  75.                     'email'             =>  $clientData['email'],
  76.                     'telephone'         =>  $clientData['telephone'],
  77.                     'mobile'            =>  $clientData['mobile'],
  78.                     'company'           =>  $clientData['company'],
  79.                     'department'        =>  $clientData['department'],
  80.                     'position'          =>  $clientData['position'],
  81.                     'company_address'   =>  $clientData['company_address'],
  82.                     'company_postcode'  =>  $clientData['company_postcode'],
  83.                     'invoice_address'   =>  $clientData['invoice_address'],
  84.                     'invoice_postcode'  =>  $clientData['invoice_postcode'],
  85.                     'budget_code'       =>  $clientData['budget_code'],
  86.                     'password'          =>  bcrypt($clientData['password'])
  87.                 ]);
  88.  
  89.                 return redirect('/client/register/successful')->with('success', trans('client::frontend.register.success'));
  90.             }catch(Exception $e)
  91.             {
  92.                 return Redirect::back()->with('error', trans('client::frontend.register.error'));
  93.             }
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement