create account

Artisan Update: Change Password and Account Closure by chri5h

View this thread on: hive.blogpeakd.comecency.com
· @chri5h ·
$0.14
Artisan Update: Change Password and Account Closure
### GitHub Repository: https://github.com/chrix95/artisan

### What is the project about?

Artisan tends to link clients who require the services of an artisan (example electrician, plumber, tailor e.t.c) for their various needs. We stand in the gap to provide the best of the best in the various fields to meet your expected result.

### How we operate?

Artisans register on the platform to get their information displayed on the search area for clients to view and request for their services.

On the other hand, the clients

- Select the time and date that's convenient enough for him/her and let us know (via the request form provided on the landing page)
- We confirm the appointment with our very best artisan for the job
- Upon job completion, we confirm that our clients are satisfied with the job offered

### New Features

- User account closure
- Users can now update their password from settings page

### How I implemented this features

- <strong>USER ACCOUNT CLOSURE:</strong>  Artisans that are registered on the platform can actually delete their account anytime they deem it necessary. I implemented this by first designing the delete button which on click provides a form for users email to be inserted

  ```js
  // gets a confirmation of account closure before actually deleting the account
    $('#apply .delBtn').click(function(){
      $('#apply').hide();
      $('#delAcct').show();
    });

    // terminates the closure of account process on button click
    $('.cancel').click(function(){
      $('#delAcct').hide();
      $('.email').val('');
      $('#apply').show();
    });
  ```

  Then once the email is entered, the information is sent to the php script using jquery validation. The snippet first verify that the form fields are correctly entered as required

  ```js
  // validates the form with this rules
  rules: {
        email: {
          required: true,
          email: true
        }
      },
  ```

  After validation is done, the information is sent to a script through the submit handler and response is sent back to the JS script for necessary actions.

  ```js
  submitHandler: function() {
  	//gets the form fields details
        var that = $('#delAcct'),
            url = that.attr('action'),
            type = that.attr('method'),
            data = {};
  	
        that.find('[name]').each(function(index, value){
            var that = $(this),
              name = that.attr('name'),
              value = that.val();

            data[name] = value; // stores the data as an array
        });
  	// sends the data to the script using ajax
        $.ajax({
          url: '../resources/script.php',
          type: 'POST',
          data: data
        })
  	// on completion, the necessary actions are taken
        .done(function(data){
          if (data == 'Account closure confirmed') {
            $('p#delmessage').css({
              "color":"#9C27B0",
              "font-size": "15px"
            });
            $('p#delmessage').text(data);
            setTimeout("window.location = 'logout.php'", 3000);
          } else if (data == 'Failed to close account') {
            $('p#delmessage').css({
              "color":"#9C27B0",
              "font-size": "15px"
            });
            $('p#delmessage').text(data);
            setTimeout("$('p#delmessage').text('')", 3000);
          } else if (data == 'Incorrect email provided') {
            $('p#delmessage').css({
              "color":"#9C27B0",
              "font-size": "15px"
            });
            $('p#delmessage').text(data);
            setTimeout("$('p#delmessage').text('')", 3000);
          }

        })
  	// on failure the error uis displayed in the console
        .fail(function(data){
          console.log("error encountered");
        });

      }
  ```

  The snippet of the script that performs the account closure is shown below. The script confirms that the email provided matches the account email and then deletes the record from the database and then logs out the user

  ```php
  if (isset($_POST['delAcct'])) {
        // get details from form
        $email = htmlentities(strip_tags(trim($_POST['email'])));
        $cmail = htmlentities(strip_tags(trim($_POST['cmail'])));

        // confirms if email provided matches the accounts email
        if ($email == $cmail) { // if the email matches
          // send details for account closure
          $delAcct = $conn->prepare("DELETE FROM registration WHERE email=:email");
          $delAcct->bindParam(":email", $email);
          $success = $delAcct->execute();

          // once the deletion process has been carried out
          if ($success) {
            echo "Account closure confirmed";
          } else {
            echo "Failed to close account";
          }

        } else { // if email doesn't matches
          echo "Incorrect email provided";
        }

      }
  ```



- <strong>PASSWORD UPDATE: </strong> The necessity may arise for a change or update of password. The artisan selects settings on his navigation section and fills the change password form and then clicks on the provided button. The button uses the jquery validation to confirm that all fields are entered correctly and the new password and confirm new password matches before sending to the PHP script.

  ```JS
  // validates the form with this rules
      rules: {
        curpass: {
          required: true
        },
        newpass: {
          required: true
        },
        conpass: {
          required: true,
          equalTo: '#newpass'
        }
      },
      submitHandler: function() {
        //gets the form fields details
        var that = $('#passUpdate'),
            url = that.attr('action'),
            type = that.attr('method'),
            data = {};

        that.find('[name]').each(function(index, value){
            var that = $(this),
              name = that.attr('name'),
              value = that.val();

            data[name] = value;  // stores the data as an array
        });
        // sends the data to the script using ajax
        $.ajax({
          url: '../resources/script.php', // script responsible for processing the information
          type: 'POST',
          data: data
        })
        // on completion, the necessary actions are taken
        .done(function(data){
          if (data == 'Password changed successfully') {
            $('p#message').css({
              "color":"#9C27B0",
              "font-size": "15px"
            });
            $('p#message').text(data);
            setTimeout("$('p#message').text('')", 3000);
          } else if (data == 'Password change failed') {

            $('p#message').css({
              "color":"#fff",
              "font-size": "15px"
            });
            $('p#message').text(data);
            setTimeout("$('p#message').text('')", 3000);
          } else if (data == 'Current password incorrect') {

            $('p#message').css("color", "red");
            $('p#message').text(data);
            console.log(data);
            setTimeout("$('p#message').text('')", 3000);
          }

        })
        // on failure the error uis displayed in the console
        .fail(function(data){
          console.log("error encountered");
        });

      }
  ```

  The php script gets the form details from the JS script and then verifies if the current password matches the one in the database before calling the password hash function `password_hash()` and then updating the record with the new password 

  ```
  if (isset($_POST['passupdate'])) {
        // get details from form
        $email	= htmlentities(strip_tags(trim($_POST['email'])));
        $curpassword = htmlentities(strip_tags(trim($_POST['curpass'])));
        $newpassword = htmlentities(strip_tags(trim($_POST['newpass'])));

        // confirm if the email exist
        $query_email = $conn->prepare("SELECT * FROM registration WHERE email=:email");
        $query_email->bindParam(":email", $email);
        $query_email->execute();
        // fetch password
        $get_details = $query_email->fetch(PDO::FETCH_OBJ);
        $retrieved_password = $get_details->password;

        $check_password = password_verify($curpassword, $retrieved_password);
        // once current password has been confirmed
        if ($check_password) {

          // hash new password and update record
          $hashPassord = password_hash($newpassword, PASSWORD_DEFAULT);
          $update_password = $conn->prepare("UPDATE registration SET password=:password WHERE email=:email");
          $update_password->bindParam(":password", $hashPassord);
          $update_password->bindParam(":email", $email);
          $success = $update_password->execute();

          // on success of password hashing and upadting
          if ($success) {

            echo "Password changed successfully";

          } else {

            echo "Password change failed";

          }

        } else {

          echo "Current password incorrect";

        }

      }
  ```

### Sample Video of implementation​

