Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
summerblue committed Aug 13, 2014
0 parents commit 224ba1a
Show file tree
Hide file tree
Showing 142 changed files with 12,693 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.idea/*
/bootstrap/compiled.php
/vendor
/node_modules
composer.phar
.env.*.php
.env.php
.DS_Store
Thumbs.db

tests/_output/*
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contribution Guidelines

Please submit all issues and pull requests to the [laravel/framework](http://github.com/laravel/framework) repository!
16 changes: 16 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');

gulp.task('css', function(){
gulp.src('app/assets/sass/main.scss')
.pipe(sass())
.pipe(autoprefixer('last 10 version'))
.pipe(gulp.dest('public/css'));
});

gulp.task('watch', function(){
gulp.watch('app/assets/sass/**/*.scss', ['css']);
});

gulp.task('default', ['watch']);
7 changes: 7 additions & 0 deletions app/Phphub/Core/CreatorListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php namespace Phphub\Core;

interface CreatorListener
{
public function creatorFailed($errors);
public function creatorSucceed($model);
}
12 changes: 12 additions & 0 deletions app/Phphub/Forms/ReplyCreationForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php namespace Phphub\Forms;

use Laracasts\Validation\FormValidator;

class ReplyCreationForm extends FormValidator
{
protected $rules = [
'body' => 'required|min:2',
'user_id' => 'required|numeric',
'topic_id' => 'required|numeric',
];
}
12 changes: 12 additions & 0 deletions app/Phphub/Forms/TopicCreationForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php namespace Phphub\Forms;

use Laracasts\Validation\FormValidator;

class TopicCreationForm extends FormValidator
{
protected $rules = [
'title' => 'required|min:5',
'body' => 'required|min:10',
'node_id' => 'required|numeric'
];
}
13 changes: 13 additions & 0 deletions app/Phphub/Forms/UserSignupForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php namespace Phphub\Forms;

use Laracasts\Validation\FormValidator;

class UserSignupForm extends FormValidator
{

protected $rules = [
'github_id' => 'required|unique:users',
'name' => 'required',
'email' => 'email'
];
}
45 changes: 45 additions & 0 deletions app/Phphub/Github/GithubAuthenticator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php namespace Phphub\Github;

use User;

/**
* This class can call the following methods on the listener object:
*
* userFound($user)
* userIsBanned($user)
* userNotFound($githubData)
*/
class GithubAuthenticator
{
protected $userModel;

public function __construct(User $userModel, GithubUserDataReader $reader)
{
$this->userModel = $userModel;
$this->reader = $reader;
}

public function authByCode(GithubAuthenticatorListener $listener, $code)
{
$githubData = $this->reader->getDataFromCode($code);
$user = $this->userModel->getByGithubId($githubData['id']);

if ($user) {
return $this->loginUser($listener, $user, $githubData);
}

return $listener->userNotFound($githubData);
}

private function loginUser($listener, $user, $githubData)
{
if ($user->is_banned) {
return $listener->userIsBanned($user);
}

$user->fill($githubData);
$user->save();

return $listener->userFound($user);
}
}
8 changes: 8 additions & 0 deletions app/Phphub/Github/GithubAuthenticatorListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php namespace Phphub\Github;

interface GithubAuthenticatorListener
{
public function userFound($user);
public function userIsBanned($user);
public function userNotFound($githubData);
}
33 changes: 33 additions & 0 deletions app/Phphub/Github/GithubUserDataReader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Phphub\Github;

use OAuth;

class GithubUserDataReader
{
public function getDataFromCode($code)
{
$data = $this->readFromGithub($code);
return $this->formatData($data);
}

private function readFromGithub($code)
{
$github = OAuth::consumer('GitHub');
$oauthTokenObject = $github->requestAccessToken($code);
$githubData = json_decode($github->request('user'), true);
$githubData['email'] = last(json_decode($github->request('user/emails'), true));
return $githubData;
}

private function formatData($data)
{
return [
'id' => $data['id'],
'name' => $data['login'],
'email' => $data['email'],
'github_id' => $data['id'],
'github_url' => $data['html_url'],
'image_url' => $data['avatar_url'],
];
}
}
33 changes: 33 additions & 0 deletions app/Phphub/Reply/ReplyCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Phphub\Reply;

