Skip to content

Commit

Permalink
Fixed forgot password form and added new constant for the email address
Browse files Browse the repository at this point in the history
  • Loading branch information
antogno committed Jan 23, 2022
1 parent 5b745cd commit da0c6d4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ $this->email->from('', 'Blogsonic.org'); // Email (e.g.: example@gmail.com)
> **Note**: This step is optional. Obviously, not doing this means not making the "Forgot password" feature work.
### Add an email to be used for contact purposes in the `application/config/constants.php` file
```php
define('WEBSITE_EMAIL', ''); // Email address to be used publicly for contact purposes (e.g.: example@gmail.com)
```
### Edit the `robots.txt` and `sitemap.xml` files according to your data
`robots.txt`:
Expand Down
2 changes: 2 additions & 0 deletions application/config/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@
defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error
defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code

define('WEBSITE_EMAIL', ''); // Email address to be used publicly for contact purposes (e.g.: example@gmail.com)
29 changes: 14 additions & 15 deletions application/controllers/Profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,28 +351,27 @@ public function forgot()

if ($this->form_validation->run()) {
$profile = $this->Profiles_model->getUserByEmail($this->input->post('email'));

$result = false;
if ($profile) {
$email = $this->input->post('email');
$password = $this->newPassword();

$result = $this->sendNewPassword($email, $password);
}

if ($result) {
$this->Profiles_model->newPassword($email, $password);
$this->sendNewPassword($email, $password);
}

$user_session = [
'forgot_password_success' => true,
'forgot_password_fail' => false
];
$this->session->set_userdata($user_session);
$user_session = [
'forgot_password_success' => $result,
'forgot_password_fail' => ! $result
];

redirect($this->encryption->decrypt($this->session->userdata('language')) . 'profiles/forgot', 'refresh');
} else {
$user_session = [
'forgot_password_success' => false,
'forgot_password_fail' => true
];
$this->session->set_userdata($user_session);
$this->session->set_userdata($user_session);

redirect($this->encryption->decrypt($this->session->userdata('language')) . 'profiles/forgot', 'refresh');
}
redirect($this->encryption->decrypt($this->session->userdata('language')) . 'profiles/forgot', 'refresh');
} else {
$this->load->view('partials/header', $data);
$this->load->view('profiles/forgot', $data);
Expand Down
4 changes: 2 additions & 2 deletions application/core/MY_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function newPassword()
*
* @param string $email the email address to send the new password to.
* @param string $password the new password.
* @return void
* @return bool `true` on success, `false` on failure.
*/
public function sendNewPassword(string $email, string $password)
{
Expand All @@ -110,6 +110,6 @@ public function sendNewPassword(string $email, string $password)
'<p>'.$this->lang->line('forgot_password_email_body') . '<strong>' . $password . '</strong></p>'
);

$this->email->send();
return $this->email->send();
}
}
2 changes: 1 addition & 1 deletion application/language/english/blogsonic_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
$lang['forgot_password'] = 'Forgot password';
$lang['forgot_password_text'] = 'Enter your Email. We\'ll send you a message with the new Password.';
$lang['forgot_password_success'] = 'We have sent a new Password to the Email address you entered. Check your inbox.';
$lang['forgot_password_fail'] = 'There are no accounts with this Email. Retry.';
$lang['forgot_password_fail'] = 'An error occurred while sending the Email. Make sure the Email address you entered is correct. If the error persists, please contact';
$lang['forgot_password_email_subject'] = 'New Password - Blogsonic.org';
$lang['forgot_password_email_body'] = 'Hi! This is your new Password for your Blogsonic.org account: ';

Expand Down
2 changes: 1 addition & 1 deletion application/language/italian/blogsonic_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
$lang['forgot_password'] = 'Password dimenticata';
$lang['forgot_password_text'] = 'Inserisci la tua Email. Ti invieremo un messaggio con la nuova Password.';
$lang['forgot_password_success'] = 'Abbiamo inviato una nuova Password all\'indirizzo Email che hai inserito. Controlla la tua casella di posta.';
$lang['forgot_password_fail'] = 'Non ci sono account con questa Email. Riprova.';
$lang['forgot_password_fail'] = 'Si è verificato un errore durante l\'invio dell\'Email. Assicurati che l\'indirizzo Email che hai inserito sia corretto. Se l\'errore persiste, si prega di contattare';
$lang['forgot_password_email_subject'] = 'Nuova Password - Blogsonic.org';
$lang['forgot_password_email_body'] = 'Ciao! Ecco la tua nuova Password per il tuo account su Blogsonic.org: ';

Expand Down
2 changes: 1 addition & 1 deletion application/views/pages/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<p><strong><?= $this->lang->line('privacy_policy_12'); ?></strong></p>
<p><?= $this->lang->line('privacy_policy_13'); ?></p>
<p><strong><?= $this->lang->line('privacy_policy_14'); ?></strong></p>
<p><?= $this->lang->line('privacy_policy_15'); ?> <a href="mailto:tonio.granaldi@gmail.com">tonio.granaldi@gmail.com</a>.</p>
<p><?= $this->lang->line('privacy_policy_15'); ?> <a href="mailto:<?= WEBSITE_EMAIL ?>"><?= WEBSITE_EMAIL ?></a>.</p>
</div>
2 changes: 1 addition & 1 deletion application/views/profiles/forgot.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
?>
<div class="alert alert-dismissible alert-danger" id="danger_popup">
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
<?= '<p><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>&nbsp;' . $this->lang->line('forgot_password_fail') . '</p>' ?>
<?= '<p><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>&nbsp;' . $this->lang->line('forgot_password_fail') . ' <a href="mailto:' . WEBSITE_EMAIL . '">' . WEBSITE_EMAIL . '</a>.</p>' ?>
</div>
<?php
}
Expand Down

0 comments on commit da0c6d4

Please sign in to comment.