Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
Conflicts:
	app/controllers/UserController.php
	app/views/groups/index.blade.php
	app/views/layouts/default.blade.php
	app/views/users/login.blade.php
	app/views/users/resend.blade.php
	app/views/users/reset.blade.php
	composer.json
	readme.md
  • Loading branch information
rydurham committed Nov 19, 2013
2 parents 147af79 + af97a7a commit 773e673
Show file tree
Hide file tree
Showing 85 changed files with 4,030 additions and 11,139 deletions.
15 changes: 15 additions & 0 deletions app/Authority/Mailers/Mailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php namespace Authority\Mailers;

use Mail;

abstract class Mailer {

public function sendTo($email, $subject, $view, $data = array())
{
Mail::queue($view, $data, function($message) use($email, $subject)
{
$message->to($email)
->subject($subject);
});
}
}
73 changes: 73 additions & 0 deletions app/Authority/Mailers/UserMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php namespace Authority\Mailers;

class UserMailer extends Mailer {

/**
* Outline all the events this class will be listening for.
* @param [type] $events
* @return void
*/
public function subscribe($events)
{
$events->listen('user.signup', 'Authority\Mailers\UserMailer@welcome');
$events->listen('user.resend', 'Authority\Mailers\UserMailer@welcome');
$events->listen('user.forgot', 'Authority\Mailers\UserMailer@forgotPassword');
$events->listen('user.newpassword', 'Authority\Mailers\UserMailer@newPassword');
}

/**
* Send a welcome email to a new user.
* @param string $email
* @param int $userId
* @param string $activationCode
* @return bool
*/
public function welcome($email, $userId, $activationCode)
{
$subject = 'Welcome to Laravel4 With Sentry';
$view = 'emails.auth.welcome';
$data['userId'] = $userId;
$data['activationCode'] = $activationCode;
$data['email'] = $email;

return $this->sendTo($email, $subject, $view, $data );
}

/**
* Email Password Reset info to a user.
* @param string $email
* @param int $userId
* @param string $resetCode
* @return bool
*/
public function forgotPassword($email, $userId, $resetCode)
{
$subject = 'Password Reset Confirmation | Laravel4 With Sentry';
$view = 'emails.auth.reset';
$data['userId'] = $userId;
$data['resetCode'] = $resetCode;
$data['email'] = $email;

return $this->sendTo($email, $subject, $view, $data );
}

/**
* Email New Password info to user.
* @param string $email
* @param int $userId
* @param string $resetCode
* @return bool
*/
public function newPassword($email, $newPassword)
{
$subject = 'New Password Information | Laravel4 With Sentry';
$view = 'emails.auth.newpassword';
$data['newPassword'] = $newPassword;
$data['email'] = $email;

return $this->sendTo($email, $subject, $view, $data );
}



}
51 changes: 51 additions & 0 deletions app/Authority/Repo/Group/GroupInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php namespace Authority\Repo\Group;

interface GroupInterface {

/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store($data);

/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id);

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id);

/**
* Return a specific user by a given id
*
* @param integer $id
* @return User
*/
public function byId($id);

/**
* Return a specific user by a given name
*
* @param string $name
* @return User
*/
public function byName($name);

/**
* Return all the registered users
*
* @return stdObject Collection of users
*/
public function all();

}
184 changes: 184 additions & 0 deletions app/Authority/Repo/Group/SentryGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php namespace Authority\Repo\Group;

use Cartalyst\Sentry\Sentry;
use Authority\Repo\RepoAbstract;

class SentryGroup extends RepoAbstract implements GroupInterface {

protected $sentry;

/**
* Construct a new SentryGroup Object
*/
public function __construct(Sentry $sentry)
{
$this->sentry = $sentry;
}

/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store($data)
{
// Logic for missing checkbox values
if (!array_key_exists('adminPermissions', $data)) $data['adminPermissions'] = 0;
if (!array_key_exists('userPermissions', $data)) $data['userPermissions'] = 0;

$result = array();
try {
// Create the group
$group = $this->sentry->createGroup(array(
'name' => e($data['name']),
'permissions' => array(
'admin' => e($data['adminPermissions']),
'users' => e($data['userPermissions']),
),
));

$result['success'] = true;
$result['message'] = trans('groups.created');
}
catch (\Cartalyst\Sentry\Users\LoginRequiredException $e)
{
$result['success'] = false;
$result['message'] = trans('groups.loginreq');
}
catch (\Cartalyst\Sentry\Users\UserExistsException $e)
{
$result['success'] = false;
$result['message'] = trans('groups.userexists');;
}

return $result;
}

/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($data)
{
// Logic for missing checkbox values
if (!array_key_exists('adminPermissions', $data)) $data['adminPermissions'] = 0;
if (!array_key_exists('userPermissions', $data)) $data['userPermissions'] = 0;

try
{
// Find the group using the group id
$group = $this->sentry->findGroupById($data['id']);

// Update the group details
$group->name = e($data['name']);
$group->permissions = array(
'admin' => e($data['adminPermissions']),
'users' => e($data['userPermissions']),
);

// Update the group
if ($group->save())
{
// Group information was updated
$result['success'] = true;
$result['message'] = trans('groups.updated');;
}
else
{
// Group information was not updated
$result['success'] = false;
$result['message'] = trans('groups.updateproblem');;
}
}
catch (\Cartalyst\Sentry\Groups\NameRequiredException $e)
{
$result['success'] = false;
$result['message'] = trans('groups.namereq');;
}
catch (\Cartalyst\Sentry\Groups\GroupExistsException $e)
{
$result['success'] = false;
$result['message'] = trans('groups.groupexists');;
}
catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e)
{
$result['success'] = false;
$result['message'] = trans('groups.notfound');
}

return $result;
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
try
{
// Find the group using the group id
$group = $this->sentry->findGroupById($id);

// Delete the group
$group->delete();
}
catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
{
return false;
}
return true;
}

/**
* Return a specific group by a given id
*
* @param integer $id
* @return Group
*/
public function byId($id)
{
try
{
$group = $this->sentry->findGroupById($id);
}
catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
{
return false;
}
return $group;
}

/**
* Return a specific group by a given name
*
* @param string $name
* @return Group
*/
public function byName($name)
{
try
{
$group = $this->sentry->findGroupByName($name);
}
catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
{
return false;
}
return $group;
}

/**
* Return all the registered groups
*
* @return stdObject Collection of groups
*/
public function all()
{
return $this->sentry->getGroupProvider()->findAll();
}
}
6 changes: 6 additions & 0 deletions app/Authority/Repo/RepoAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php namespace Authority\Repo;

abstract class RepoAbstract {


}
43 changes: 43 additions & 0 deletions app/Authority/Repo/RepoServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php namespace Authority\Repo;

use Illuminate\Support\ServiceProvider;
use Authority\Repo\Session\SentrySession;
use Authority\Repo\User\SentryUser;
use Authority\Repo\Group\SentryGroup;
use Cartalyst\Sentry\Sentry;

class RepoServiceProvider extends ServiceProvider {

/**
* Register the binding
*/
public function register()
{
$app = $this->app;

// Bind the Session Repository
$app->bind('Authority\Repo\Session\SessionInterface', function($app)
{
return new SentrySession(
$app['sentry']
);
});

// Bind the User Repository
$app->bind('Authority\Repo\User\UserInterface', function($app)
{
return new SentryUser(
$app['sentry']
);
});

// Bind the Group Repository
$app->bind('Authority\Repo\Group\GroupInterface', function($app)
{
return new SentryGroup(
$app['sentry']
);
});
}

}
Loading

0 comments on commit 773e673

Please sign in to comment.