Skip to content

Commit 224ba1a

Browse files
committed
first commit
0 parents  commit 224ba1a

File tree

142 files changed

+12693
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+12693
-0
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.idea/*
2+
/bootstrap/compiled.php
3+
/vendor
4+
/node_modules
5+
composer.phar
6+
.env.*.php
7+
.env.php
8+
.DS_Store
9+
Thumbs.db
10+
11+
tests/_output/*

CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contribution Guidelines
2+
3+
Please submit all issues and pull requests to the [laravel/framework](http://github.com/laravel/framework) repository!

Gulpfile.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var gulp = require('gulp');
2+
var sass = require('gulp-sass');
3+
var autoprefixer = require('gulp-autoprefixer');
4+
5+
gulp.task('css', function(){
6+
gulp.src('app/assets/sass/main.scss')
7+
.pipe(sass())
8+
.pipe(autoprefixer('last 10 version'))
9+
.pipe(gulp.dest('public/css'));
10+
});
11+
12+
gulp.task('watch', function(){
13+
gulp.watch('app/assets/sass/**/*.scss', ['css']);
14+
});
15+
16+
gulp.task('default', ['watch']);

app/Phphub/Core/CreatorListener.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php namespace Phphub\Core;
2+
3+
interface CreatorListener
4+
{
5+
public function creatorFailed($errors);
6+
public function creatorSucceed($model);
7+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php namespace Phphub\Forms;
2+
3+
use Laracasts\Validation\FormValidator;
4+
5+
class ReplyCreationForm extends FormValidator
6+
{
7+
protected $rules = [
8+
'body' => 'required|min:2',
9+
'user_id' => 'required|numeric',
10+
'topic_id' => 'required|numeric',
11+
];
12+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php namespace Phphub\Forms;
2+
3+
use Laracasts\Validation\FormValidator;
4+
5+
class TopicCreationForm extends FormValidator
6+
{
7+
protected $rules = [
8+
'title' => 'required|min:5',
9+
'body' => 'required|min:10',
10+
'node_id' => 'required|numeric'
11+
];
12+
}

app/Phphub/Forms/UserSignupForm.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php namespace Phphub\Forms;
2+
3+
use Laracasts\Validation\FormValidator;
4+
5+
class UserSignupForm extends FormValidator
6+
{
7+
8+
protected $rules = [
9+
'github_id' => 'required|unique:users',
10+
'name' => 'required',
11+
'email' => 'email'
12+
];
13+
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php namespace Phphub\Github;
2+
3+
use User;
4+
5+
/**
6+
* This class can call the following methods on the listener object:
7+
*
8+
* userFound($user)
9+
* userIsBanned($user)
10+
* userNotFound($githubData)
11+
*/
12+
class GithubAuthenticator
13+
{
14+
protected $userModel;
15+
16+
public function __construct(User $userModel, GithubUserDataReader $reader)
17+
{
18+
$this->userModel = $userModel;
19+
$this->reader = $reader;
20+
}
21+
22+
public function authByCode(GithubAuthenticatorListener $listener, $code)
23+
{
24+
$githubData = $this->reader->getDataFromCode($code);
25+
$user = $this->userModel->getByGithubId($githubData['id']);
26+
27+
if ($user) {
28+
return $this->loginUser($listener, $user, $githubData);
29+
}
30+
31+
return $listener->userNotFound($githubData);
32+
}
33+
34+
private function loginUser($listener, $user, $githubData)
35+
{
36+
if ($user->is_banned) {
37+
return $listener->userIsBanned($user);
38+
}
39+
40+
$user->fill($githubData);
41+
$user->save();
42+
43+
return $listener->userFound($user);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php namespace Phphub\Github;
2+
3+
interface GithubAuthenticatorListener
4+
{
5+
public function userFound($user);
6+
public function userIsBanned($user);
7+
public function userNotFound($githubData);
8+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace Phphub\Github;
2+
3+
use OAuth;
4+
5+
class GithubUserDataReader
6+
{
7+
public function getDataFromCode($code)
8+
{
9+
$data = $this->readFromGithub($code);
10+
return $this->formatData($data);
11+
}
12+
13+
private function readFromGithub($code)
14+
{
15+
$github = OAuth::consumer('GitHub');
16+
$oauthTokenObject = $github->requestAccessToken($code);
17+
$githubData = json_decode($github->request('user'), true);
18+
$githubData['email'] = last(json_decode($github->request('user/emails'), true));
19+
return $githubData;
20+
}
21+
22+
private function formatData($data)
23+
{
24+
return [
25+
'id' => $data['id'],
26+
'name' => $data['login'],
27+
'email' => $data['email'],
28+
'github_id' => $data['id'],
29+
'github_url' => $data['html_url'],
30+
'image_url' => $data['avatar_url'],
31+
];
32+
}
33+
}

app/Phphub/Reply/ReplyCreator.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace Phphub\Reply;
2+
3+
use Phphub\Forms\ReplyCreationForm;
4+
use Phphub\Core\CreatorListener;
5+
use Reply, Auth;
6+
7+
class ReplyCreator
8+
{
9+
protected $replyModel;
10+
protected $form;
11+
12+
public function __construct(Reply $replyModel, ReplyCreationForm $form)
13+
{
14+
$this->userModel = $replyModel;
15+
$this->form = $form;
16+
}
17+
18+
public function create(CreatorListener $observer, $data)
19+
{
20+
$data['user_id'] = Auth::user()->id;
21+
22+
// Validation
23+
$this->form->validate($data);
24+
25+
$reply = Reply::create($data);
26+
if ( ! $reply)
27+
{
28+
return $observer->creatorFailed($reply->getErrors());
29+
}
30+
31+
return $observer->creatorSucceed($reply);
32+
}
33+
}

app/Phphub/Topic/TopicCreator.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace Phphub\Topic;
2+
3+
use Phphub\Forms\TopicCreationForm;
4+
use Phphub\Core\CreatorListener;
5+
use Topic, Auth;
6+
7+
class TopicCreator
8+
{
9+
protected $topicModel;
10+
protected $form;
11+
12+
public function __construct(Topic $topicModel, TopicCreationForm $form)
13+
{
14+
$this->userModel = $topicModel;
15+
$this->form = $form;
16+
}
17+
18+
public function create(CreatorListener $observer, $data)
19+
{
20+
$data['user_id'] = Auth::user()->id;
21+
22+
// Validation
23+
$this->form->validate($data);
24+
25+
$topic = Topic::create($data);
26+
if ( ! $topic)
27+
{
28+
return $observer->creatorFailed($topic->getErrors());
29+
}
30+
31+
return $observer->creatorSucceed($topic);
32+
}
33+
}

app/Phphub/Topic/TopicPresenter.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php namespace Phphub\Topic;
2+
3+
use Laracasts\Presenter\Presenter;
4+
use Input, URL;
5+
6+
class TopicPresenter extends Presenter
7+
{
8+
public function topicFilter($filter)
9+
{
10+
$query_append = '';
11+
if ( !empty(Input::except('filter')) )
12+
{
13+
$query_append = '&'.http_build_query(Input::except('filter'));
14+
}
15+
16+
return URL::to('topics') . '?filter=' . $filter . $query_append;
17+
}
18+
19+
public function getTopicFilter()
20+
{
21+
$filters = ['noreply', 'vote', 'excellent','recent'];
22+
$request_filter = Input::get('filter');
23+
if ( in_array($request_filter, $filters) )
24+
{
25+
return $request_filter;
26+
}
27+
return 'recent';
28+
}
29+
30+
}

app/Phphub/User/UserCreator.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php namespace Phphub\User;
2+
3+
use Phphub\Forms\UserSignupForm;
4+
use User;
5+
6+
/**
7+
* This class can call the following methods on the observer object:
8+
*
9+
* userValidationError($errors)
10+
* userCreated($user)
11+
*/
12+
class UserCreator
13+
{
14+
protected $userModel;
15+
protected $signupForm;
16+
17+
public function __construct(User $userModel, UserSignupForm $signupForm)
18+
{
19+
$this->userModel = $userModel;
20+
$this->signupForm = $signupForm;
21+
}
22+
23+
public function create(UserCreatorListener $observer, $data)
24+
{
25+
// Validation
26+
$this->signupForm->validate($data);
27+
28+
return $this->createValidUserRecord($observer, $data);
29+
}
30+
31+
private function createValidUserRecord($observer, $data)
32+
{
33+
$user = User::create($data);
34+
if ( ! $user)
35+
{
36+
return $observer->userValidationError($user->getErrors());
37+
}
38+
39+
return $observer->userCreated($user);
40+
}
41+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php namespace Phphub\User;
2+
3+
interface UserCreatorListener
4+
{
5+
public function userValidationError($errors);
6+
public function userCreated($user);
7+
}

app/Phphub/User/UserPresenter.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php namespace Phphub\User;
2+
3+
use Laracasts\Presenter\Presenter;
4+
5+
class UserPresenter extends Presenter
6+
{
7+
/**
8+
* Present a link to the user gravatar
9+
*
10+
* @param int $size
11+
* @return string
12+
*/
13+
public function gravatar($size = 30)
14+
{
15+
$email = md5($this->email);
16+
17+
return "//gravatar.com/avatar/{$email}?s={$size}";
18+
}
19+
20+
}

app/assets/sass/main.scss

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
html,
2+
body {
3+
height: 100%;
4+
/* The html and body elements cannot have any padding or margin. */
5+
}
6+
7+
#wrap {
8+
min-height: 100%;
9+
height: auto;
10+
/* Negative indent footer by its height */
11+
margin: 0 auto -60px;
12+
/* Pad bottom by footer height */
13+
padding: 0 0 60px;
14+
}
15+
16+
#footer {
17+
height: 60px;
18+
background-color: #f5f5f5;
19+
}
20+
.footer {
21+
padding-top: 19px;
22+
color: #777;
23+
border-top: 1px dotted #e5e5e5;
24+
}
25+
26+
embed {
27+
display:none;
28+
}

app/commands/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)