Skip to content

Instantly share code, notes, and snippets.

@envex
Created November 10, 2009 16:05
Show Gist options
  • Save envex/230986 to your computer and use it in GitHub Desktop.
Save envex/230986 to your computer and use it in GitHub Desktop.
//signup.ctp
<h2>Signup</h2>
<?php $session->flash(); ?>
<?php
e($form->create('Member', array('action' => 'signup'))); ?>
<h3>Login Information</h3>
<ul class="form">
<li>
<label for="">Email Address</label>
<?php e($form->input('Member.email', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">Password</label>
<?php e($form->input('Member.password', array('type' => 'password', 'label' => false))); ?>
</li>
<li>
<label for="">Confirm Password</label>
<?php e($form->input('Member.password2', array('type' => 'password', 'label' => false))); ?>
</li>
</ul>
<h3>Personal Information</h3>
<ul class="form">
<li>
<label for="">Full Name</label>
<?php e($form->input('Member.name', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">Company Name</label>
<?php e($form->input('Member.company', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">Street Address</label>
<?php e($form->input('Member.street', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">City</label>
<?php e($form->input('Member.city', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">State</label>
<?php e($form->input('Member.state', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">Zip Code</label>
<?php e($form->input('Member.zip', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
<li>
<label for="">Phone Number</label>
<?php e($form->input('Member.phone', array('type' => 'text', 'size' => '20', 'label' => false))); ?>
</li>
</ul>
<?php e($form->submit('Sign Up Now!', array('class'=>'signup_button'))); ?>
<?php e($form->end()); ?>
//MembersController
<?php
class MembersController extends AppController{
var $name = 'Members';
function beforeFilter(){
$this->Auth->userModel = 'Member';
$this->Auth->allow('signup');
$this->set('area','members');
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
}
//show the members section
function index(){
}
//We need to signup new users
function signup() {
if (!empty($this->data)) {
//lets check to see if the password & confirm password are empty
if(isset($this->data['Member']['password']) && isset($this->data['Member']['password2'])){
$this->data['Member']['passwordhashed'] = $this->Auth->password($this->data['Member']['password']);
$this->data['Member']['password2hashed'] = $this->Auth->password($this->data['Member']['password2']);
$this->data['Member']['password'] = $this->data['Member']['passwordhashed'];
}
$this->Member->create();
$this->data['Member']['joined'] = date('Y-m-d');
if ($this->Member->save($this->data)) {
$this->Session->setFlash('Your account has been created!');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('You account could not be created. Try again!');
}
}
}
//Let the user login
function login(){
$this->set('onLogin','true');
}
//Logout the user
function logout(){
$this->Session->setFlash('You\'ve been logged out!');
$this->redirect($this->Auth->logout());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment