Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
*) Complete registration process, including forms, views, and control…
Browse files Browse the repository at this point in the history
…lers

*) Updated schema
*) Updated fixtures
*) DID NOT RUN DOCTRINE BUILD
  • Loading branch information
ajbrown committed Feb 9, 2009
1 parent e95fb9f commit 0fe1599
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 166 deletions.
6 changes: 2 additions & 4 deletions application/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
. PATH_SEPARATOR . ROOT . '/application/default'
. PATH_SEPARATOR . ROOT . '/library'
. PATH_SEPARATOR . ROOT . '/models'
. PATH_SEPARATOR . ROOT . '/models/handlers'
. PATH_SEPARATOR . ROOT . '/models/generated'
. PATH_SEPARATOR . '/usr/share/php/Zend/library'
. PATH_SEPARATOR . '/usr/share/php/Doctrine/lib'
. PATH_SEPARATOR . '/usr/share/php'
. PATH_SEPARATOR . '/usr/share/php/Doctrine-1.1.0-RC1/lib'
);

require_once 'Zend/Controller/Plugin/Abstract.php';
Expand Down Expand Up @@ -163,7 +162,6 @@ public function initApp()
//configure mail transport
$tr = new Zend_Mail_Transport_Sendmail( '[email protected]' );
Zend_Mail::setDefaultTransport( $tr );

}

/**
Expand Down
7 changes: 7 additions & 0 deletions application/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
</reqs>
</confirmAccount>
</routes>

<recaptcha>
<username>hypermuttlabs</username>
<password>hypermutt!@#</password>
<publicKey>6LdiCgUAAAAAAO5ffS8gINxZ4lv6cAuNLz41gTGT</publicKey>
<privateKey>6LdiCgUAAAAAAK4_IxT92MtiQFI8sIAXyRnWHKuu</privateKey>
</recaptcha>

</production>

Expand Down
49 changes: 46 additions & 3 deletions application/dashboard/controllers/CatalogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,72 @@
class Dashboard_CatalogController extends Dashboard_BaseController
{

/**
* @var Artist
*/
protected $_artist;

public function init()
{
parent::init();

$artists = new App_Table_Artist();
$this->_artist = $artists->findOneByAccountId( $this->_identity->id );

}
public function indexAction()
{
$releaseTable = new App_Table_Release();
$releases = $releaseTable->findByArtistId( $this->_artist->id );

$this->view->assign( 'releases', $releases );
}

public function addreleaseAction()
{
$form = new App_Form_Release();
$form->addElement( 'Submit', 'continue', array(
'label' => 'Save & Add Tracks',
'value' => 'continue'
) );

if( !empty( $_POST ) && $form->isValid( $_POST ) ) {

//find the artistId for this account:
$release = new Release();
$release->title = $form->getValue( 'title' );
$release->artistId = $this->_artist->id;
$release->publishDate = $form->getValue( 'publishDate' );
$release->save();

$this->_flash->addMessage( 'Your release has been created.' );
if( $form->getValue( 'continue' ) != null ) {
$this->_redirector->gotoSimple( 'addtrack', null, null,
array( 'releaseId' => $release->id ) );
}

$form->setDefaults( array( 'publishDate' => date( 'm/d/Y' ) ) );
}


$form->setMethod( 'post' );
$form->setAction( '/dashboard/catalog/addrelease' );
$this->view->form = $form;
}

