[1.0.x] Register With OTP

Created on 18 April 2024, 5 months ago
Updated 20 August 2024, about 1 month ago

This module enables the OTP verification during user registration, preventing the creation of bot account on the site.

Project link

https://www.drupal.org/project/register_with_otp →

📌 Task
Status

Needs work

Component

module

Created by

🇮🇳India Vishal Prasad

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Vishal Prasad
  • 🇮🇳India vishal.kadam Mumbai

    Thank you for applying!

    Please read Review process for security advisory coverage: What to expect → for more details and Security advisory coverage application checklist → to understand what reviewers look for. Tips for ensuring a smooth review → gives some hints for a smoother review.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • For the time this application is open, only your commits are allowed.
    • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application and no other user will be able to opt projects into security advisory policy.
    • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

    To the reviewers

    Please read How to review security advisory coverage applications → , Application workflow → , What to cover in an application review → , and Tools to use for reviews → .

    The important notes are the following.

    • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
    • Reviewers should show the output of a CLI tool → only once per application.
    • It may be best to have the applicant fix things before further review.

    For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues → .

  • 🇮🇳India vishal.kadam Mumbai
  • 🇮🇳India vishal.kadam Mumbai

    Remember to change status, when the project is ready to be reviewed. In this queue, projects are only reviewed when the status is Needs review.

  • Status changed to Needs review 5 months ago
  • 🇮🇳India Vishal Prasad

    Hello @vishal.kadam I have made the required changes as per phpcs suggestions, you can now review the module.
    Thank you,

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work 5 months ago
  • 🇮🇳India vishal.kadam Mumbai

    1. FILE: register_with_otp.info.yml

    package: Custom

    This line is used by custom modules created for specific sites. It is not a package name used for projects hosted on drupal.org.

    2. FILE: register_with_otp.module

    /**
     * @file
     * Primary module hooks for register_with_otp module.
     */

    In Drupal, there are no primary and secondary hooks. The description for a .module file is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.

    3. FILE: register_with_otp.libraries.yml

    libraries/otp-fields.css: {}

    It is good practice to store .css files in the 'css' subfolder.

    4. FILE: libraries/otp-fields.css

    #otp-field-error, .email-error {
        color: red;
    }
    .email-message, .otp-success {
        color: rgb(3, 202, 3);
    }

    Line indented incorrectly. Use 2 spaces instead of 4.
    According to Drupal's CSS formatting guidelines → , each selector should be on a single line when a ruleset has a group of selectors separated by commas.

  • Status changed to Needs review 5 months ago
  • 🇮🇳India Vishal Prasad

    @vishal.kadam I have made these changes, please review.

  • 🇮🇳India vishal.kadam Mumbai

    I noticed that the CSS file is currently located in the 'libraries/css' folder instead of the recommended 'css' folder.

    Rest looks fine to me.

    Let’s wait for a Code Review Administrator to take a look and if everything goes fine, you will get the role.

  • 🇮🇳India Vishal Prasad

    @vishal.kadam i made the required changes.

  • Status changed to RTBC 5 months ago
  • 🇮🇳India vishal.kadam Mumbai
  • Status changed to Needs work 5 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
    • A specific point may just be an example and may apply in other places
    • A review is about code that doesn't follow the coding standards, contains possible security issue, or does not correctly use the Drupal API; the single points are not ordered, not even by importance

    src/Form/RegisterWithOtp.php

        if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
          $message = 'Email address is invalid.';
          $form['account']['mail']['#suffix'] = '<div class="email-error">' . $message . '</div>';
          $response->addCommand(new ReplaceCommand('#email-field', $form['account']['mail']));
        }
        elseif ($user) {
          $form['account']['mail']['#suffix'] = '<div class="email-error">Email is already taken</div>';
          $response->addCommand(new ReplaceCommand('#email-field', $form['account']['mail']));
        }
    

    Messages shown in the user interface must be translatable.

              $message = $this->sendOtpMail($otp, $data, $email, $timestamp, $session);
    
              if ($message) {
                $this->messenger()->addMessage($message);
              }
    

    The first argument passed to addMessage() must be a translatable string. $this->sendOtpMail() returns either a string concatenation or a Boolean value.

          $message = 'An OTP has been sent to your new email ' . $email;
          $this->logger('register_with_otp')->notice($this->t("A new OTP requested:") . $otp);
    

    The first argument passed to notice() must be a literal string.
    Notice that concatenating a translatable string with a variable is not correct too. Translatable strings use placeholders, which avoids to concatenate a translatable string with a dynamic value (which could cause security issues).

        catch (\Exception $e) {
          $this->logger('register_with_otp')->notice($e->getMessage());
          return FALSE;
        }
    

    To log an exception, there is watchdog_exception() or the alternative shown in that documentation page.

  • Status changed to Needs review 4 months ago
  • 🇮🇳India Vishal Prasad

    @apaderno I have made some changes for the translatable strings, can you please review it

    Thanks regards!

  • 🇮🇳India rushiraval

    I am changing the issue priority as per issue priorities → .

  • Status changed to Needs work about 2 months ago
  • 🇺🇸United States cmlara

    Is there a reason this module does not use the form alter API?

  • Status changed to Needs review about 2 months ago
  • 🇮🇳India Vishal Prasad

    @cmlara I thought of overriding the core's user entity form directly, as the hook form alter was getting way lengthy and also to follow the OOPs concept properly i avoided the form alter API.

  • 🇺🇸United States cmlara

    as the hook form alter was getting way lengthy and also to follow the OOPs concept properly i avoided the form alter API.

    I will note you could put significant portions of the logic in a service and from the hook call your service to process the data to primarily maintain OOP logic.

    What was your considerations when you evaluated the choices regarding multiple module compatibility?

  • 🇮🇳India Vishal Prasad

    @cmlara since my implementation is not changing the id of the main form so the form alter hooks from other modules are not ignored. and
    This also supports a more comprehensive approach

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The RegisterForm class is not part of the public API and it cannot be extended from a contributed module. (It is expressly marked @internal.)

    The form ID is public API. That is why contributed modules can implement hook_form_FORM_ID_alter() for forms implemented by Drupal core.

    @cmlara is correct when he says that hook_entity_type_alter() does not allow compatibility with other modules: The last module that would implement hook_entity_type_alter() and call $entity_types['user']->setFormClass('register', …) would not allow other modules to work, while hook_form_FORM_ID_alter() would not create such conflict.

  • 🇺🇸United States cmlara

    @vishal-prasad:

    I attempted to reach out to you via your corporate email around 0046 Friday (UTC).

  • Status changed to Needs work about 1 month ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India Vishal Prasad

    Hii @avpaderno i have reached out to @cmlara on drupal slack for the discussion about the proposed resolution, will find a solution for this soon and update the module.

Production build 0.71.5 2024