CodeIgniter 3 функция сброса пароля электронной почты - PullRequest
0 голосов
/ 24 июня 2019

Я сделал функцию сброса пароля для одного из моих проектов.

В данный момент я застрял, так как не уверен, как связать код.

У меня есть функция электронной почты, функция сброса и ссылка сброса, все готово к работе.Но я не уверен, как получить ссылку сброса, которая будет отправлена ​​по почте на введенный адрес электронной почты из представления и сообщения электронной почты, чтобы включить мой токен сброса и сообщение.

Пожалуйста, посмотрите на мой код и, если возможно, посоветуйте, очень ценю.

Это мой код контроллера пользователя

public function Email($data){

                $config = array(
                'useragent' => 'codeIgniter',
                'protocol' => 'mail',
                'mailpath' => '/usr/sbin/sendmail',
                'smtp_host' => 'localhost',
                'smtp_user' => 'Myemail',
                'smtp_pass' => 'mypass',
                'smtp_port' => 25,
                'smtp_timeout' => 55,
                'wordwrap' => TRUE,
                'wrapchars' => 76,
                'mailtype' => 'html',
                'charset' => 'utf-8',
                'validate' => FALSE,
                'priority' => 3,
                'crlf' => "\r\n",
                'newline' => "\r\n",
                'bcc_batch_mode' => FALSE,
                'bcc_batch_size' => 200,
                );

                $this->load->library('email', $config);
                $this->email->set_newline('\r\n');
                $this->email->from('myemail');
                $this->email->to('');    //This is where I'm not sure.
                $this->email->subject("Reset Password");
                $this->email->message(); //Next point where I'm not sure
                $this->email->set_mailtype('html');

                if($this->email->send()){
                    return TRUE;
                }
                else{
                    return FALSE;
                }

        }

        public function forgotpassword(){
                $this->load->view('templates/header');
                $this->load->view('users/forgotpassword');
                $this->load->view('templates/footer');

            }
        public function resetlink(){
                $email = $this->input->post('email');
                $result = $this->db->query("select * from users where 
email ='".$email."'")->result_array();
                if(count($result)>0){
                    $token = rand(100000,999999);

                    $this->db->query("update users set password = 
'".$token."' where email = '".$email."'");

                    $message = "Please click on the password reset link 
<br><a href='".base_url('users/reset?token=').$token."'>Reset 
Password</a>";

                    $this->Email($email, 'Reset Password Link', $message);
                }
                else{
                    $this->session->set_flashdata('message', 'Email not 
 registered');
                    redirect(base_url('users/forgotpassword'));
                }
            }
        public function resetpass(){
            $data['token'] = $this->input->get('token');
            $_SESSION['token'] = $data['token'];
            $this->load->view('templates/header');
            $this->load->view('users/resetpass');
            $this->load->view('templates/footer');
        }
        public function updatepass(){
            $_SESSION['token'];
            $data = $this->input->post();
            if ($data['password'] == $data ['cpassword']){
                $this->db->query("update users set 
password'".$data['password']."' where password='".$_SESSION['token']."'");
            }
        }

Это мой забытый пароль

<style>
                body{
                    background-image: 
url("/assets/images/posts/background12.jpg");
                    background-repeat: no-repeat;
                    background-size: cover;
                }
            </style>

            <br>
            <br>
            <form action="<?= base_url('users/resetlink')?>" 
method="post">
            <div class="row" >
                <div class="col-md-3"></div>
                <div class="col-md-6">
                    <div class="form-group" >
                        <h2 align="center" >Reset your Password</h2>
                        <br>
                        <input type="email" class="form-control" 
name="email" placeholder="Email" required autofocus>
                    </div>
                    <input style="margin-top: 15px" type="submit" 
class="btn btn-info btn-block" value="Send reset link">
                    <h3 style="margin-top: 30px" align="center"><?= $this- 
>session->flashdata('message') ?></h3>
                </div>

                <div class="col-md-3"></div>
            </div>
            </form>

Сброс пароля Просмотр

<style>
body{
    background-image: url("/assets/images/posts/background12.jpg");
    background-repeat: no-repeat;
    background-size: cover;
}
</style>

<br>
<br>
<form action="<?= base_url('users/resetpass') ?>">
<div class="row" >
    <div class="col-md-3"></div>
    <div class="col-md-6">
        <h1>Reset Password</h1>
        <div class="form-group" >
            <h1 align="center"><?= $this->session->flashdata('message') ?></h1>
            <input type="password" id="email" class="form-control" 
name="password" placeholder="Password" required autofocus>
        </div>
        <div class="form-group" >
            <input type="password" id="email" class="form-control" 
name="cpassword" placeholder="Confirm Password" required autofocus>
        </div>

        <input style="margin-top: 15px" type="submit" class="btn btn-info 
btn-block" value="Reset password">
    </div>
    <div class="col-md-3"></div>
</div>
</form>

Это весь соответствующий код, который я получил для этого.Любая помощь будет оценена

1 Ответ

1 голос
/ 24 июня 2019

Если вы измените функцию электронной почты на

public function Email($email, $subject, $content){

                $config = array(
                'useragent' => 'codeIgniter',
                'protocol' => 'mail',
                'mailpath' => '/usr/sbin/sendmail',
                'smtp_host' => 'localhost',
                'smtp_user' => 'Myemail',
                'smtp_pass' => 'mypass',
                'smtp_port' => 25,
                'smtp_timeout' => 55,
                'wordwrap' => TRUE,
                'wrapchars' => 76,
                'mailtype' => 'html',
                'charset' => 'utf-8',
                'validate' => FALSE,
                'priority' => 3,
                'crlf' => "\r\n",
                'newline' => "\r\n",
                'bcc_batch_mode' => FALSE,
                'bcc_batch_size' => 200,
                );

                $this->load->library('email', $config);
                $this->email->set_newline('\r\n');
                $this->email->from('myemail');
                $this->email->to($email);    //email address passed into the function.
                $this->email->subject($subject); // subject passed into the function
                $this->email->message($content); //content passed into the function
                $this->email->set_mailtype('html');

                if($this->email->send()){
                    return TRUE;
                }
                else{
                    return FALSE;
                }

        }

Однако, согласно [документации Codeigniter] [1]

[1]: https://www.codeigniter.com/user_guide/libraries/email.html?highlight=complete%20web, вам необходимо отправить полную веб-страницу. Поэтому вам нужно что-то вроде -

$message = "<html><head><title>Password Reset</title></head><body>Please click on the password reset link <br><a href='".base_url('users/reset?token=').$token."'>Reset Password</a></body></html>";

$this->Email($email, 'Reset Password Link', $message);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...