HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/gggg.komma.nl/vendor/komma/kms/src/Core/Attributes/SendPasswordMail.php
<?php
namespace Komma\KMS\Core\Attributes;

use Illuminate\Foundation\Auth\User as Authenticatable;

/**
 * Class SendPasswordMail
 *
 * Sends the user a mail to set or reset their password.
 * The set mail can contain a text in which the user is welcomed to the system and requested to set a password, before
 * he can use the system.
 * The reset mail can contain a text in which the user is instructed to reset his password in case he has forgotten it.
 *
 * @package Komma\KMS\Core\Attributes
 */
class SendPasswordMail extends Attribute
{
    /** @var Authenticatable */
    protected $authenticatable;

    protected int $type = PasswordMailTypes::RESET;

    protected ?int $getsValueFrom = Attribute::NonInteractiveAttribute;

    /**
     * SendPasswordMail constructor.
     *
     * @param Authenticatable $authenticatable
     * @param int             $type
     */
    public function __construct(Authenticatable $authenticatable, int $type)
    {
        $this->authenticatable = $authenticatable;
        parent::__construct();

        if(!PasswordMailTypes::isValidItem($type)) throw new \InvalidArgumentException('The given type is invalid. It must be one of the constants as defined in: '.PasswordMailTypes::class);
        $this->type = $type;
    }

    /**
     * Get the url the user will get in his email to reset his password
     */
    public function passwordUrl() {
        switch ($this->type) {
            case PasswordMailTypes::WELCOME:
                return route('kms_users.send_set_password_email');
            case PasswordMailTypes::RESET:
            default:
                return route('kms_users.send_reset_password_email');
        }
    }

    /**
     * Get the url the user will get in his email to reset his password
     */
    public function getExplanation() {
        switch ($this->type) {
            case PasswordMailTypes::WELCOME:
                return __('KMS::users.password_set_mail_explanation');
            case PasswordMailTypes::RESET:
            default:
                return __('KMS::users.password_reset_mail_explanation');
        }
    }

    private function getTestAttributeName()
    {
        switch ($this->type) {
            case PasswordMailTypes::WELCOME:
                return 'send_password_set_mail_button';
                break;
            case PasswordMailTypes::RESET:
            default:
                return 'send_password_reset_mail_button';
        }
    }

    /**
     * Get the url the user will get in his email to reset his password
     */
    public function getButtonText() {
        switch ($this->type) {
            case PasswordMailTypes::WELCOME:
                return __('KMS::users.send_password_set_mail');
                break;
            case PasswordMailTypes::RESET:
            default:
                return __('KMS::users.send_password_reset_mail');
        }
    }

    /**
     * Returns a view that visually represents this attribute
     *
     * @return string
     */
    public function render(): string
    {
        return view('KMS::attributes.sendPasswordMail', [
            'setPasswordUrl' => $this->passwordUrl(),
            'buttonText' => $this->getButtonText(),
            'explanation' => $this->getExplanation(),
            'dataAttributes' => $this->getDataAttributes(),
            'styleClass' => $this->getStyleClass(),
            'authenticatableId' => $this->authenticatable->id,
            'testAttributeName' => $this->getTestAttributeName(),
            'key' => $this->getKey()
        ])->render();
    }
}