Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.54 KB | None | 0 0
  1. public function myAccount(Request $request, Response $response)
  2.     {
  3.  
  4.         $sentinel = new S($this->container);
  5.         $sentinel->hasPerm('user.account');
  6.  
  7.         $requestParams = $request->getParams();
  8.  
  9.         $user = $this->auth->check();
  10.         if ($request->isPost()) {
  11.  
  12.             $first_name = $requestParams['first_name'];
  13.             $last_name = $requestParams['last_name'];
  14.             $email = $requestParams['email'];
  15.             $username = $requestParams['username'];
  16.             $password = $requestParams['password'];
  17.             $password_confirm = $requestParams['password_confirm'];
  18.             $gender = $requestParams['gender'];
  19.             $title = $requestParams['title'];
  20.             $address_1 = $requestParams['address_1'];
  21.             $address_2 = $requestParams['address_2'];
  22.             $town = $requestParams['town'];
  23.             $postcode = $requestParams['postcode'];
  24.             $date_of_birth = $requestParams['date_of_birth'];
  25.             $home_phone = $requestParams['home_phone'];
  26.             $mobile_phone = $requestParams['mobile_phone'];
  27.             $next_kin = $requestParams['next_kin'];
  28.             $next_kin_relationship = $requestParams['next_kin_relationship'];
  29.             $next_kin_home_phone = $requestParams['next_kin_home_phone'];
  30.             $next_kin_mobile_phone = $requestParams['next_kin_mobile_phone'];
  31.             $doctors_name = $requestParams['doctors_name'];
  32.             $doctors_medication = $requestParams['doctors_medication'];
  33.             $doctors_injurys = $requestParams['doctors_injurys'];
  34.  
  35.             var_dump($_REQUEST);
  36.  
  37.             if (null !== $request->getParam('update_account')) {
  38.                 // Validate Data
  39.                 $validate_data = array(
  40.                     'first_name' => array(
  41.                         'rules' => V::length(2, 25)->alpha('\''),
  42.                         'messages' => array(
  43.                             'length' => 'Must be between 2 and 25 characters.',
  44.                             'alpha' => 'Letters only and can contain \''
  45.                         )
  46.                     ),
  47.                     'last_name' => array(
  48.                         'rules' => V::length(2, 25)->alpha('\''),
  49.                         'messages' => array(
  50.                             'length' => 'Must be between 2 and 25 characters.',
  51.                             'alpha' => 'Letters only and can contain \''
  52.                         )
  53.                     ),
  54.                     'email' => array(
  55.                         'rules' => V::noWhitespace()->email(),
  56.                         'messages' => array(
  57.                             'email' => 'Enter a valid email address.',
  58.                             'noWhitespace' => 'Must not contain any spaces.'
  59.                         )
  60.                     ),
  61.                     'username' => array(
  62.                         'rules' => V::noWhitespace()->alnum(),
  63.                         'messages' => array(
  64.                             'slug' => 'Must be alpha numeric with no spaces.',
  65.                             'noWhitespace' => 'Must not contain any spaces.'
  66.                         )
  67.                     ),
  68.                     'doctors_name' => array(
  69.                         'rules' => V::noWhitespace()->alnum(),
  70.                         'messages' => array(
  71.                             'slug' => 'Must be alpha numeric with no spaces.',
  72.                             'noWhitespace' => 'Must not contain any spaces.'
  73.                         )
  74.                     ),
  75.  
  76.                 );
  77.                 //Check username
  78.                 if ($user->username != $username) {
  79.                     $check_username = Users::where('id', '!=', $user->id)->where('username', '=', $username)->get()->count();
  80.                     if ($check_username > 0) {
  81.                         $this->validator->addError('username', 'Username is already in use.');
  82.                     }
  83.                 }
  84.  
  85.  
  86.                 //Check Email
  87.                 //if ($user->email != $email) {
  88.                 //    $check_email = Users::where('id', '!=', $user->id)->where('email', '=', $email)->get()->count();
  89.                 //    if ($check_email > 0) {
  90.                 //        $this->validator->addError('email', 'Email address is already in use.');
  91.                 //    }
  92.                 //}
  93.  
  94.                 $this->validator->validate($request, $validate_data);
  95.  
  96.                 if ($this->validator->isValid()) {
  97.  
  98.                     $new_information = [
  99.                         'first_name' => $first_name,
  100.                         'last_name' => $last_name,
  101.                         'email' => $email,
  102.                         'username' => $username,
  103.                         'gender' => $gender,
  104.                         'title' => $title,
  105.                         'address_1' => $address_1,
  106.                         'address_2' => $address_2,
  107.                         'town' => $town,
  108.                         'postcode' => $postcode,
  109.                         'date_of_birth' => $date_of_birth,
  110.                         'home_phone' => $home_phone,
  111.                         'mobile_phone' => $mobile_phone,
  112.                         'next_kin' => $next_kin,
  113.                         'next_kin_relationship' => $next_kin_relationship,
  114.                         'next_kin_home_phone' => $next_kin_home_phone,
  115.                         'next_kin_mobile_phone' => $next_kin_mobile_phone,
  116.                         'doctors_name' => $doctors_name,
  117.                         'doctors_medication' => $doctors_medication,
  118.                         'doctors_allergies' => $doctors_allergies,
  119.                         'doctors_injurys' => $doctors_injurys
  120.  
  121.  
  122.                     ];
  123.                     var_dump($new_information);
  124.  
  125.                     $update_user = $this->auth->update($user, $new_information);
  126.  
  127.                     if ($update_user) {
  128.                         $this->flash('success', 'Your account has been updated successfully.');
  129.                         $this->logger->addInfo("My Account: User successfully updated.", array("first_name" => $first_name, "last_name" => $last_name, "email" => $email, "username" => $username, "user_id" => $user->id, "doctors_name" => $user->doctors_name));
  130.                         return $this->redirect($response, 'my-account');
  131.                     } else {
  132.                         $this->flash('danger', 'There was an error updating your account information.');
  133.                         $this->logger->addInfo("My Account: An unknown error occured updating user.", array("first_name" => $first_name, "last_name" => $last_name, "email" => $email, "username" => $username, "user_id" => $user->id));
  134.                     }
  135.                 }
  136.             }
  137.  
  138.             if (null !== $request->getParam('change_password')) {
  139.                 // Validate Data
  140.                 $validate_data = array(
  141.                     'password' => array(
  142.                         'rules' => V::noWhitespace()->length(6, 25),
  143.                         'messages' => array(
  144.                             'length' => 'Must be between 6 and 25 characters.',
  145.                             'noWhitespace' => 'Must not contain any spaces.'
  146.                         )
  147.                     ),
  148.                     'password_confirm' => array(
  149.                         'rules' => V::equals($password),
  150.                         'messages' => array(
  151.                             'equals' => 'Passwords do not match.'
  152.                         )
  153.                     )
  154.                 );
  155.  
  156.                 $this->validator->validate($request, $validate_data);
  157.  
  158.                 if ($this->validator->isValid()) {
  159.  
  160.                     $new_information = [
  161.                         'password' => $password,
  162.                     ];
  163.  
  164.                     $update_user = $this->auth->update($user, $new_information);
  165.  
  166.                     if ($update_user) {
  167.                         $this->flash('success', 'Your password has been updated successfully.');
  168.                         $this->logger->addInfo("My Account: Password successfully changed", array("user_id" => $user->id));
  169.                         return $this->redirect($response, 'my-account');
  170.                     } else {
  171.                         $this->flash('danger', 'There was an error changing your password.');
  172.                         $this->logger->addInfo("My Account: An unknown error occured changing a password.", array("user_id" => $user->id));
  173.                     }
  174.                 }
  175.             }
  176.  
  177.         }
  178.  
  179.         return $this->view->render($response, 'my-account.twig', array("requestParams" => $requestParams));
  180.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement