<commit_before>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2018] EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

package EnsEMBL::Users::Mailer::User;

use strict;
use warnings;

use parent qw(EnsEMBL::Web::Mailer);

sub set_noreply_sender {
  ## Sets the 'from' field as ENSEMBL_NOREPLY_EMAIL
  ## Call this for sending emails to unregistered emails (likely to be invalid) so that the ENSEMBL_HELPDESK_EMAIL doesn't get bombarded with bounced email.
  my $self    = shift;
  $self->from = $self->hub->species_defs->ENSEMBL_NOREPLY_EMAIL;
}

sub send_verification_email {
  ## Sends an activation email to newly registered users
  ## @param Login object that needs to be verified
  my ($self, $login) = @_;

  my $sitename  = $self->site_name;
  my $user      = $login->user;
  my $type      = $login->type;
  my $provider  = $login->provider || '';
  my $identity  = $login->identity;
  my $function  = 'Confirm';
  my $email     = $user->email;
  my $name      = $user->name;
  my $url       = $self->url({
    'species'     => '',
    'type'        => 'Account',
    'action'      => 'Details',
    'function'    => $function,
    'code'        => $login->get_url_code
  });


  my $greeting = qq(Hi\n\n\nThank you for registering with $sitename. Before you can access your account, you will need to confirm your email address ($email) and set a password - click on the link below to visit our account activation page);

  my $more_info = qq#Your $sitename user account will allow you to:\n\n* save data that you have uploaded to our servers (non-saved data is deleted after 7 days)\n\n* bookmark your most-used pages\n\n* save page configurations so you can return to a view exactly as you left it, even on another computer\n\n* create groups to make collaboration easier#;

  my $extra = qq(If you did not register with us yourself, please contact us and we will delete your details from our database. See below for more information about our privacy policy.);

  my $message   =  qq($greeting\n\n\n$url\n\n\n$more_info\n\n\n$extra); 

  $self->to      = "$name <$email>";
  $self->subject = qq($sitename: $function your email address);
  $self->message = $message.$self->email_footer;
  $self->set_noreply_sender;
  $self->send;
}

sub send_password_retrieval_email {
  ## Send email to the registered email with a link to reset password for a 'local' login
  ## @param Login object whose password needs to be retrieved
  my ($self, $login) = @_;

  my $sitename    = $self->site_name;
  my $user        = $login->user;
  my $name        = $login->name;
  my $email       = $user->email;
  my $footer      = $self->email_footer;
  my $url         = $self->url({
    'species'       => '',
    'type'          => 'Account',
    'action'        => 'Password',
    'function'      => 'Change',
    'code'          => $login->get_url_code
  });

  $self->to       = "$name <email>";
  $self->subject  = qq($sitename: Reset your password);
  $self->message  = qq(We received a request to reset your password for $sitename. If this was you, please go to the following url:\n\n\n$url\n\n\nThis will allow you to set a new password and log in to the site again.\n\n)
                    .qq(If this was not you, please let us know at <EMAIL>. You can ignore the link above; your old password will not be changed and you will be able to continue to use it.\n\n);
                    .$footer;

  $self->set_noreply_sender;
  $self->send;
}

sub send_change_email_confirmation_email {
  ## Sends an email to the new email address if the user want to change his email
  ## @param Any active login object related to the user
  ## @param New email string
  my ($self, $login, $new_email) = @_;
<commit_msg>fix account bug introduced by 8433fee<commit_after>=head1 LICENSE

Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2018] EMBL-European Bioinformatics Institute

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut

package EnsEMBL::Users::Mailer::User;

use strict;
use warnings;

use parent qw(EnsEMBL::Web::Mailer);

sub set_noreply_sender {
  ## Sets the 'from' field as ENSEMBL_NOREPLY_EMAIL
  ## Call this for sending emails to unregistered emails (likely to be invalid) so that the ENSEMBL_HELPDESK_EMAIL doesn't get bombarded with bounced email.
  my $self    = shift;
  $self->from = $self->hub->species_defs->ENSEMBL_NOREPLY_EMAIL;
}

sub send_verification_email {
  ## Sends an activation email to newly registered users
  ## @param Login object that needs to be verified
  my ($self, $login) = @_;

  my $sitename  = $self->site_name;
  my $user      = $login->user;
  my $type      = $login->type;
  my $provider  = $login->provider || '';
  my $identity  = $login->identity;
  my $function  = 'Confirm';
  my $email     = $user->email;
  my $name      = $user->name;
  my $url       = $self->url({
    'species'     => '',
    'type'        => 'Account',
    'action'      => 'Details',
    'function'    => $function,
    'code'        => $login->get_url_code
  });


  my $greeting = qq(Hi\n\n\nThank you for registering with $sitename. Before you can access your account, you will need to confirm your email address ($email) and set a password - click on the link below to visit our account activation page);

  my $more_info = qq#Your $sitename user account will allow you to:\n\n* save data that you have uploaded to our servers (non-saved data is deleted after 7 days)\n\n* bookmark your most-used pages\n\n* save page configurations so you can return to a view exactly as you left it, even on another computer\n\n* create groups to make collaboration easier#;

  my $extra = qq(If you did not register with us yourself, please contact us and we will delete your details from our database. See below for more information about our privacy policy.);

  my $message   =  qq($greeting\n\n\n$url\n\n\n$more_info\n\n\n$extra); 

  $self->to      = "$name <$email>";
  $self->subject = qq($sitename: $function your email address);
  $self->message = $message.$self->email_footer;
  $self->set_noreply_sender;
  $self->send;
}

sub send_password_retrieval_email {
  ## Send email to the registered email with a link to reset password for a 'local' login
  ## @param Login object whose password needs to be retrieved
  my ($self, $login) = @_;

  my $sitename    = $self->site_name;
  my $user        = $login->user;
  my $name        = $login->name;
  my $email       = $user->email;
  my $footer      = $self->email_footer;
  my $url         = $self->url({
    'species'       => '',
    'type'          => 'Account',
    'action'        => 'Password',
    'function'      => 'Change',
    'code'          => $login->get_url_code
  });

  $self->to       = "$name <email>";
  $self->subject  = qq($sitename: Reset your password);
  $self->message  = qq(We received a request to reset your password for $sitename. If this was you, please go to the following url:\n\n\n$url\n\n\nThis will allow you to set a new password and log in to the site again.\n\n)
                    .qq(If this was not you, please let us know at <EMAIL>. You can ignore the link above; your old password will not be changed and you will be able to continue to use it.\n\n)
                    .$footer;

  $self->set_noreply_sender;
  $self->send;
}

sub send_change_email_confirmation_email {
  ## Sends an email to the new email address if the user want to change his email
  ## @param Any active login object related to the user
  ## @param New email string
  my ($self, $login, $new_email) = @_;

{'fraction_non_alphanumeric': 0.10789869318838903, 'fraction_numerical': 0.005551058170463745, 'mean_word_length': 3.2600985221674876, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4881208', 'n_tokens_mistral': 2709, 'n_tokens_neox': 2577, 'n_words': 1027}