激活注册

时间:2012-01-31 18:31:15

标签: php jquery codeigniter

我要注意的是,在注册帐户时,用户会收到一封电子邮件,其中包含指向我的激活页面的链接,其中包含用户ID和注册码。所以它看起来像

myurl.com/activate/10000/8794078fdajklfj/

对于带代码点火器的路线,我正在使用它:

$ route ['activate /(:any)'] =“activate / index / $ 1”;

这是对的吗?

当用户访问网址时,会有一个文本框供用户填写他们的电子邮件地址,以便与用户ID和注册密钥进行匹配以进行验证。但是,我正在试图弄清楚如何使用jquery ajax设置它。

$(window).load(function(){
/*
* Validate the form when it is submitted
*/
var validate = $("form").validate({
    rules: {
        email: {
          email: true
        }
    },
    invalidHandler: function(form, validator) {
        var errors = validator.numberOfInvalids();
        if (errors) {
            var message = errors == 1
            ? 'You missed 1 field. It has been highlighted.'
            : 'You missed ' + errors + ' fields. They have been highlighted.';
            $('.box .content').removeAlertBoxes();
            $('.box .content').alertBox(message, {type: 'warning', icon: true, noMargin: false});
            $('.box .content .alert').css({
                width: '',
                margin: '0',
                borderLeft: 'none',
                borderRight: 'none',
                borderRadius: 0
            });
        } else {
            $('.box .content').removeAlertBoxes();
        }
    },
    showErrors : function(errorMap, errorList) {
        this.defaultShowErrors();
        var self = this;
        $.each(errorList, function() {
            var $input = $(this.element);
            var $label = $input.parent().find('label.error').hide();
            $label.addClass('red');
            $label.css('width', '');
            $input.trigger('labeled');
            $label.fadeIn();
        });
    },
    submitHandler: function(form) {
        var dataString = $('form').serialize();
        $.ajax({
            type: 'POST',
            url: 'http://www.kansasoutlawwrestling.com/kowmanager/activate/activate_submit',
            data: dataString,
            dataType: 'json',
            success:  function(data) {
                if (data.error) {
                    $('.box .content').removeAlertBoxes();
                    $('.box .content').alertBox(data.message, {type: 'warning', icon: true, noMargin: false});
                    $('.box .content .alert').css({
                        width: '',
                        margin: '0',
                        borderLeft: 'none',
                        borderRight: 'none',
                        borderRadius: 0
                    });
                } else {
                    $('.box .content').removeAlertBoxes();
                    $('.box .content').alertBox(data.message, {type: 'success', icon: true, noMargin: false});
                    window.location='/kowmanager/login';
                } 
            }
        });
    }
});
}); 

控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Activate extends CI_Controller 
{ 

public function __construct()
{
    parent::__construct();
    $this->load->library('kow_auth');  
    $this->load->model('kow_auth/users');           
}   

public function index()
{
    //Config Defaults Start
    $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
    $cssPageAddons = '';//If you have extra CSS for this view append it here
    $jsPageAddons = '<script src="http://www.kansasoutlawwrestling.com/kowmanager/assets/js/activatevalidate.js"></script>';//If you have extra JS for this view append it here
    $metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
    $siteTitle = '';//alter only if you need something other than the default for this view.
    //Config Defaults Start


    //examples of how to use the message box system (css not included).
    //$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');

    /**********************************************************Your Coding Logic Here, Start*/

    if (!$this->session->userdata('xtr') == "yes") {
        $bodyContent = "activate_form";//which view file
    } else {
        $bodyContent = "dashboard";//which view file
    }

    $bodyType = "full";//type of template

    /***********************************************************Your Coding Logic Here, End*/

    //Double checks if any default variables have been changed, Start.
    //If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.      
    if(count($msgBoxMsgs) !== 0)
    {
        $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
    }
    else
    {
        $msgBoxes = array('display' => 'none');
    }

    if($siteTitle == '')
    {
        $siteTitle = $this->metatags->SiteTitle(); //reads 
    }

    //Double checks if any default variables have been changed, End.

    $this->data['msgBoxes'] = $msgBoxes;
    $this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
    $this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
    $this->data['metaAddons'] = $metaAddons;//if there is any addictional meta data to add from the above variable this will send it to the view.
    $this->data['pageMetaTags'] = $this->metatags->MetaTags();//defaults can be changed via models/metatags.php
    $this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
    $this->data['bodyType'] = $bodyType;
    $this->data['bodyContent'] = $bodyContent;
    $this->load->view('usermanagement/index', $this->data);
}

function activate_submit()
{
    $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');

    $user_id            = $this->uri->segment(3);
    $registration_key   = $this->uri->segment(4);

    if (!$this->form_validation->run()) 
    {
        echo json_encode(array('error' => 'yes', 'message' => 'There was a problem submitting the form! Please refresh the window and try again!'));    
    }
    else
    {                           
        if ($this->kow_auth->activate_user($user_id, $registration_key, $this->input->post('email'))) 
        {
            echo json_encode(array('sucess' => 'yes', 'message' => 'Your account has been successfully activated!'));
        } 
        else 
        {                                                           
            echo json_encode(array('error' => 'yes', 'message' => 'The activation code you entered is incorrect or expired!'));
        }
    }
}

}

/* End of file activate.php */ 
/* Location: ./application/controllers/activate.php */ 

0 个答案:

没有答案