use Phphub\Forms\ReplyCreationForm;
use Phphub\Core\CreatorListener;
use Reply, Auth;

class ReplyCreator
{
protected $replyModel;
protected $form;

public function __construct(Reply $replyModel, ReplyCreationForm $form)
{
$this->userModel = $replyModel;
$this->form = $form;
}

public function create(CreatorListener $observer, $data)
{
$data['user_id'] = Auth::user()->id;

// Validation
$this->form->validate($data);

$reply = Reply::create($data);
if ( ! $reply)
{
return $observer->creatorFailed($reply->getErrors());
}

return $observer->creatorSucceed($reply);
}
}
33 changes: 33 additions & 0 deletions app/Phphub/Topic/TopicCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Phphub\Topic;

use Phphub\Forms\TopicCreationForm;
use Phphub\Core\CreatorListener;
use Topic, Auth;

class TopicCreator
{
protected $topicModel;
protected $form;

public function __construct(Topic $topicModel, TopicCreationForm $form)
{
$this->userModel = $topicModel;
$this->form = $form;
}

public function create(CreatorListener $observer, $data)
{
$data['user_id'] = Auth::user()->id;

// Validation
$this->form->validate($data);

$topic = Topic::create($data);
if ( ! $topic)
{
return $observer->creatorFailed($topic->getErrors());
}

return $observer->creatorSucceed($topic);
}
}
30 changes: 30 additions & 0 deletions app/Phphub/Topic/TopicPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php namespace Phphub\Topic;

use Laracasts\Presenter\Presenter;
use Input, URL;

class TopicPresenter extends Presenter
{
public function topicFilter($filter)
{
$query_append = '';
if ( !empty(Input::except('filter')) )
{
$query_append = '&'.http_build_query(Input::except('filter'));
}

return URL::to('topics') . '?filter=' . $filter . $query_append;
}

public function getTopicFilter()
{
$filters = ['noreply', 'vote', 'excellent','recent'];
$request_filter = Input::get('filter');
if ( in_array($request_filter, $filters) )
{
return $request_filter;
}
return 'recent';
}

}
41 changes: 41 additions & 0 deletions app/Phphub/User/UserCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace Phphub\User;

use Phphub\Forms\UserSignupForm;
use User;

/**
* This class can call the following methods on the observer object:
*
* userValidationError($errors)
* userCreated($user)
*/
class UserCreator
{
protected $userModel;
protected $signupForm;

public function __construct(User $userModel, UserSignupForm $signupForm)
{
$this->userModel = $userModel;
$this->signupForm = $signupForm;
}

public function create(UserCreatorListener $observer, $data)
{
// Validation
$this->signupForm->validate($data);

return $this->createValidUserRecord($observer, $data);
}

private function createValidUserRecord($observer, $data)
{
$user = User::create($data);
if ( ! $user)
{
return $observer->userValidationError($user->getErrors());
}

return $observer->userCreated($user);
}
}
7 changes: 7 additions & 0 deletions app/Phphub/User/UserCreatorListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php namespace Phphub\User;

interface UserCreatorListener
{
public function userValidationError($errors);
public function userCreated($user);
}
20 changes: 20 additions & 0 deletions app/Phphub/User/UserPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php namespace Phphub\User;

use Laracasts\Presenter\Presenter;

class UserPresenter extends Presenter
{
/**
* Present a link to the user gravatar
*
* @param int $size
* @return string
*/
public function gravatar($size = 30)
{
$email = md5($this->email);

return "//gravatar.com/avatar/{$email}?s={$size}";
}

}
28 changes: 28 additions & 0 deletions app/assets/sass/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}

#wrap {
min-height: 100%;
height: auto;
/* Negative indent footer by its height */
margin: 0 auto -60px;
/* Pad bottom by footer height */
padding: 0 0 60px;
}

#footer {
height: 60px;
background-color: #f5f5f5;
}
.footer {
padding-top: 19px;
color: #777;
border-top: 1px dotted #e5e5e5;
}

embed {
display:none;
}
Empty file added app/commands/.gitkeep
Empty file.
Loading

0 comments on commit 224ba1a

Please sign in to comment.