public function addtrackAction()
{

$form = new App_Form_NewTrack();

if ( !empty( $_POST ) && $form->isValid( $_POST ) ) {

$artists = new App_Table_Artist();

//--------------------------------
// Check the file info, and save
//--------------------------------
$track = new Track();
$track->title = $form->getValue( 'title' );
$track->artistId = $this->_identity->id;
$track->artistId = $this->_artist->id;
$track->releaseId = $form->getValue( 'releaseId' );
$track->single = true;
$track->publishDate = $form->getValue( 'publishDate' );
Expand All @@ -56,6 +98,7 @@ public function addtrackAction()
$form = new App_Form_NewTrack();
}

$form->setDefault( 'releaseId', $this->_request->getParam( 'releaseId' ) );
$form->setMethod( 'post' );
$form->setAction( '/dashboard/catalog/addtrack' );
$this->view->form = $form;
Expand Down
5 changes: 3 additions & 2 deletions application/dashboard/views/scripts/catalog/addtrack.phtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php $this->placeholder( 'title' )->set( 'Upload Track' ); ?>
<?php echo $this->form; ?>

<div class="tundra">
<?php echo $this->form; ?>
</div>
12 changes: 9 additions & 3 deletions application/data/controllers/ArtistsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ public function infoAction()

public function releasesAction()
{
$artistId = $this->_request->getParam( 'id' );
$artistId = $this->_request->getParam( 'id' );
$published = $this->_request->getParam( 'published', false );

$releaseTable = new App_Table_Release();
$releases = $releaseTable->findPublishedByArtist( $artistId, false )
->toArray( true );
if( $published ) {
$releases = $releaseTable->findPublishedByArtist( $artistId )
->toArray( true );
} else {
$releases = $releaseTable->findByArtistId( $artistId );
}

$data = new Zend_Dojo_Data( 'id', $releases, 'releases' );
echo $data->toJson();
}
Expand Down
192 changes: 76 additions & 116 deletions application/default/controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public function loginAction()
} else {

$userdata = $adapter->getResultRowObject( null, 'password' );
$auth->getStorage()->write( $userdata );

//translate the user into an actual doctrine object
$accounts = new App_Table_Account();
$auth->getStorage()->write( $accounts->find( $userdata->id ) );

//audit the login
$login = new AccountLogin();
Expand Down Expand Up @@ -112,161 +115,118 @@ public function profileAction()

public function logoutAction()
{

if ( Zend_Auth::getInstance()->getIdentity() ) {

Zend_Auth::getInstance()->clearIdentity();
$this->_flash->addMessage( 'You have been logged out.' );
}

}

public function registerAction()
{
$username = $this->_getParam( 'emailAddress' );
$regForm = new forms_RegisterForm();

if ( !empty( $username ) && $regForm->isValid( $_POST ) ) {

$params = $this->_getAllParams();
$messages = array();
$valid = true;

// make sure the username isn't taken
require_once 'models/handlers/AccountsHandler.php';
$accounts = new AccountsHandler( Doctrine_Manager::connection() );
$result = $accounts->findOneByEmailAddress( $params[ 'emailAddress' ] );

if ( false !== $result ) {
$messages[] = 'The username you specfied is already taken.';
$valid = false;
}

// password confirmation must be the same
if ( !$params['password'] == $params['passwordconfirm'] ) {
$messages[] = 'The passwords you entered did not match';
$valid = false;
}


if ( $valid ) {

// save the user

$user = $accounts->create();
$user->username = $params[ 'emailAddress' ];
$user->emailAddress = $params[ 'emailAddress' ];
$user->password = md5( $params[ 'password' ] );
$user->confirmed = false;
$user->save();


// send the confirmation, and redirect to the confirm page

$this->_sendConfirmEmail( $user->emailAddress );

$form = new App_Form_Register();

$msg = "A confirmation code has been set to "
. "<cite>{$user->emailAddress}</cite>. Please check "
. "your enter the confirmation into the field below.";

$this->_flash->addMessage( $msg );
$this->_redirect( '/account/confirm/' . $user->emailAddress );
return;

}
if ( !empty( $_POST ) && $form->isValid( $_POST ) ) {

// add error messages to flash
foreach( $messages as $msg ) {
$this->_flash->addMessage( $msg );
}
if( $form->getValue( 'sellerAccount' ) ) {
$account = new Seller();
} else {
$account = new Buyer();
}

$account->username = $form->getValue( 'emailAddress' );
$account->emailAddress = $form->getValue( 'emailAddress' );
$account->password = $form->getValue( 'password' );
$account->confirmed = false;
$account->save();

// send the confirmation, and redirect to the confirm page
$this->_sendConfirmEmail( $account->emailAddress );

$msg = "A confirmation code has been set to "
. "<cite>{$account->emailAddress}</cite>. Please check "
. "your enter the confirmation into the field below.";

$this->_flash->addMessage( $msg );
$this->_redirector->gotoSimple( 'confirm', null, null, array(
'email' => $account->emailAddress
) );
}

$regForm->setMethod( 'post' );
$this->view->form = $regForm;
$form->setMethod( 'post' );
$this->view->form = $form;
}

public function confirmAction()
{
$code = $this->_getParam( 'code' );
$email = $this->_getParam( 'email' );
$resend = $this->_getParam( 'resend' );

$form = new forms_ConfirmForm();
$form->setMethod( 'get' );
$form->setDefaults( array( 'email' => $email, 'code' => $code ) );
$code = $this->_request->getParam( 'code' );
$email = $this->_request->getParam( 'email' );

if( !empty( $resend ) && !empty( $email ) ) {
$form = new App_Form_ConfirmRegister();
$form->setMethod( 'post' );

//------------------------------------------
// Resend email confirmation
//------------------------------------------
if( !empty( $_POST ) && $form->isValid( $_POST ) ) {

//make sure the supplied email address is registered and not confirmed
$accounts = new AccountsHandler();
$result = $accounts->findOneByEmailAddress( $email );
if( false !== $result ) {
$confirms = new App_Table_AccountConfirm();
$code = $form->getValue( 'code' );
$email = $form->getValue( 'emailAddress' );

$this->_sendConfirmEmail( $email );
$this->_flash->addMessage( 'A confirmation code has been resent' );
//------------------------------------------
// Attempt to confirm an email address
//-----------------------------------------
$confirm = $confirms->find( $email );

} else {
if ( $confirm == false ) {

$this->_flash->addMessage(
'The email address you entered is not pending confirmation.'
);
}
} else if( !empty( $code ) ) {
$form->getElement( 'emailAddress' )
->addError( 'This e-mail address is not pending confirmation' );

//------------------------------------------
// Attempt to confirm an email address
//------------------------------------------
} elseif( $code == $confirm->code ) {

$confirmcodes = new AccountConfirmsHandler();
$confirm->Account->confirmed = true;
$confirm->Account->save();
$confirm->delete();
$this->_flash->addMessage( 'Your e-mail address has been confirmed. You may now log in.' );

if( $confirmcodes->confirm( $email, $code ) ) {

$accounts = new AccountsHandler();
$accounts->confirmByEmail( $email );

$this->_flash->addMessage(
'Your email address has been confirmed. You may now log in.'
);

$this->_redirector->gotoSimple( 'login' );
} else {

$this->_flash->addMessage(
'The confirmation code is incorrect for the email address '
. 'you provided. Please try again.'
);
}
$this->_redirector->gotoSimple(
'login' );
} else {
$form->getElement( 'code' )
->addError( 'The confirmation code is incorrect.' );
}
}

$this->view->form = $form;
$this->view->assign( 'email', $email );
$this->view->assign( 'code', $code );
}

protected function _sendConfirmEmail( $emailaddress )
protected function _sendConfirmEmail( $emailAddress )
{
$confirm = new AccountConfirm();
$confirm->emailAddress = $emailAddress;
$confirm->save();

$this->view->layout()->setLayout( 'blank' );

$confirms = new AccountConfirmsHandler();
$code = $confirms->generate( $emailaddress );
$this->view->assign( 'emailAddress', $confirm->emailAddress );
$this->view->assign( 'confirmCode', $confirm->code );

$view = new Zend_Layout();
$view->setLayout( 'blank' );
$link = $this->_helper->url( 'confirm', 'account', 'default', array(
'email' => $confirm->emailAddress,
'code' => $confirm->code
) );

$view->getView()->assign( 'emailAddress', $emailaddress );
$view->getView()->assign( 'confirmCode', $code );
$this->view->assign( 'link', "http://{$this->_config->hostname}/{$link}" );

$mail = new Zend_Mail();
$mail->addTo( $emailaddress );
$mail->setBodyText( $view->render( 'mail/confirm-text' ) );
$mail->setBodyHtml( $view->render( 'mail/confirm-html' ) );
$mail->setFrom( 'accounts@zendforge.org' );
$mail->setReturnPath( 'no-reply@zendforge.org' );
$mail->setSubject( 'Please Confirm Your E-Mail Address for ZendForge' );
$mail->addTo( $confirm->emailAddress );
$mail->setBodyText( $this->view->render( 'mail/confirm-text.phtml' ) );
$mail->setBodyHtml( $this->view->render( 'mail/confirm-html.phtml' ) );
$mail->setFrom( 'accounts@' . $this->_config->hostname, 'BitNotion, M.D.' );
$mail->setReturnPath( 'no-reply@' . $this->_config->hostname );
$mail->setSubject( 'BitNotion | Please Confirm Your E-Mail Address' );
$mail->send();
}

Expand Down
Loading

0 comments on commit 0fe1599

Please sign in to comment.