dqprf0976 2015-10-03 14:10 采纳率: 100%
浏览 86
已采纳

注册后,验证邮件和电子邮件尚未经过验证

I create a menu login and register with email verification . but none the less I want if the email has not been verified will display the message " Your email has not been verified " what should I add to my script ... ?

ex :

active = 1 ( already verified )

active = 0 ( not verified )

controllers:

public function index($param='')
{
    if($param == 'error')
        $param = 'Incorrect username or password';

    $data = array('title'=>'Login', 
                  'message'=>$param, 
                  'isi' => 'login/vlogin', 
                  'base_url'=>base_url());
    $this->load->view('layout/wrapper', $data); 
}


public function do_login(){


    $data = $this->input->post(null,true);
    $is_login = $this->db->get_where('user',array(
                            'email'=>$data['email'],
                            'password'=>$data['password'],
                            'active'=> 1
                             ))->row();      
    if($is_login){
        $session_set = array(

            'is_login'  => true,
            'firstname' => $is_login->firstname,
            'lastname'  => $is_login->lastname,
            'jkl'       => $is_login->jkl,  
            'id'        => $is_login->id,               
            'lastlogin' => $is_login->lastlogin
        );
        $this->db->update('user',array('lastlogin'=>date('Y-m-d H:i:s')),array('id'=>$is_login->id));
        $this->session->set_userdata($session_set);
        redirect('homepage/homepage/menu');
    }else{
        redirect('login/login/index/error');
    }
}
  • 写回答

2条回答 默认 最新

  • doudao1922 2015-10-03 17:24
    关注

    You have to check first if user credentials are correct and then check whether email is verified or not.

    So, you can try this:

    public function do_login() {
    
        $data = $this->input->post(null, true);
    
        $user = $this->db->get_where('user', array(
            'email'=>$data['email'],
            'password'=>$data['password']
             ))->row();
    
        if ($user) {    //User exists
            if ($user->active == 1) {   //User exists and his email is verified
                $session_set = array(
                    'is_login'  => true,
                    'firstname' => $user->firstname,
                    'lastname'  => $user->lastname,
                    'jkl'       => $user->jkl,  
                    'id'        => $user->id,               
                    'lastlogin' => $user->lastlogin
                );
    
                $this->db->update('user', array('lastlogin'=>date('Y-m-d H:i:s')), array('id'=>$user->id));
                $this->session->set_userdata($session_set);
                redirect('homepage/homepage/menu');   
    
            } else {    //User exists BUT his email is NOT verified
    
                $this->session->set_flashdata('message', 'Your email is not verified yet');
                //You have to capture and show the flash message in view
    
                redirect('login/login/index/error');
            }
        } else {    //User does NOT exist at all
    
            $this->session->set_flashdata('message', 'The combination of username and/or password was incorrect. Please, try again.');
            //You have to capture and show the flash message in view
    
            redirect('login/login/index/error');
        }
    }
    

    And in your view put something like:

    <?php if ($this->session->flashdata('message')) : ?>
    <p class="someErrorClass"><?php echo $this->session->flashdata('message'); ?></p>
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应