links for 2008-06-06

Advertisements
Posted in 15
3 comments on “links for 2008-06-06
  1. Joener says:

    Hi Richard,

    Can you help me to figure out. What the problem in my code.
    When i try to register, it didnt save to my database. and didnt sent to the email address of the uernae name email.

    Kindly refer to my code below.

    //Users controller

    class UsersController extends AppController
    {
    var $name=’Users’;
    var $helpers= array(‘Html’,’Form’);
    var $components = array(‘Email’,’Auth’);

    function signup()
    {

    if (!empty($this->data))
    {
    if(isset($this->data[‘User’][‘password2’]))
    $this->data[‘User’][‘password2hashed’] = $this->Auth->password($this->data[‘User’][‘password2’]);

    $this->data[‘User’][‘confirm_code’] = String::uuid();

    $this->User->create();

    if ($this->User->save($this->data))
    {
    $this->Email->to = $this->data[‘User’][’email’];
    $this->Email->subject = ‘Confirmation’;
    $this->Email->replyTo = ‘noreply@cakequickwall.com’;
    $this->Email->from = ‘Quickwall
    ‘;
    $this->Email->sendAs = ‘html’;
    $this->Email->template = ‘confirmation’;
    $this->set(‘name’,$this->data[‘User’][‘username’]);
    $this->set(‘server_name’,$_SERVER[‘SERVER_NAME’]);
    $this->set(‘id’,$this->User->getLastInsertID());
    $this->set(‘code’, $this->data[‘User’][‘confirm_code’]);

    if($this->Email->send())
    {
    $this->Session->setFlash(‘Confirmation mail sent.Please check your inbox’);
    $this->redirect(array(‘controller’ => ‘questions’,’action’=>’home’));
    }
    else
    {
    $this->User->delete($this->User->getLastInsertID());
    $this->Session->setFlash(‘There was a problem sending
    the confirmation mail. Please try again’);
    }

    }
    else
    {
    $this->Session->setFlash(‘There was an error signing up.
    Please, try again.’);
    }

    $this->data = null;

    }
    }

    //confirm function

    function confirm($user_id=null, $code=null) {

    if(empty($user_id) || empty($code))
    {
    $this->set(‘confirmed’, 0);
    $this->render();
    }
    $user = $this->User->read(null, $user_id);
    if(empty($user)) {
    $this->set(‘confirmed’, 0);
    $this->render();
    }
    if($user[‘User’][‘confirm_code’] == $code){
    $this->User->id = $user_id;
    $this->User->saveField(‘confirmed’, ‘1’);
    $this->set(‘confirmed’, 1);
    } else {
    $this->set(‘confirmed’, 0);
    }
    }

    //confirmation.ctp

    Hi ,
    Thank you for signing up in Quickwall. To complete the sign up
    process please click on the link below:
    <a href="http://
    url(array(‘controller’ => ‘users’, ‘action’ => ‘confirm’));
    ?>//”>Confirm your account

    //confirm.ctp

    Sign Up Confirmation

    Congratulations! You have successfully confirmed your
    account. Now you can login.

    Invalid Confirmation. Please sign up.

  2. Joener says:

    Hope you can help me. Thanx

  3. Hi Joener

    I don’t check back on this blog very ofter, I’ve moved to http://richardathome.com

    My first guess is that you new user is failing to validate so it isn’t saving and it’s failing for one of the fields you are not displaying on your registration form.

    You can add the following to the bottom of your signup function to output all the errors associated with it:

    echo pr($this->User->validationErrors);

    Hope this helps

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: