Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function myAccount(Request $request, Response $response)
- {
- $sentinel = new S($this->container);
- $sentinel->hasPerm('user.account');
- $requestParams = $request->getParams();
- $user = $this->auth->check();
- if ($request->isPost()) {
- $first_name = $requestParams['first_name'];
- $last_name = $requestParams['last_name'];
- $email = $requestParams['email'];
- $username = $requestParams['username'];
- $password = $requestParams['password'];
- $password_confirm = $requestParams['password_confirm'];
- $gender = $requestParams['gender'];
- $title = $requestParams['title'];
- $address_1 = $requestParams['address_1'];
- $address_2 = $requestParams['address_2'];
- $town = $requestParams['town'];
- $postcode = $requestParams['postcode'];
- $date_of_birth = $requestParams['date_of_birth'];
- $home_phone = $requestParams['home_phone'];
- $mobile_phone = $requestParams['mobile_phone'];
- $next_kin = $requestParams['next_kin'];
- $next_kin_relationship = $requestParams['next_kin_relationship'];
- $next_kin_home_phone = $requestParams['next_kin_home_phone'];
- $next_kin_mobile_phone = $requestParams['next_kin_mobile_phone'];
- $doctors_name = $requestParams['doctors_name'];
- $doctors_medication = $requestParams['doctors_medication'];
- $doctors_injurys = $requestParams['doctors_injurys'];
- var_dump($_REQUEST);
- if (null !== $request->getParam('update_account')) {
- // Validate Data
- $validate_data = array(
- 'first_name' => array(
- 'rules' => V::length(2, 25)->alpha('\''),
- 'messages' => array(
- 'length' => 'Must be between 2 and 25 characters.',
- 'alpha' => 'Letters only and can contain \''
- )
- ),
- 'last_name' => array(
- 'rules' => V::length(2, 25)->alpha('\''),
- 'messages' => array(
- 'length' => 'Must be between 2 and 25 characters.',
- 'alpha' => 'Letters only and can contain \''
- )
- ),
- 'email' => array(
- 'rules' => V::noWhitespace()->email(),
- 'messages' => array(
- 'email' => 'Enter a valid email address.',
- 'noWhitespace' => 'Must not contain any spaces.'
- )
- ),
- 'username' => array(
- 'rules' => V::noWhitespace()->alnum(),
- 'messages' => array(
- 'slug' => 'Must be alpha numeric with no spaces.',
- 'noWhitespace' => 'Must not contain any spaces.'
- )
- ),
- 'doctors_name' => array(
- 'rules' => V::noWhitespace()->alnum(),
- 'messages' => array(
- 'slug' => 'Must be alpha numeric with no spaces.',
- 'noWhitespace' => 'Must not contain any spaces.'
- )
- ),
- );
- //Check username
- if ($user->username != $username) {
- $check_username = Users::where('id', '!=', $user->id)->where('username', '=', $username)->get()->count();
- if ($check_username > 0) {
- $this->validator->addError('username', 'Username is already in use.');
- }
- }
- //Check Email
- //if ($user->email != $email) {
- // $check_email = Users::where('id', '!=', $user->id)->where('email', '=', $email)->get()->count();
- // if ($check_email > 0) {
- // $this->validator->addError('email', 'Email address is already in use.');
- // }
- //}
- $this->validator->validate($request, $validate_data);
- if ($this->validator->isValid()) {
- $new_information = [
- 'first_name' => $first_name,
- 'last_name' => $last_name,
- 'email' => $email,
- 'username' => $username,
- 'gender' => $gender,
- 'title' => $title,
- 'address_1' => $address_1,
- 'address_2' => $address_2,
- 'town' => $town,
- 'postcode' => $postcode,
- 'date_of_birth' => $date_of_birth,
- 'home_phone' => $home_phone,
- 'mobile_phone' => $mobile_phone,
- 'next_kin' => $next_kin,
- 'next_kin_relationship' => $next_kin_relationship,
- 'next_kin_home_phone' => $next_kin_home_phone,
- 'next_kin_mobile_phone' => $next_kin_mobile_phone,
- 'doctors_name' => $doctors_name,
- 'doctors_medication' => $doctors_medication,
- 'doctors_allergies' => $doctors_allergies,
- 'doctors_injurys' => $doctors_injurys
- ];
- var_dump($new_information);
- $update_user = $this->auth->update($user, $new_information);
- if ($update_user) {
- $this->flash('success', 'Your account has been updated successfully.');
- $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));
- return $this->redirect($response, 'my-account');
- } else {
- $this->flash('danger', 'There was an error updating your account information.');
- $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));
- }
- }
- }
- if (null !== $request->getParam('change_password')) {
- // Validate Data
- $validate_data = array(
- 'password' => array(
- 'rules' => V::noWhitespace()->length(6, 25),
- 'messages' => array(
- 'length' => 'Must be between 6 and 25 characters.',
- 'noWhitespace' => 'Must not contain any spaces.'
- )
- ),
- 'password_confirm' => array(
- 'rules' => V::equals($password),
- 'messages' => array(
- 'equals' => 'Passwords do not match.'
- )
- )
- );
- $this->validator->validate($request, $validate_data);
- if ($this->validator->isValid()) {
- $new_information = [
- 'password' => $password,
- ];
- $update_user = $this->auth->update($user, $new_information);
- if ($update_user) {
- $this->flash('success', 'Your password has been updated successfully.');
- $this->logger->addInfo("My Account: Password successfully changed", array("user_id" => $user->id));
- return $this->redirect($response, 'my-account');
- } else {
- $this->flash('danger', 'There was an error changing your password.');
- $this->logger->addInfo("My Account: An unknown error occured changing a password.", array("user_id" => $user->id));
- }
- }
- }
- }
- return $this->view->render($response, 'my-account.twig', array("requestParams" => $requestParams));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement