public function __toString() { // $attr = $this->_html_attr; // $attr['class'] = $this->css_class(); // $attr['type'] = $this->field_type(); // return Form::checkbox($this->name(), null, (bool)$this->value(), $attr); if (array_key_exists('recaptcha', Kohana::modules())) { $recap = Recaptcha::instance(); return $recap->get_html(); } else { return ""; } }
public function action_index() { if (Auth::instance()->get_user()) { $this->template->current_user_id = Auth::instance()->get_user(); $this->template->current_user = ORM::factory('user', Auth::instance()->get_user()); $this->request->redirect('home/'); } $this->layout->page_title = 'Register an account'; $this->layout->scripts = array('sourcemap-core', 'sourcemap-template'); $f = Sourcemap_Form::load('/register'); $f->action('register')->method('post'); $this->template->form = $f; if (strtolower(Request::$method) === 'post') { $validate = $f->validate($_POST); if (array_key_exists('recaptcha', Kohana::modules())) { $recap = Recaptcha::instance(); $revalid = (bool) $recap->is_valid($_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); $validate = $validate && $revalid; } if ($validate) { $p = $f->values(); // check for username in use $exists = ORM::factory('user')->where('username', '=', $p['username'])->find()->loaded(); if ($exists) { Message::instance()->set('That username is taken.'); return; } // check for email in use $exists = ORM::factory('user')->where('email', '=', $p['email'])->find()->loaded(); if ($exists) { Message::instance()->set('An account exists for that email address.'); return; } $new_user = ORM::factory('user'); $new_user->username = $p['username']; $new_user->email = $p['email']; $new_user->password = $p['password']; $new_user->save(); if (!$new_user->id) { Message::instance()->set('Could not complete registration. Please contact support.'); return $this->request->redirect('register'); } //send a notification $subj = 'Re: Your New Account on Open Supply Chains'; $h = md5(sprintf('%s-%s', $new_user->username, $new_user->email)); $lid = strrev(base64_encode($new_user->username)); $url = URL::site("register/confirm?t={$lid}-{$h}", true); $msgbody = "Dear {$new_user->username},\n\n"; $msgbody .= 'Welcome to Open Supply Chains! '; $msgbody .= "Go to the url below to activate your account.\n\n"; $msgbody .= $url . "\n\n"; $msgbody .= "If you have any questions, please contact us.\n"; $addlheaders = "From: Open Supply Chains\r\n"; try { $sent = mail($new_user->email, $subj, $msgbody, $addlheaders); Message::instance()->set('Please check your email for further instructions.', Message::INFO); } catch (Exception $e) { Message::instance()->set('Sorry, could not complete registration. Please contact support.'); } return $this->request->redirect('register'); } else { Message::instance()->set('Check the information below and try again.'); } } else { /* pass */ } }