<center>![sample video.gif](https://steemitimages.com/DQmYW2BBU9HVg8144Bv5Ex5SWdyk4ykyey31NX63JkJNZLE/sample%20video.gif)</center>

### Commits on GitHub

- https://github.com/chrix95/artisan/commit/2b26c842aa6603d348d7ad532e8800f365866761
- https://github.com/chrix95/artisan/commit/a6dedd338287a7f0895c5a1b69acdb4ece9e67ff

### Previous Update

- <https://utopian.io/utopian-io/@chri5h/55dga9-artisans-bridging-the-gap-between-clients-and-artisans>
- <https://steemit.com/utopian-io/@chri5h/artisan-update-readme-contact-page-login-and-dashboard>

### How to contribute

- Fork the repo <https://github.com/chrix95/artisan>
- Create your feature branch
- Commit your changes
- Push to the branch:
- Submit a pull request.
👍  , , , , , ,
properties (23)
authorchri5h
permlinkartisan-update-change-password-and-account-closure
categoryutopian-io
json_metadata{"tags":["utopian-io","development","artisan","open-source"],"image":["https://steemitimages.com/DQmYW2BBU9HVg8144Bv5Ex5SWdyk4ykyey31NX63JkJNZLE/sample%20video.gif"],"links":["https://github.com/chrix95/artisan","https://github.com/chrix95/artisan/commit/2b26c842aa6603d348d7ad532e8800f365866761","https://github.com/chrix95/artisan/commit/a6dedd338287a7f0895c5a1b69acdb4ece9e67ff","https://utopian.io/utopian-io/@chri5h/55dga9-artisans-bridging-the-gap-between-clients-and-artisans","https://steemit.com/utopian-io/@chri5h/artisan-update-readme-contact-page-login-and-dashboard"],"app":"steemit/0.1","format":"markdown"}
created2018-05-08 12:17:30
last_update2018-05-08 12:17:30
depth0
children3
last_payout2018-05-15 12:17:30
cashout_time1969-12-31 23:59:59
total_payout_value0.127 HBD
curator_payout_value0.011 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9,822
author_reputation2,291,303,072,819
root_title"Artisan Update: Change Password and Account Closure"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id54,558,147
net_rshares29,204,073,410
author_curate_reward""
vote details (7)
@codingdefined ·
Thank you for your contribution. I feel the development effort is less on this contribution and would love to see more features in a single contribution. Also its better to write the logic rather than writing whole code in the post.

----------------------------------------------------------------------
Need help? Write a ticket on https://support.utopian.io.

Chat with us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://join.utopian.io)**
properties (22)
authorcodingdefined
permlinkre-chri5h-artisan-update-change-password-and-account-closure-20180509t113955172z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://support.utopian.io","https://discord.gg/uTyJkNm","https://join.utopian.io"],"app":"steemit/0.1"}
created2018-05-09 11:39:54
last_update2018-05-09 11:39:54
depth1
children1
last_payout2018-05-16 11:39:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length468
author_reputation528,937,085,127,963
root_title"Artisan Update: Change Password and Account Closure"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id54,737,635
net_rshares0
@chri5h ·
Thanks for the approval. I will effect the corrections in my next contribution. But I do hope I get upvoted for this contribution.
properties (22)
authorchri5h
permlinkre-codingdefined-re-chri5h-artisan-update-change-password-and-account-closure-20180509t115749354z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-05-09 11:57:51
last_update2018-05-09 11:57:51
depth2
children0
last_payout2018-05-16 11:57:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length130
author_reputation2,291,303,072,819
root_title"Artisan Update: Change Password and Account Closure"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id54,739,984
net_rshares0
@steemitboard ·
Congratulations @chri5h! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstcommented.png)](http://steemitboard.com/@chri5h) You got a First Reply

Click on any badge to view your own Board of Honor on SteemitBoard.

To support your work, I also upvoted your post!
For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard)

If you no longer want to receive notifications, reply to this comment with the word `STOP`

> Upvote this notification to help all Steemit users. Learn why [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-chri5h-20180508t174638000z
categoryutopian-io
json_metadata{"image":["https://steemitboard.com/img/notifications.png"]}
created2018-05-08 17:46:36
last_update2018-05-08 17:46:36
depth1
children0
last_payout2018-05-15 17:46:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length719
author_reputation38,975,615,169,260
root_title"Artisan Update: Change Password and Account Closure"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id54,609,111
net_rshares0