create account

Artisan Update: Change Password, Account Closure, Password recovery and profile update by chri5h

View this thread on: hive.blogpeakd.comecency.com
· @chri5h ·
$0.11
Artisan Update: Change Password, Account Closure, Password recovery and profile update
### 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
- Users can recover their password if they loose it
- Users can now upload profile picture and create their username and provide their category for listing.

### 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.validate` script. 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. The `submitHandler:function()` gets the form name and scans through the form to get the fields name and their respective values.

  ```js
  submitHandler: function() {
  	//gets the form fields details
        var that = $('#delAcct'),
            url = that.attr('action'),
            type = that.attr('method'),
            data = {};
  	// scans and get the field name and values	
        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
        });
  	
  ```

  The snippet of the script that performs the account closure is shown below. The script confirms that the email provided posted to `$email` matches the account email which is posted to `$cmail` and then deletes the record using mysql `DELETE` syntax `DELETE FROM registration WHERE email=$email` from the database. Once its successful, the script echoes a statement which is sent back to the JS file for proper actions to be taken.


- <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 performs the same action as the closure button (validating the form based on the provided rules and sending the form details to the PHP script).

  But in this case the PHP script gets the form details from the JS file and pulls the password stored in the database using the user email

  ```
  $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;
  ```

  then verifies if the current password provided matches the one retrieved from the database using the PHP function `password_verify()` . If it is true, the new password is then hashed using password hash function `password_hash()` and then updating the users record with the new password 

  ```php
  $check_password = password_verify($curpassword, $retrieved_password);
  // once current password has been confirmed
  // hash new password and update record
  $hashPassord = password_hash($newpassword, PASSWORD_DEFAULT);
  ```

![delete and password update.gif](https://steemitimages.com/DQmanicxTgtFVDNaNBXJRCqthFmAXswe2M77Ww47A3oFinc/delete%20and%20password%20update.gif)

- <strong>FORGOT PASSWORD:</strong> As humans, it's likely possible for one to forget password. In order to recover your your account, we made provision for double authentication using the email address and phone number. Once they match our record in the database, the PHP script send a mail using the `mail()` to the email address with a new set of password  in numbers using `rand()`. The random password is then hashed and stored in the database for next login. The user might decide to change his password at will.

  ```php
  $random_password = rand(10000000000,99999999999);

  $password = password_hash($random_password, PASSWORD_DEFAULT);

  // send mail to email address
  $to = $email;
  $subject = 'Artisan Forget Password';
  $body = "Hi " .$email. ",\n\n
  We all forget our password most time, it's no big deal.\n\n
  Your new login details are: \n\n
  Email: " . $email ."\n\n
  Password: " . $random_password . "\n\n
  Please log in with the details provided. And do not reply this mail." ;

  mail($to, $subject, $body , 'noreply@artisan.com');

  echo "Recovery Password has been sent to email";
  ```

<center>![forgot password.gif](https://steemitimages.com/DQmTMPTUj52wEyRXU62biUeqUqiuwbYy257o8Ur9NjjHLdU/forgot%20password.gif)</center>

- <strong>PROFILE FOLIO UPDATE:</strong> To fully complete registration, artisans are required to select their category, username and a profile picture (for identification purposes). Once the information is filled into the form, they are sent to the PHP script for processing and update on the page. The image is processed in the upload.php script file. It first ensures that the file size to be uploaded is not more than the specified size. Then it moves the picture file to a folder on the server and creates a file name using the uploaded image name to store the path to the database for reference purpose.

  ```PHP
  if ($_FILES['file']['size'] > 0) {
    // if file submitted is greater than 0 it will run
    if ($_FILES['file']['size'] <= 253000000 ) {
      // if file submitted is less than 2.5mb it will run
      if (move_uploaded_file($_FILES['file']['tmp_name'], "userprof/".$_FILES['file']['name'])) {
        // file uploaded
        // checks to upload to file to our image folder
        // using javascript to return result to page
        $file_name = "userprof/".$_FILES['file']['name'];
  ```

  To update the profile picture immediately, the image path is passed into a JS function `updatepicture(pic)` with parameter already supplied in the PHP script. 

  ```PHP
  // this is passed in the upload.php script
  window.parent.updatepicture("<?php echo 'userprof/'.$_FILES['file']["name"]; ?>");

  <script type="text/javascript">
  	function updatepicture(image){
  		parent.document.getElementById("image").src = image;
  	}
  </script>
  ```

<center>![profile update.gif](https://steemitimages.com/DQmavoLaszy8v9X6iKdTs6dgCoEsbb81eJeP7277NRXsT9G/profile%20update.gif)</center>
  ​

### Commits on GitHub

- https://github.com/chrix95/artisan/commit/2b26c842aa6603d348d7ad532e8800f365866761
- https://github.com/chrix95/artisan/commit/a6dedd338287a7f0895c5a1b69acdb4ece9e67ff
- https://github.com/chrix95/artisan/commit/96b2603df6f9c0133e6e2ea772d8f667a38cf645
- https://github.com/chrix95/artisan/commit/355eaf41187d994d192da54f2a62dd3981e41695

### 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>
- <https://steemit.com/utopian-io/@chri5h/artisan-update-change-password-and-account-closure>

### 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-account-closure-password-recovery-and-profile-update
categoryutopian-io
json_metadata{"tags":["utopian-io","development","artisan","open-source"],"image":["https://steemitimages.com/DQmanicxTgtFVDNaNBXJRCqthFmAXswe2M77Ww47A3oFinc/delete%20and%20password%20update.gif","https://steemitimages.com/DQmTMPTUj52wEyRXU62biUeqUqiuwbYy257o8Ur9NjjHLdU/forgot%20password.gif","https://steemitimages.com/DQmavoLaszy8v9X6iKdTs6dgCoEsbb81eJeP7277NRXsT9G/profile%20update.gif"],"links":["https://github.com/chrix95/artisan","https://github.com/chrix95/artisan/commit/2b26c842aa6603d348d7ad532e8800f365866761","https://github.com/chrix95/artisan/commit/a6dedd338287a7f0895c5a1b69acdb4ece9e67ff","https://github.com/chrix95/artisan/commit/96b2603df6f9c0133e6e2ea772d8f667a38cf645","https://github.com/chrix95/artisan/commit/355eaf41187d994d192da54f2a62dd3981e41695","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","https://steemit.com/utopian-io/@chri5h/artisan-update-change-password-and-account-closure"],"app":"steemit/0.1","format":"markdown"}
created2018-05-12 01:42:24
last_update2018-05-12 01:42:24
depth0
children9
last_payout2018-05-19 01:42:24
cashout_time1969-12-31 23:59:59
total_payout_value0.093 HBD
curator_payout_value0.019 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,649
author_reputation2,291,303,072,819
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,213,756
net_rshares25,139,747,631
author_curate_reward""
vote details (9)
@amosbastian ·
Hi @chri5h, your contribution was unvoted because after a long discussion we decided that it's not really providing much value to the open source community. 

There have been a few similar projects popping up on Utopian that all have the same thing in common: they are basic websites that all need the same features added (log in, sign up, updating profile etc.) like this one [here](https://github.com/Raphaeludo/Hospital_Management_System). It's great that you are all (I think you know each other in real life) learning while developing, but until we feel your contributions are providing enough value to the open source community they won't be eligible for rewards.

---- 
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)
authoramosbastian
permlinkre-chri5h-artisan-update-change-password-account-closure-password-recovery-and-profile-update-20180516t104756581z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["chri5h"],"links":["https://github.com/Raphaeludo/Hospital_Management_System","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-05-16 10:47:57
last_update2018-05-16 10:47:57
depth1
children0
last_payout2018-05-23 10:47:57
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_length839
author_reputation174,473,586,900,705
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,988,224
net_rshares0
@codingdefined ·
Thank you for your contribution. It's nice to see you have started commenting on your code. Also it would be better if you can add more features into a single contribution.

Link to the Answers of the Questionnaire - 

[Click here](https://review.utopian.io/result/3/2322122)

---- 
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-account-closure-password-recovery-and-profile-update-20180513t123246654z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://review.utopian.io/result/3/2322122","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-05-13 12:32:45
last_update2018-05-13 12:32:45
depth1
children5
last_payout2018-05-20 12:32:45
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_length445
author_reputation529,116,176,659,350
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,456,968
net_rshares0
@chri5h ·
Thanks. I happy to have done the corrections you gave in my previous contribution. I will try my possible best to add more features jnto a single commit as u have said.
properties (22)
authorchri5h
permlinkre-codingdefined-re-chri5h-artisan-update-change-password-account-closure-password-recovery-and-profile-update-20180513t125139948z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-05-13 12:51:48
last_update2018-05-13 12:51:48
depth2
children4
last_payout2018-05-20 12:51:48
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_length168
author_reputation2,291,303,072,819
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,459,273
net_rshares0
@codingdefined ·
Not actually a single commit in the Github, but when you add a contribution to Utopian it would be nice to see more features in that contribution.
properties (22)
authorcodingdefined
permlinkre-chri5h-re-codingdefined-re-chri5h-artisan-update-change-password-account-closure-password-recovery-and-profile-update-20180513t132123989z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-05-13 13:21:24
last_update2018-05-13 13:21:24
depth3
children3
last_payout2018-05-20 13:21:24
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_length146
author_reputation529,116,176,659,350
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,462,840
net_rshares0
@timothy-mee ·
i like this and would love to contribute to this project.. Keep up the good work
👍  
properties (23)
authortimothy-mee
permlinkre-chri5h-artisan-update-change-password-account-closure-password-recovery-and-profile-update-20180515t092159435z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-05-15 09:22:00
last_update2018-05-15 09:22:00
depth1
children0
last_payout2018-05-22 09:22:00
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_length80
author_reputation4,101,677,399,196
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,792,159
net_rshares633,995,484
author_curate_reward""
vote details (1)
@utopian-io · (edited)
Hey @chri5h, your contribution was unvoted because we found out that it did not follow the [Utopian rules](https://join.utopian.io/rules).

 Upvote this comment to help Utopian grow its power and help other Open Source contributions like this one.

**Want to chat? Join us on [Discord](https://discord.gg/Pc8HG9x).**
properties (22)
authorutopian-io
permlinkre-artisan-update-change-password-account-closure-password-recovery-and-profile-update-20180513t184504z
categoryutopian-io
json_metadata"{"app": "beem/0.19.29"}"
created2018-05-13 18:45:06
last_update2018-05-16 10:30:12
depth1
children0
last_payout2018-05-20 18:45:06
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_length316
author_reputation152,955,367,999,756
root_title"Artisan Update: Change Password, Account Closure, Password recovery and profile update"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id55,507,067
net_rshares0