Kimai_Auth_Kimai::forgotPassword PHP Method

forgotPassword() public method

public forgotPassword ( string $name ) : string
$name string
return string
    public function forgotPassword($name)
    {
        $kga = $this->getKga();
        $database = $this->getDatabase();
        $is_customer = $database->is_customer_name($name);
        $mail = new Zend_Mail('utf-8');
        $mail->setFrom($kga['conf']['adminmail'], 'Kimai - Open Source Time Tracking');
        $mail->setSubject($kga['lang']['passwordReset']['mailSubject']);
        $transport = new Zend_Mail_Transport_Sendmail();
        $passwordResetHash = str_shuffle(MD5(microtime()));
        if ($is_customer) {
            $customerId = $database->customer_nameToID($name);
            $customer = $database->customer_get_data($customerId);
            $database->customer_edit($customerId, array('passwordResetHash' => $passwordResetHash));
            $mail->addTo($customer['mail']);
        } else {
            $userId = $database->user_name2id($name);
            $user = $database->user_get_data($userId);
            $database->user_edit($userId, array('passwordResetHash' => $passwordResetHash));
            $mail->addTo($user['mail']);
        }
        Kimai_Logger::logfile('password reset: ' . $name . ($is_customer ? ' as customer' : ' as user'));
        $ssl = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off';
        $url = ($ssl ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/forgotPassword.php?name=' . urlencode($name) . '&key=' . $passwordResetHash;
        $message = $kga['lang']['passwordReset']['mailMessage'];
        $message = str_replace('%{URL}', $url, $message);
        $mail->setBodyText($message);
        try {
            $mail->send($transport);
            return $kga['lang']['passwordReset']['mailConfirmation'];
        } catch (Zend_Mail_Transport_Exception $e) {
            return $e->getMessage();
        }
    }